Skip to content

Commit

Permalink
add support for custom sounds, also an alternative to Sound.valueOf w…
Browse files Browse the repository at this point in the history
…hich throws errors on versions below 1.21.3
  • Loading branch information
Tanguygab committed Dec 1, 2024
1 parent abd23c9 commit a648baa
Showing 1 changed file with 5 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.extendedclip.deluxemenus.utils.VersionHelper;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.Bukkit;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.scheduler.BukkitRunnable;
Expand Down Expand Up @@ -354,32 +353,16 @@ public void run() {
case BROADCAST_SOUND:
case BROADCAST_WORLD_SOUND:
case PLAY_SOUND:
final Sound sound;
String sound;
float volume = 1;
float pitch = 1;

if (!executable.contains(" ")) {
try {
sound = Sound.valueOf(executable.toUpperCase());
} catch (final IllegalArgumentException exception) {
DeluxeMenus.printStacktrace(
"Sound name given for sound action: " + executable + ", is not a valid sound!",
exception
);
break;
}
sound = executable;
} else {
String[] parts = executable.split(" ", 3);

try {
sound = Sound.valueOf(parts[0].toUpperCase());
} catch (final IllegalArgumentException exception) {
DeluxeMenus.printStacktrace(
"Sound name given for sound action: " + parts[0] + ", is not a valid sound!",
exception
);
break;
}
sound = parts[0];

if (parts.length == 3) {
try {
Expand Down Expand Up @@ -415,6 +398,8 @@ public void run() {
}
}

sound = sound.toLowerCase().replace("_", ".");

switch (actionType) {
case BROADCAST_SOUND:
for (final Player broadcastTarget : Bukkit.getOnlinePlayers()) {
Expand Down

0 comments on commit a648baa

Please sign in to comment.