Class VarSound

java.lang.Object
de.marcely.bedwars.tools.VarSound
All Implemented Interfaces:
Cloneable

public abstract class VarSound extends Object implements Cloneable
Easy solution for playing vanilla and custom sounds while retaining async support.
  • Constructor Details

    • VarSound

      public VarSound()
  • Method Details

    • isVanilla

      public abstract boolean isVanilla()
      Returns whether this sound is a vanilla sound or whether it's a custom sound that requires a resource pack.
      Returns:
      true if it's a vanilla sound, false otherwise
    • getName

      public abstract String getName()
      Returns the name of the sound.

      If it's a vanilla sound, it returns Enum.name().

      Returns:
      The name of the sound
    • getBukkitEnum

      public abstract Sound getBukkitEnum()
      Returns the bukkit enum of the sound.
      Returns:
      The bukkit enum of the sound. May be null if it's not present
    • getVolume

      public float getVolume()
      Returns the volume of the sound.

      Default is 1.

      Returns:
      The volume of the sound
    • setVolume

      public VarSound setVolume(float volume)
      Sets the volume of the sound.
      Parameters:
      volume - The volume of the sound
      Returns:
      Returns this exact instance
    • getPitch

      public float getPitch()
      Returns the pitch of the sound.

      Default is 1.

      Returns:
      The pitch of the sound
    • setPitch

      public VarSound setPitch(float pitch)
      Sets the pitch of the sound.
      Parameters:
      pitch - The pitch of the sound
      Returns:
      Returns this exact instance
    • isActive

      public boolean isActive()
      Returns whether this sound is active.

      If it's not active, it won't play.

      Returns:
      true if it's active, false otherwise
    • setActive

      public VarSound setActive(boolean active)
      Sets whether this sound is active.

      If it's not active, it won't play.

      Parameters:
      active - true if it's active, false otherwis
      Returns:
      Returns this exact instancee
    • play

      public abstract void play(Player player, Location loc, @Nullable @Nullable Float overrideVolume, @Nullable @Nullable Float overridePitch)
      Plays the sound to the player at the given location.
      Parameters:
      player - The player to play the sound to
      loc - The location to play the sound at
      overrideVolume - The volume to play the sound at. If null, it uses getVolume()
      overridePitch - The pitch to play the sound at. If null, it uses getPitch()
    • play

      public abstract void play(Location loc, @Nullable @Nullable Float overrideVolume, @Nullable @Nullable Float overridePitch)
      Plays the sound at the given location.
      Parameters:
      loc - The location to play the sound at
      overrideVolume - The volume to play the sound at. If null, it uses getVolume()
      overridePitch - The pitch to play the sound at. If null, it uses getPitch()
    • play

      public void play(Player player, Location loc)
      Plays the sound to the player at the given location.
      Parameters:
      player - The player to play the sound to
      loc - The location to play the sound at
    • play

      public void play(Player player)
      Plays the sound to the player at the location of the player.
      Parameters:
      player - The player to play the sound to
    • play

      public void play(Location loc)
      Plays the sound at the given location.
      Parameters:
      loc - The location to play the sound at
    • clone

      public VarParticle clone()
      Overrides:
      clone in class Object
    • serializeAsConfig

      public ConfigurationSection serializeAsConfig()
      Serializes this sound into a ConfigurationSection. It includes the following keys:
      • name: The name of the sound (required)
      • is-active: Whether the sound is active (default: true)
      • is-custom-resourcepack: Whether the sound is a custom sound that requires a resource pack (default: false)
      • volume: The volume of the sound (default: 1.0)
      • pitch: The pitch of the sound (default: 1.0)
      Returns:
      The serialized sound
    • parse

      public static VarSound parse(ConfigurationSection config) throws IllegalArgumentException
      Parses a sound from a ConfigurationSection. It includes the following keys:
      • name: The name of the sound (required)
      • is-active: Whether the sound is active (default: true)
      • is-custom-resourcepack: Whether the sound is a custom sound that requires a resource pack (default: false)
      • volume: The volume of the sound (default: 1.0)
      • pitch: The pitch of the sound (default: 1.0)
      Parameters:
      config - The config to parse
      Returns:
      The parsed sound
      Throws:
      IllegalArgumentException - If the config is invalid
    • from

      public static VarSound from(Sound sound)
      Creates a VarSound from a vanilla sound.
      Parameters:
      sound - The sound
      Returns:
      The created wrapper
    • fromCustom

      public static VarSound fromCustom(String name)
      Creates a VarSound from a custom sound.
      Parameters:
      name - The name of the sound
      Returns:
      The created wrapper