Class Sound

java.lang.Object
valorless.havenbags.datamodels.Sound

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

This class encapsulates a sound identifier along with playback parameters (volume and pitch). It supports both namespaced sound keys (e.g., "minecraft:entity.player.levelup") and legacy enum-based keys (e.g., "ENTITY_PLAYER_LEVELUP"), providing flexibility across different Minecraft versions.

Instances can be created directly or parsed from a compact string format using parse(String).

Since:
1.0
Author:
Valorless
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    Namespaced or legacy sound key identifier, e.g.
    Playback pitch.
    Playback volume.
  • 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.
    Returns a string representation of this sound for debugging purposes.

    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 identifier, e.g. "minecraft:entity.player.levelup" or "ENTITY_PLAYER_LEVELUP".
    • volume

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

      public Float pitch
      Playback pitch. Typical range: 0.5–2.0; 1.0 is normal pitch.
  • 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()
      Returns a string representation of this sound for debugging purposes.
      Overrides:
      toString in class Object
      Returns:
      a formatted string containing the sound's key, volume, and pitch
    • 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