Skip to content

Commit

Permalink
fix mace sound on older versions
Browse files Browse the repository at this point in the history
  • Loading branch information
nossr50 committed Jan 4, 2025
1 parent 1db0aae commit bfbefa7
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/main/java/com/gmail/nossr50/util/sounds/SoundManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,18 @@
import org.bukkit.World;
import org.bukkit.entity.Player;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class SoundManager {
private static Sound CRIPPLE_SOUND;

private static final String ITEM_MACE_SMASH_GROUND = "ITEM_MACE_SMASH_GROUND";

private static final String VALUE_OF = "valueOf";

private static final String ORG_BUKKIT_SOUND = "org.bukkit.Sound";

/**
* Sends a sound to the player
* @param soundType the type of sound
Expand Down Expand Up @@ -110,12 +119,16 @@ private static Sound getCrippleSound() {
}

try {
CRIPPLE_SOUND = Sound.valueOf("ITEM_MACE_SMASH_GROUND");
return CRIPPLE_SOUND;
} catch (IllegalArgumentException e) {
// Spigot changed the class from enum to interface around 1.21.3
final Class<?> clazz = Class.forName(ORG_BUKKIT_SOUND);
final Method valueOf = clazz.getMethod(VALUE_OF);
CRIPPLE_SOUND = (Sound) valueOf.invoke(null, ITEM_MACE_SMASH_GROUND);
} catch (IllegalArgumentException | ClassNotFoundException | NoSuchMethodException | InvocationTargetException
| IllegalAccessException e) {
CRIPPLE_SOUND = Sound.BLOCK_ANVIL_PLACE;
return CRIPPLE_SOUND;
}

return CRIPPLE_SOUND;
}

public static float getFizzPitch() {
Expand Down

0 comments on commit bfbefa7

Please sign in to comment.