Class SFX

java.lang.Object
valorless.havenbags.utils.SFX

public class SFX extends Object
Sound effects utility class for playing sounds in various contexts.

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
    invalid reference
    valorless.havenbags.datamodels.ravencrest.Sound
    model
  • Block and material sound extraction using reflection
  • Fallback handling for version compatibility

Since:
1.0
Author:
Valorless
  • Constructor Summary

    Constructors
    Constructor
    Description
    SFX()
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static org.bukkit.Sound
    Retrieves a Bukkit Sound enum constant by name.
    static String
    getSoundBreak(org.bukkit.block.Block block)
    Retrieves the break sound identifier for a block.
    static String
    getSoundBreak(org.bukkit.Material material)
    Retrieves the break sound identifier for a material.
    static String
    getSoundPlace(org.bukkit.block.Block block)
    Retrieves the placement sound identifier for a block.
    static String
    getSoundPlace(org.bukkit.Material material)
    Retrieves the placement sound identifier for a material.
    static void
    Play(String sound, float volume, float pitch, org.bukkit.entity.Player player)
    Plays a sound at the player's location with the given volume and pitch.
    static void
    Play(String sound, float volume, float pitch, org.bukkit.Location location)
    Plays a sound at a specific location with the given volume and pitch.
    static void
    Play(Sound sound, org.bukkit.entity.Player player)
    Plays a Sound model to a player.
    static void
    Play(Sound sound, org.bukkit.Location location)
    Plays a Sound model at a specific location.
    static void
    PlayNamespace(String sound, float volume, float pitch, org.bukkit.entity.Player player)
    Plays a namespaced sound to a player.
    static void
    PlayNamespace(String sound, float volume, float pitch, org.bukkit.Location location)
    Plays a namespaced sound at a specific location.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SFX

      public SFX()
  • Method Details

    • Play

      public static void Play(String sound, float volume, float pitch, org.bukkit.entity.Player player)
      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 identifier
      volume - the volume (1.0 is normal volume)
      pitch - the pitch (1.0 is normal pitch)
      player - the player who should hear the sound
    • Play

      public static void Play(String sound, float volume, float pitch, org.bukkit.Location location)
      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 identifier
      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
    • GetSound

      public static org.bukkit.Sound GetSound(String sound)
      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

      public static void Play(Sound sound, org.bukkit.entity.Player player)
      Plays a Sound model to a player.

      Convenience method that extracts the key, volume, and pitch from a

      invalid reference
      valorless.havenbags.datamodels.ravencrest.Sound
      instance and plays it to the player.

      Parameters:
      sound - the sound model containing playback parameters
      player - the player who should hear the sound
    • Play

      public static void Play(Sound sound, org.bukkit.Location location)
      Plays a Sound model at a specific location.

      Convenience method that extracts the key, volume, and pitch from a

      invalid reference
      valorless.havenbags.datamodels.ravencrest.Sound
      instance and plays it at the location.

      Parameters:
      sound - the sound model containing playback parameters
      location - the location where the sound should be played
    • getSoundPlace

      public static String getSoundPlace(org.bukkit.block.Block block)
      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_PLACE if unavailable
    • getSoundPlace

      public static String getSoundPlace(org.bukkit.Material material)
      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

      public static String getSoundBreak(org.bukkit.block.Block block)
      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_BREAK if unavailable
    • getSoundBreak

      public static String getSoundBreak(org.bukkit.Material material)
      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