playSound

fun Player.playSound(sound: Sound, volume: Float = 1.0f, pitch: Float = 1.0f, category: SoundCategory = SoundCategory.MASTER)

Plays a sound to the player at their current location.

This is a convenient extension function that simplifies playing sounds to players by automatically using the player's current location and providing sensible defaults for common parameters.

Receiver

The player who will hear the sound.

Since

1.0.0

Example usage:

// Play a simple click sound
player.playSound(Sound.UI_BUTTON_CLICK)

// Play a louder explosion sound
player.playSound(Sound.ENTITY_GENERIC_EXPLODE, volume = 2.0f)

// Play a high-pitched ding sound in the records category
player.playSound(
sound = Sound.BLOCK_NOTE_BLOCK_PLING,
pitch = 2.0f,
category = SoundCategory.RECORDS
)

Parameters

sound

The sound effect to play. Use values from the Sound enum.

volume

The volume at which to play the sound. Default is 1.0 (100%). Values greater than 1.0 will be louder, values less than 1.0 will be quieter. The volume affects how far away the sound can be heard.

pitch

The pitch at which to play the sound. Default is 1.0 (normal pitch). Values range from 0.5 (lower pitch) to 2.0 (higher pitch). Affects the speed and tone of the sound.

category

The sound category this sound belongs to. Default is SoundCategory.MASTER. This determines which volume slider in the client's settings affects this sound.

See also

Sound

for available sound effects

SoundCategory

for available sound categories