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.1
Author:
Crypto Morin
See Also:
  • Instrument
  • Note
  • 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 & 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 void testMusic(@NotNull @NotNull 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.
      Since:
      1.0.0
    • fromFile

      public static 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.
      Since:
      1.0.0
      See Also:
    • playMusic

      public static 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_2

      Instruments

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

      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.
      Since:
      1.0.0
      See Also:
    • parseInstructions

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

      @Nullable public static @Nullable org.bukkit.Note parseNote(@NotNull @NotNull 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(@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 7
      delay - the delay between each play.
      Returns:
      the async task handling the operation.
      Since:
      2.0.0