Class NoteBlockMusic
You can write small text scripts for Minecraft note blocks without needing to use any redstone or building to make your music. This class is independent of XSound.
- Version:
- 3.0.0
- Author:
- Crypto Morin
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAn instruction is any musical movement or section that can be a restatement and might have a fermata.static classA sequence is a restatement collection of multiple otherNoteBlockMusic.Sequences andNoteBlockMusic.Soundthat itself might be a part of anotherNoteBlockMusic.Sequencestatic classAn instruction that produces a sonud which consists of aInstrumentand aNotewithNote.Tone, but without duration or -
Method Summary
Modifier and TypeMethodDescriptionstatic CompletableFuture<Void> fromFile(@NotNull org.bukkit.entity.Player player, @NotNull Supplier<org.bukkit.Location> location, @NotNull Path path) Plays a music from a file.static org.bukkit.Note.TonegetNoteTone(char ch) Gets a note tone from a character.static @NotNull XSoundgetSoundFromInstrument(@NotNull org.bukkit.Instrument instrument) static floatnoteToPitch(@NotNull org.bukkit.Note note) static NoteBlockMusic.SequenceparseInstructions(@NotNull CharSequence script) static @Nullable org.bukkit.NoteParses a MinecraftNotewith itsNote.ToneWith the format: <tone>[pitch][octave]static @NotNull org.bukkit.scheduler.BukkitTaskplayAscendingNote(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull org.bukkit.entity.Player player, @NotNull org.bukkit.entity.Entity playTo, @NotNull org.bukkit.Instrument instrument, int ascendLevel, int delay) Plays an instrument's notes in an ascending form.static CompletableFuture<Void> playMusic(@NotNull org.bukkit.entity.Player player, @NotNull Supplier<org.bukkit.Location> location, @Nullable String script) This is a very special and unique method.static CompletableFuture<Void> testMusic(@NotNull org.bukkit.entity.Player player) A pre-written music script to test withplayMusic(Player, Supplier, String)If you made a cool script using this let me know, I'll put it here.
-
Method Details
-
getSoundFromInstrument
@NotNull public static @NotNull XSound getSoundFromInstrument(@NotNull @NotNull org.bukkit.Instrument instrument) -
getNoteTone
@Nullable public static org.bukkit.Note.Tone getNoteTone(char ch) Gets a note tone from a character. Can't be optimized further using an array since switch statement here can be optimized by JIT even more.The character paseed to this method is assumed to be uppercase, otherwise it needs to be
ch & 0x5fmanually.https://minecraft.wiki/w/Note_Block#Notes
- Parameters:
ch- the character of the note tone.- Returns:
- the note tone or null if not found.
- Since:
- 3.0.0
-
testMusic
A pre-written music script to test withplayMusic(Player, Supplier, String)If you made a cool script using this let me know, I'll put it here. You can still give me the script and I'll put it on the Spigot page.- Parameters:
player- the player to send the notes to.- Returns:
- the async task handling the notes.
- Since:
- 1.0.0
-
fromFile
public static CompletableFuture<Void> fromFile(@NotNull @NotNull org.bukkit.entity.Player player, @NotNull @NotNull Supplier<org.bukkit.Location> location, @NotNull @NotNull Path path) Plays a music from a file. This file can have YAML comments (#) and empty lines.- Parameters:
player- the player to play the music to.location- the location to play the notes to.path- the path of the file to read the music notes from.- Returns:
- the async task handling the file operations and music parsers.
- Since:
- 1.0.0
- See Also:
-
playMusic
public static CompletableFuture<Void> playMusic(@NotNull @NotNull org.bukkit.entity.Player player, @NotNull @NotNull Supplier<org.bukkit.Location> location, @Nullable @Nullable String script) This is a very special and unique method. This method allows you to write your own Minecraft music without needing to use redstones and note blocks.We'll take a whole thread for the music for blocking requests. Format:
Instrument, Tone, Repeat (optional), Repeating Delay (optional, required if Repeat is used) [Next Delay]
Both delays are in milliseconds.
Also you can use segments (segment) to repeat a segment multiple times.Example
Shortcuts:
BD,G 20 BD,G 20 BD,G -> BD,G,3,20(BD,G,3,20 BG,E,5,10),1000,2 1000 BA,A Translated: Play BASS_DRUM with tone G 3 times every 20 ticks.
Play BASS_GUITAR with tone E 5 times every 10 ticks.
Play those ^ again two times with 1 second delay between repeats.
Wait 1000ms.
Play BANJO with tone A once.Note Tones
Available Note Tones: G, A, B, C, D, E, F (Idk why G is the first one)
Note.Tone
You can also use sharp or flat tones by using '#' for sharp and '_' for flat e.g. B_ C#
Octave numbers 1 and 2 can be used. C1, C#1, B_1, D_2Instruments
Available Instruments: Basically the first letter of every instrument. E.g.
BD -> BASS_DRUM
You can also use their full name.InstrumentCompletableFuture
Warning: Do not use blocking methods such as join() or get() You may use cancel() or the then... methods.
- Parameters:
player- in order to play the note we need a player instance. Any player.location- the location to play this note to.script- the music script.- Returns:
- the async task processing the script.
- Since:
- 1.0.0
- See Also:
-
parseInstructions
-
parseNote
Parses a MinecraftNotewith itsNote.ToneWith the format: <tone>[pitch][octave]Available Note Tones: G, A, B, C, D, E, F (Idk why G is the first one)
Note.Tone
You can also use sharp or flat tones by using '#' for sharp and '_' for flat e.g. B_ C#
Octave numbers 1 and 2 can be used. C1, C#1, B_1, D_2
Pitch Octave- Returns:
- a note with a tone.
- Since:
- 3.0.0
-
noteToPitch
public static float noteToPitch(@NotNull @NotNull org.bukkit.Note note) -
playAscendingNote
@NotNull public static @NotNull org.bukkit.scheduler.BukkitTask playAscendingNote(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull org.bukkit.entity.Player player, @NotNull @NotNull org.bukkit.entity.Entity playTo, @NotNull @NotNull org.bukkit.Instrument instrument, int ascendLevel, int delay) Plays an instrument's notes in an ascending form. This method is not really relevant to this utility class, but a nice feature.- Parameters:
plugin- the plugin handling schedulers.player- the player to play the note from.playTo- the entity to play the note to.instrument- the instrument.ascendLevel- the ascend level of notes. Can only be positive and not higher than 7delay- the delay between each play.- Returns:
- the async task handling the operation.
- Since:
- 2.0.0
-