Sound Utils
Allows to parse and play sounds privately for a player or broadcast them across the server/dimension
Introduction
A fully functional Version of this class has first been introduced in Version 2.1.0
(Before SI: Essentials 2.3.0 known as SoundParser)
The Sound Utils class allows you to parse Sound IDs (you can find a list here) to a SoundEvent which you can then use to either play a sound privately for one player or broadcast it across the entire server/an entire dimension.
Class
File: SoundUtils.java
Package: dev.soncresityindustries.es.api.v0.util
Methods
parseSoundOrDefaultSuccess
public static SoundEvent parseSoundOrDefaultSuccess(@Nullable String soundID) {}Parses the SoundEvent from a Sound ID (you can find a list here) or defaults to SOUND_FEEDBACK_SUCCESS_ID (or sound_feedback_success_id).
Warning
Before SI: Essentials 2.2.0, this method would always return SoundEvents.PLAYER_LEVELUP!
Usage
SoundEvent soundEvent = SoundUtils.parseSoundOrDefaultSuccess(soundID);parseSoundOrDefaultClick
public static SoundEvent parseSoundOrDefaultClick(@Nullable String soundID) {}Parses the SoundEvent from a Sound ID (you can find a list here) or defaults to SOUND_FEEDBACK_CLICK_ID (or sound_feedback_click_id).
Usage
SoundEvent soundEvent = SoundUtils.parseSoundOrDefaultClick(soundID);parseSoundOrDefaultFail
public static SoundEvent parseSoundOrDefaultFail(@Nullable String soundID) {}Parses the SoundEvent from a Sound ID (you can find a list here) or defaults to SOUND_FEEDBACK_FAIL_ID (or sound_feedback_fail_id).
Warning
Before SI: Essentials 2.2.0, this method would always return SoundEvents.NOTE_BLOCK_BASS!
Usage
SoundEvent soundEvent = SoundUtils.parseSoundOrDefaultFail(soundID);parseSoundOrDefault
public static SoundEvent parseSoundOrDefault(@Nullable String soundID, @NotNull SoundEvent defaultSound) {}Parses the SoundEvent from a Sound ID (you can find a list here) or defaults to the specified defaultSound sound value.
Usage
SoundEvent soundEvent = SoundUtils.parseSoundOrDefault(soundID, defaultSound);playSuccessSound
Older versions
Older versions of this method won't be documented anymore since they underwent significant changes in SI: Essentials 2.3.0 and the old versions are now considered outdated and should not be used anymore.
public static void playSuccessSound(@NotNull ServerPlayer player, @NotNull SoundType soundType, @NotNull SoundSource soundSource, @NotNull Vec3 position) {}Plays the parsed SOUND_FEEDBACK_SUCCESS_ID (or sound_feedback_success_id) sound privately or publicly (depending on SoundType) while respecting the player's choice through ENABLE_SOUND_FEEDBACK (or enable_sound_feedback).
Usage
SoundUtils.playSuccessSound(player, soundType, soundSource, player.position());playClickSound
public static void playClickSound(@NotNull ServerPlayer player, @NotNull SoundType soundType, @NotNull SoundSource soundSource, @NotNull Vec3 position) {}Plays the parsed SOUND_FEEDBACK_CLICK_ID (or sound_feedback_click_id) sound privately or publicly (depending on SoundType) while respecting the player's choice through ENABLE_SOUND_FEEDBACK (or enable_sound_feedback).
Usage
SoundUtils.playClickSound(player, soundType, soundSource, player.position());playFailSound
Older versions
Older versions of this method won't be documented anymore since they underwent significant changes in SI: Essentials 2.3.0 and the old versions are now considered outdated and should not be used anymore.
public static void playFailSound(@NotNull ServerPlayer player, @NotNull SoundType soundType, @NotNull SoundSource soundSource, @NotNull Vec3 position) {}Plays the parsed SOUND_FEEDBACK_FAIL_ID (or sound_feedback_fail_id) sound privately or publicly (depending on SoundType) while respecting the player's choice through ENABLE_SOUND_FEEDBACK (or enable_sound_feedback).
Usage
SoundUtils.playFailSound(player, soundType, soundSource, player.position());forcePlaySound
public static void forcePlaySound(@NotNull ServerPlayer player, @NotNull SoundType soundType, @NotNull SoundEvent soundEvent, @NotNull SoundSource soundSource, @NotNull Vec3 position, float volume, float pitch) {}Forces to play a sound privately or publicly (depending on SoundType) regardless of ENABLE_SOUND_FEEDBACK (or enable_sound_feedback).
Usage
SoundUtils.forcePlaySound(player, soundType, soundEvent, soundSource, player.position(), volume, pitch);playSound
Older versions
Older versions of this method won't be documented anymore since they underwent significant changes in SI: Essentials 2.3.0 and the old versions are now considered outdated and should not be used anymore.
public static void playSound(@NotNull ServerPlayer player, @NotNull SoundType soundType, @NotNull SoundEvent soundEvent, @NotNull SoundSource soundSource, @NotNull Vec3 position, float volume, float pitch) {}Plays a sound privately or publicly (depending on SoundType) while respecting the player's choice through ENABLE_SOUND_FEEDBACK (or enable_sound_feedback).
Usage
SoundUtils.playSound(player, soundType, soundEvent, soundSource, player.position(), volume, pitch);SoundType
Since SI: Essentials 2.3.0, you can specify the SoundType which defines whether the sound should be played privately for the player, in the level at the players position, publicly for all players in the same dimension or publicly across the server.
Those 4 SoundTypes are defined in the SoundType enum which is located in the dev.soncresityindustries.es.api.v0.constant package. Those enum constants are:
SoundType.PRIVATE- The sound will only be played for the specified player.SoundType.DIMENSION- The sound will be played in the dimension of the source/player at the specified position and can be heard by all players nearby.SoundType.BROADCAST_DIMENSION- The sound will be played for all players in the same dimension as the specified source/player regardless of their distance.SoundType.BROADCAST_SERVER- The sound will be played for all players on the server regardless of their dimension (providing a source is still required to access all players on the server).