Class Sound

java.lang.Object
valorless.rarespawns.datamodels.Sound

public class Sound extends Object
Data model representing a sound to be played by RareSpawns.

Stores the sound key (namespaced or legacy) and playback controls (volume and pitch) as floats compatible with the Bukkit API. Not to be confused with the org.bukkit.Sound enum; this model uses string keys to support custom or version-agnostic identifiers.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    Namespaced or legacy sound key, e.g.
    Playback pitch (float).
    Playback volume (float).
  • Constructor Summary

    Constructors
    Constructor
    Description
    Sound(String key, Double volume, Double pitch)
    Creates a sound model with the given identifier and playback parameters.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Sound
    parse(String string)
    Parses a sound definition from a compact string.
    void
    play(org.bukkit.entity.Player player)
    Plays this sound to the specified player.
    void
    play(org.bukkit.Location location)
    Plays this sound at the specified location.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • key

      public String key
      Namespaced or legacy sound key, e.g. "minecraft:entity.player.levelup" or "ENTITY_PLAYER_LEVELUP".
    • volume

      public Float volume
      Playback volume (float). Typical range: 0.0+; 1.0 is normal.
    • pitch

      public Float pitch
      Playback pitch (float). Typical range: about 0.5–2.0; 1.0 is normal.
  • Constructor Details

    • Sound

      public Sound(String key, Double volume, Double pitch)
      Creates a sound model with the given identifier and playback parameters.
      Parameters:
      volume - the desired volume as Double (must not be null); converted to float
      pitch - the desired pitch as Double (must not be null); converted to float
      sound - the sound key identifier (must not be null)
  • Method Details

    • parse

      public static Sound parse(String string)
      Parses a sound definition from a compact string.

      Expected format: key:volume:pitch Examples: ENTITY_PLAYER_LEVELUP:0.5:1.2. Behavior:

      • If the input does not contain a colon or does not have exactly 3 parts, the entire input is treated as the key and volume/pitch default to 1.0.
      • If volume or pitch fail to parse as numbers, fall back to defaults (1.0, 1.0).

      Parameters:
      string - the input string to parse
      Returns:
      a constructed Sound model based on the parsed values or sensible defaults
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • play

      public void play(org.bukkit.Location location)
      Plays this sound at the specified location.
      Parameters:
      location - the location where the sound should be played
    • play

      public void play(org.bukkit.entity.Player player)
      Plays this sound to the specified player.
      Parameters:
      player - the player where the sound should be played