-
-
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
Changes from 1 commit
05162fb
22f9a0f
2c202cb
e89d44e
e51d00b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -61,8 +61,18 @@ public float getPitch(SoundType soundType) { | |||||
| return (float) config.getDouble(key, 1.0); | ||||||
| } | ||||||
|
|
||||||
| public String getSound(SoundType soundType) { | ||||||
| String key = "Sounds." + soundType.toString() + ".ID"; | ||||||
| return (String) config.getString(key); | ||||||
| } | ||||||
|
|
||||||
| public boolean getIsEnabled(SoundType soundType) { | ||||||
| String key = "Sounds." + soundType.toString() + ".Enabled"; | ||||||
| return config.getBoolean(key, true); | ||||||
| } | ||||||
|
|
||||||
| public boolean getCustomSoundEnabled() { | ||||||
| String key = "Sounds.EnableCustomSounds"; | ||||||
| return config.getBoolean(key, true); | ||||||
|
||||||
| return config.getBoolean(key, true); | |
| return config.getBoolean(key, false); |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,50 @@ | ||||||||||||||||||
| package com.gmail.nossr50.util.sounds; | ||||||||||||||||||
|
|
||||||||||||||||||
| import org.bukkit.NamespacedKey; | ||||||||||||||||||
| import java.lang.reflect.*; | ||||||||||||||||||
| import java.util.Locale; | ||||||||||||||||||
|
|
||||||||||||||||||
| public final class SoundLookup { | ||||||||||||||||||
|
|
||||||||||||||||||
| private static final boolean USE_PAPER_REGISTRY; | ||||||||||||||||||
|
|
||||||||||||||||||
| static { | ||||||||||||||||||
| boolean paper = false; | ||||||||||||||||||
| try { Class.forName("org.bukkit.Registry"); paper = true; } catch (ClassNotFoundException ignored) {} | ||||||||||||||||||
| USE_PAPER_REGISTRY = paper; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| public static boolean exists(String id) { | ||||||||||||||||||
| if (USE_PAPER_REGISTRY) return paperRegistryExists(id); | ||||||||||||||||||
| return legacyEnumExists(id); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| private static boolean paperRegistryExists(String id) { | ||||||||||||||||||
| try { | ||||||||||||||||||
| 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; | ||||||||||||||||||
|
||||||||||||||||||
| 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; |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,31 +1,33 @@ | ||||||
| package com.gmail.nossr50.util.sounds; | ||||||
|
|
||||||
| public enum SoundType { | ||||||
| ANVIL, | ||||||
| LEVEL_UP, | ||||||
| FIZZ, | ||||||
| ITEM_BREAK, | ||||||
| POP, | ||||||
| CHIMAERA_WING, | ||||||
| ROLL_ACTIVATED, | ||||||
| SKILL_UNLOCKED, | ||||||
| DEFLECT_ARROWS, | ||||||
| TOOL_READY, | ||||||
| ABILITY_ACTIVATED_GENERIC, | ||||||
| ABILITY_ACTIVATED_BERSERK, | ||||||
| BLEED, | ||||||
| GLASS, | ||||||
| ITEM_CONSUMED, | ||||||
| CRIPPLE, | ||||||
| TIRED; | ||||||
|
|
||||||
| public boolean usesCustomPitch() { | ||||||
| switch (this) { | ||||||
| case POP: | ||||||
| case FIZZ: | ||||||
| return true; | ||||||
| default: | ||||||
| return false; | ||||||
| } | ||||||
| ANVIL("minecraft:block.anvil.place"), | ||||||
| ITEM_BREAK("minecraft:entity.item.break"), | ||||||
| POP("minecraft:entity.item.pickup"), | ||||||
| CHIMAERA_WING("minecraft:entity.bat.takeoff"), | ||||||
| LEVEL_UP("minecraft:entity.player.levelup"), | ||||||
| FIZZ("minecraft:block.fire.extinguish"), | ||||||
| TOOL_READY("minecraft:item.armor.equip_gold"), | ||||||
| ROLL_ACTIVATED("minecraft:entity.llama.swag"), | ||||||
| SKILL_UNLOCKED("minecraft:ui.toast.challenge_complete"), | ||||||
| ABILITY_ACTIVATED_BERSERK("minecraft:block.conduit.ambient"), | ||||||
| TIRED("minecraft:block.conduit.ambient"), | ||||||
| ABILITY_ACTIVATED_GENERIC("minecraft:item.trident.riptide_3"), | ||||||
| DEFLECT_ARROWS("minecraft:entity.ender_eye.death"), | ||||||
| BLEED("minecraft:entity.ender_eye.death"), | ||||||
| GLASS("minecraft:block.glass.break"), | ||||||
| ITEM_CONSUMED("minecraft:item.bottle.empty"), | ||||||
| CRIPPLE("minecraft:block.anvil.place"); | ||||||
|
||||||
| CRIPPLE("minecraft:block.anvil.place"); | |
| CRIPPLE("minecraft:item.mace.smash_ground"); |
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.