Class SFX
This class provides methods to play sounds to players or at locations, supporting both legacy enum-based sound keys and modern namespaced identifiers. It includes utilities for extracting sound information from blocks and materials using reflection to maintain compatibility across Minecraft versions.
Key features:
- Play sounds to players or at world locations
- Support for both enum and namespaced sound identifiers
- Integration with
model
invalid reference
valorless.havenbags.datamodels.ravencrest.Sound - Block and material sound extraction using reflection
- Fallback handling for version compatibility
- Since:
- 1.0
- Author:
- Valorless
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic org.bukkit.SoundRetrieves a Bukkit Sound enum constant by name.static StringgetSoundBreak(org.bukkit.block.Block block) Retrieves the break sound identifier for a block.static StringgetSoundBreak(org.bukkit.Material material) Retrieves the break sound identifier for a material.static StringgetSoundPlace(org.bukkit.block.Block block) Retrieves the placement sound identifier for a block.static StringgetSoundPlace(org.bukkit.Material material) Retrieves the placement sound identifier for a material.static voidPlays a sound at the player's location with the given volume and pitch.static voidPlays a sound at a specific location with the given volume and pitch.static voidPlays a Sound model to a player.static voidPlays a Sound model at a specific location.static voidPlayNamespace(String sound, float volume, float pitch, org.bukkit.entity.Player player) Plays a namespaced sound to a player.static voidPlayNamespace(String sound, float volume, float pitch, org.bukkit.Location location) Plays a namespaced sound at a specific location.
-
Constructor Details
-
SFX
public SFX()
-
-
Method Details
-
Play
Plays a sound at the player's location with the given volume and pitch.Automatically detects whether the sound identifier is namespaced (contains a period) and delegates to the appropriate playback method. If the sound string is null or empty, no action is taken.
- Parameters:
sound- The name of the sound to play.volume- The volume of the sound (1.0 is normal volume).pitch- The pitch of the sound (1.0 is normal pitch).player- The player for whom the sound will be played.
-
PlayNamespace
public static void PlayNamespace(String sound, float volume, float pitch, org.bukkit.entity.Player player) Plays a namespaced sound to a player.Uses the modern namespaced sound format (e.g., "minecraft:entity.player.levelup"). If the sound string is null or empty, no action is taken. Errors are logged but do not interrupt execution.
- Parameters:
sound- the namespaced sound identifiervolume- the volume (1.0 is normal volume)pitch- the pitch (1.0 is normal pitch)player- the player who should hear the sound
-
Play
Plays a sound at a specific location with the given volume and pitch.Automatically detects whether the sound identifier is namespaced (contains a period) and delegates to the appropriate playback method. If the sound string is null or empty, no action is taken.
- Parameters:
sound- the sound identifier (enum name or namespaced)volume- the volume (1.0 is normal volume)pitch- the pitch (1.0 is normal pitch)location- the location where the sound should be played
-
PlayNamespace
public static void PlayNamespace(String sound, float volume, float pitch, org.bukkit.Location location) Plays a namespaced sound at a specific location.Uses the modern namespaced sound format (e.g., "minecraft:block.stone.break"). If the sound string is null or empty, no action is taken. Errors are logged but do not interrupt execution.
- Parameters:
sound- the namespaced sound identifiervolume- the volume (1.0 is normal volume)pitch- the pitch (1.0 is normal pitch)location- the location where the sound should be played
-
GetSound
Retrieves a Bukkit Sound enum constant by name.Searches the sound registry for a matching sound identifier (case-insensitive). Returns null if no matching sound is found.
- Parameters:
sound- the sound identifier to search for- Returns:
- the matching Sound enum constant, or null if not found
-
Play
Plays a Sound model to a player.Convenience method that extracts the key, volume, and pitch from a
instance and plays it to the player.invalid reference
valorless.havenbags.datamodels.ravencrest.Sound- Parameters:
sound- the sound model containing playback parametersplayer- the player who should hear the sound
-
Play
Plays a Sound model at a specific location.Convenience method that extracts the key, volume, and pitch from a
instance and plays it at the location.invalid reference
valorless.havenbags.datamodels.ravencrest.Sound- Parameters:
sound- the sound model containing playback parameterslocation- the location where the sound should be played
-
getSoundPlace
Retrieves the placement sound identifier for a block.Uses reflection to access the SoundGroup API, which may vary between versions. Returns a default stone placement sound if the block or sound cannot be determined.
- Parameters:
block- the block to get the placement sound for- Returns:
- the sound identifier string, or
DEFAULT_PLACEif unavailable
-
getSoundPlace
Retrieves the placement sound identifier for a material.Uses reflection to access the SoundGroup API via created block data. Returns null if the material is not a block, or the default sound if the sound cannot be determined.
- Parameters:
material- the material to get the placement sound for- Returns:
- the sound identifier string, or null if not a block
-
getSoundBreak
Retrieves the break sound identifier for a block.Uses reflection to access the SoundGroup API, which may vary between versions. Returns a default stone break sound if the block or sound cannot be determined.
- Parameters:
block- the block to get the break sound for- Returns:
- the sound identifier string, or
DEFAULT_BREAKif unavailable
-
getSoundBreak
Retrieves the break sound identifier for a material.Uses reflection to access the SoundGroup API via created block data. Returns null if the material is not a block, or the default sound if the sound cannot be determined.
- Parameters:
material- the material to get the break sound for- Returns:
- the sound identifier string, or null if not a block
-