Class NoteBlockMusic

java.lang.Object
com.cryptomorin.xseries.NoteBlockMusic

public final class NoteBlockMusic extends Object
NoteBlockMusic - Write music scripts for Minecraft.
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:
  • Instrument
  • Note
  • Method Details

    • getSoundFromInstrument

      @Nonnull public static XSound getSoundFromInstrument(@Nonnull 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 & 0x5f manually.

      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

      public static CompletableFuture<Void> testMusic(@Nonnull org.bukkit.entity.Player player)
      A pre-written music script to test with playMusic(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(@Nonnull org.bukkit.entity.Player player, @Nonnull Supplier<org.bukkit.Location> location, @Nonnull 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(@Nonnull org.bukkit.entity.Player player, @Nonnull Supplier<org.bukkit.Location> location, @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_2

      Instruments

      Available Instruments: Basically the first letter of every instrument. E.g. BD -> BASS_DRUM
      You can also use their full name. Instrument

      CompletableFuture

      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

      public static NoteBlockMusic.Sequence parseInstructions(@Nonnull CharSequence script)
    • parseNote

      @Nullable public static org.bukkit.Note parseNote(@Nonnull String note)
      Parses a Minecraft Note with its Note.Tone With 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

      Tones:


      Pitch Octave
      Returns:
      a note with a tone.
      Since:
      3.0.0
    • noteToPitch

      public static float noteToPitch(@Nonnull org.bukkit.Note note)