Class SoundData

java.lang.Object
com.jeff_media.jefflib.data.SoundData

public final class SoundData extends Object
Data class to wrap all information needed to play a sound
  • Constructor Details

  • Method Details

    • fromConfigurationSection

      public static SoundData fromConfigurationSection(@NotNull ConfigurationSection config, @Nullable String prefix) throws IllegalArgumentException
      Parses a ConfigurationSection into a SoundData object.

      Example:

       SoundData sound = SoundData.fromConfigurationSection(getConfig().getConfigurationSection("my_sound",null);
       

      Example YAML:

       my_sound:
        effect: AMBIENT_CAVE    # case insensitive for builtin sounds, CaSe SeNsItIvE for custom sounds
        volume: 0.5            # optional, default 1
        pitch: 1.5             # optional, default 1
        pitch-variant: 0.5     # optional, default 0. If this is set to 0.5, and pitch is set to 1.5, the sound will play with a pitch between 1 and 2
        sound-category: MASTER # optional, case insensitive, default MASTER
        
      Parameters:
      config - ConfigurationSection to parse
      prefix - Prefix to use when looking up values in the ConfigurationSection. If non-null, this prefix is prefixed to all keys. For example, if this is set to "foo-", then the keys to look up are "foo-sound", "foo-volume", etc.
      Throws:
      IllegalArgumentException - When no sound is defined, or if the sound category is not valid.
    • playToPlayer

      public void playToPlayer(Player player)
      Plays the sound only to the given player
      Parameters:
      player - Player
    • playToPlayer

      public void playToPlayer(Player player, Location location)
      Plays the sound only to the given player, at the given location
      Parameters:
      player - Player
      location - Location
    • playToWorld

      public void playToWorld(Location location)
      Plays the sound to all players in the world, at the given location
      Parameters:
      location - Location