Package valorless.havenbags.datamodels
Class Sound
java.lang.Object
valorless.havenbags.datamodels.Sound
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic SoundParses a sound definition from a compact string.voidplay(org.bukkit.entity.Player player) Plays this sound to the specified player.voidplay(org.bukkit.Location location) Plays this sound at the specified location.toString()Returns a string representation of this sound for debugging purposes.
-
Field Details
-
key
Namespaced or legacy sound key identifier, e.g. "minecraft:entity.player.levelup" or "ENTITY_PLAYER_LEVELUP". -
volume
Playback volume. Typical range: 0.0+; 1.0 is normal volume. -
pitch
Playback pitch. Typical range: 0.5–2.0; 1.0 is normal pitch.
-
-
Constructor Details
-
Sound
Creates a sound model with the given identifier and playback parameters.- Parameters:
volume- the desired volume as Double (must not be null); converted to floatpitch- the desired pitch as Double (must not be null); converted to floatsound- the sound key identifier (must not be null)
-
-
Method Details
-
parse
Parses a sound definition from a compact string.Expected format:
key:volume:pitchExamples: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
Returns a string representation of this sound for debugging purposes. -
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
-