Skip to content

Commit

Permalink
fix: IncompatibleClassChangeError on org.bukkit.Sound
Browse files Browse the repository at this point in the history
Closes #131
  • Loading branch information
RoinujNosde committed Dec 29, 2024
1 parent 83d36a4 commit 1a4d7fc
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/main/java/me/roinujnosde/titansbattle/utils/SoundUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;

public class SoundUtils {
Expand Down Expand Up @@ -38,13 +40,26 @@ public static void playSound(@NotNull Type type, @NotNull FileConfiguration conf
if (soundName.isEmpty()) return;
Sound sound = null;
try {
sound = Sound.valueOf(soundName.toUpperCase(Locale.ROOT));
sound = getSound(soundName.toUpperCase(Locale.ROOT));
} catch (IllegalArgumentException e) {
LOGGER.warning(String.format("Invalid sound: %s", soundName));
}
if (sound == null) {
return;
}
player.playSound(player.getLocation(), sound, 1F, 1F);
}

private static Sound getSound(String name) {
try {
Method valueOf = Sound.class.getMethod("valueOf", String.class);
return (Sound) valueOf.invoke(null, name);
} catch (ReflectiveOperationException ex) {
LOGGER.log(Level.SEVERE, "Error getting sound object", ex);
return null;
}
}

public enum Type {
JOIN_GAME, LEAVE_GAME, ALLY_DEATH, ENEMY_DEATH, WATCH, TELEPORT, VICTORY, BORDER
}
Expand Down

0 comments on commit 1a4d7fc

Please sign in to comment.