Class SFX

java.lang.Object
valorless.valorlessutils.sound.SFX

public class SFX extends Object
Sound effects helper methods.

This class provides:

  • Convenience methods for playing a sound given a String identifier for a Player or at a Location.
  • Support for namespaced sound keys (e.g. "minecraft:block.stone.place") via the String-based Bukkit sound API.
  • Utilities to derive the correct placement/break sound for a block/material using BlockData.getSoundGroup().

Identifier formats

Server version notes

On 1.17/1.17.1 this class plays enum sounds using the legacy overload Player.playSound(Location, Sound, float, float). On later versions it uses Player.playSound(Player, Sound, float, float).

  • Constructor Summary

    Constructors
    Constructor
    Description
    SFX()
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static org.bukkit.Sound
    Resolves a string sound name to a Sound from Registry.SOUNDS.
    static String
    getSoundBreak(org.bukkit.block.Block block)
    Returns a break sound identifier for the given block.
    static String
    getSoundBreak(org.bukkit.Material material)
    Returns a break sound identifier for the given material.
    static String
    getSoundPlace(org.bukkit.block.Block block)
    Returns a placement sound identifier for the given block.
    static String
    getSoundPlace(org.bukkit.Material material)
    Returns a placement sound identifier for the given material.
    static void
    Play(String sound, float volume, float pitch, org.bukkit.entity.Player player)
    Plays a sound for a player.
    static void
    Play(String sound, float volume, float pitch, org.bukkit.Location location)
    Plays a sound at a location.
    static void
    PlayNamespace(String sound, float volume, float pitch, org.bukkit.entity.Player player)
    Plays a namespaced/string sound for a player in the SoundCategory.MASTER category.
    static void
    PlayNamespace(String sound, float volume, float pitch, org.bukkit.Location location)
    Plays a namespaced/string sound at a location in the SoundCategory.MASTER category.

    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 for a player.

      Behavior:

      • If sound is null or empty, nothing is played.
      • For server versions 1.17/1.17.1: plays the resolved Sound at the player's location.
      • For later versions: if sound contains a dot, treats it as a namespaced key and calls PlayNamespace(String, float, float, Player); otherwise resolves to Sound via GetSound(String) and plays it to the player.
      Parameters:
      sound - sound identifier (enum style like "BLOCK_NOTE_BLOCK_PLING", or a namespaced key like "minecraft:entity.player.levelup")
      volume - volume multiplier
      pitch - pitch multiplier
      player - target player
    • PlayNamespace

      public static void PlayNamespace(String sound, float volume, float pitch, org.bukkit.entity.Player player)
      Plays a namespaced/string sound for a player in the SoundCategory.MASTER category.
      Parameters:
      sound - namespaced sound key (e.g. "minecraft:block.stone.place")
      volume - volume multiplier
      pitch - pitch multiplier
      player - target player
    • Play

      public static void Play(String sound, float volume, float pitch, org.bukkit.Location location)
      Plays a sound at a location.

      If sound contains a dot, it is treated as a namespaced key and this method delegates to PlayNamespace(String, float, float, Location). Otherwise sound is resolved to a Sound via GetSound(String) and played in the location's world.

      Parameters:
      sound - sound identifier (enum style or namespaced)
      volume - volume multiplier
      pitch - pitch multiplier
      location - target location
    • PlayNamespace

      public static void PlayNamespace(String sound, float volume, float pitch, org.bukkit.Location location)
      Plays a namespaced/string sound at a location in the SoundCategory.MASTER category.
      Parameters:
      sound - namespaced sound key (e.g. "minecraft:block.stone.place")
      volume - volume multiplier
      pitch - pitch multiplier
      location - target location (must have a non-null world)
    • GetSound

      public static org.bukkit.Sound GetSound(String sound)
      Resolves a string sound name to a Sound from Registry.SOUNDS.

      Matching is performed using String.equalsIgnoreCase(String) against Sound#toString().

      Parameters:
      sound - enum-like sound name (typically uppercase), e.g. "BLOCK_STONE_PLACE"
      Returns:
      the resolved Sound, or null when not found
    • getSoundPlace

      public static String getSoundPlace(org.bukkit.block.Block block)
      Returns a placement sound identifier for the given block.

      Uses BlockData.getSoundGroup() and reflectively invokes SoundGroup#getPlaceSound() to remain compatible with server implementations where the concrete return type may change. If a sound cannot be determined, a safe default is returned.

      Parameters:
      block - block to inspect
      Returns:
      a sound identifier (usually enum-style); never null
    • getSoundPlace

      public static String getSoundPlace(org.bukkit.Material material)
      Returns a placement sound identifier for the given material.
      Parameters:
      material - material to inspect
      Returns:
      a sound identifier; null if material is null or not a block
    • getSoundBreak

      public static String getSoundBreak(org.bukkit.block.Block block)
      Returns a break sound identifier for the given block.
      Parameters:
      block - block to inspect
      Returns:
      a sound identifier (usually enum-style); never null
    • getSoundBreak

      public static String getSoundBreak(org.bukkit.Material material)
      Returns a break sound identifier for the given material.
      Parameters:
      material - material to inspect
      Returns:
      a sound identifier; null if material is null or not a block