-
-
Notifications
You must be signed in to change notification settings - Fork 922
(Improvement) Implement playing sound by string ID #5201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I've replaced enum-based sound playing events with string-based equivalents, which should open the door for server customization and other enhancements in the future - Added SoundLookup class with different registry lookup methods depending on server version. - Added the ability to configure what sounds are played depending on event, with a fallback built into SoundType. - Removed getCrippleSound as SoundLookup can now fall back to the original default sound if the mace sound doesn't exist on the server's Minecraft version. - Added a EnableCustomSounds config variable that will skip SoundLookup ID checking and just pass the sound string directly to the client, mainly due to the fact that it isn't possible to verify if resource pack values exist. - Cleaned up a few switch statements to match how the original getSound had it formatted. I'd love to see/do a further expansion of sound configuration for each ability now that we can just fall back to generic, but that may be for another PR.
|
@JeBobs have you test on Spigot and Paper? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR replaces enum-based sound playing with string-based sound IDs to enable server customization and future enhancements. The implementation adds a sound lookup system that can handle different Minecraft server versions and provides fallback mechanisms for unsupported sounds.
Key changes:
- Added string-based sound ID system with configurable sound mappings
- Implemented SoundLookup class with version-aware registry checking
- Added EnableCustomSounds configuration option for resource pack compatibility
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| sounds.yml | Adds sound ID mappings and EnableCustomSounds configuration option |
| SoundType.java | Converts enum to include default sound IDs and modernizes switch syntax |
| SoundManager.java | Replaces enum-based sound lookup with string-based system using SoundLookup |
| SoundLookup.java | New utility class for checking sound existence across different server versions |
| SoundConfig.java | Adds methods to retrieve sound IDs and custom sound configuration |
| BLEED("minecraft:entity.ender_eye.death"), | ||
| GLASS("minecraft:block.glass.break"), | ||
| ITEM_CONSUMED("minecraft:item.bottle.empty"), | ||
| CRIPPLE("minecraft:block.anvil.place"); |
Copilot
AI
Aug 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CRIPPLE sound is using 'minecraft:block.anvil.place' as fallback, but based on the sounds.yml configuration, it should use 'minecraft:item.mace.smash_ground'. This inconsistency means the fallback won't match the configured sound ID.
| CRIPPLE("minecraft:block.anvil.place"); | |
| CRIPPLE("minecraft:item.mace.smash_ground"); |
|
|
||
| public boolean getCustomSoundEnabled() { | ||
| String key = "Sounds.EnableCustomSounds"; | ||
| return config.getBoolean(key, true); |
Copilot
AI
Aug 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default value for EnableCustomSounds should be 'false' to match the configuration file default, not 'true'. This could cause unexpected behavior when the configuration is not explicitly set.
| return config.getBoolean(key, true); | |
| return config.getBoolean(key, false); |
| } | ||
|
|
||
| public boolean getIsEnabled(SoundType soundType) { | ||
| String key = "Sounds." + soundType.toString() + ".Enabled"; |
Copilot
AI
Aug 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The key construction uses '.Enabled' but the YAML configuration uses '.Enable' (without 'd'). This will cause the configuration lookup to fail and always return the default value.
| String key = "Sounds." + soundType.toString() + ".Enabled"; | |
| String key = "Sounds." + soundType.toString() + ".Enable"; |
| Class<?> registry = Class.forName("org.bukkit.Registry"); | ||
| Object soundReg = registry.getField("SOUND_EVENT").get(null); | ||
| Method get = soundReg.getClass().getMethod("get", NamespacedKey.class); | ||
| return get.invoke(soundReg, NamespacedKey.fromString(id)) != null; |
Copilot
AI
Aug 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NamespacedKey.fromString(id) can throw IllegalArgumentException for invalid namespaced keys. This should be wrapped in a try-catch block to prevent the exception from propagating and causing the method to return false incorrectly.
| return get.invoke(soundReg, NamespacedKey.fromString(id)) != null; | |
| NamespacedKey key; | |
| try { | |
| key = NamespacedKey.fromString(id); | |
| } catch (IllegalArgumentException e) { | |
| return false; | |
| } | |
| return get.invoke(soundReg, key) != null; |
|
@JeBobs Don't mind the copilot comments too much, I saw the "request review from copilot" and was wondering what the heck it would even do, so I pressed it to "try it and see". |
|
i tested spigot 1.20.4 and paper 1.21.4 as those are what I've had on hand, but I'll do more extensive testing later today |
Mostly, I'd want you to test Spigot and Paper for the oldest supported version as well to make sure no exceptions are being thrown / etc. As of right now, that would be Minecraft version |
|
I appreciate you taking time for manual testing. |
|
I'll make some tweaks to your branch and merge afterwards, might not get to it this weekend. |
|
@JeBobs I'm making some optimizations now, reflection calls are expensive and should be cached. I'm also changing how custom sounds are defined, you'll see soon. |

I've replaced enum-based sound playing events with string-based equivalents, which should open the door for server customization and other enhancements in the future
I'd love to see/do a further expansion of sound configuration for each ability now that we can just fall back to generic, but that may be for another PR.