From b17191b553ce17a833fbde41779c8bea80b1dbe3 Mon Sep 17 00:00:00 2001 From: chris Date: Sat, 22 Jul 2023 04:25:09 +0200 Subject: [PATCH] Fix /playsound command by stripping only the Minecraft namespace (#3956) Fixes https://github.com/GeyserMC/Geyser/issues/3953 --- .../org/geysermc/geyser/util/SoundUtils.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/util/SoundUtils.java b/core/src/main/java/org/geysermc/geyser/util/SoundUtils.java index 18c37d0b0..b56d9873b 100644 --- a/core/src/main/java/org/geysermc/geyser/util/SoundUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/SoundUtils.java @@ -65,20 +65,20 @@ public final class SoundUtils { * @return a Bedrock sound */ public static String translatePlaySound(String javaIdentifier) { - SoundMapping soundMapping = Registries.SOUNDS.get(trim(javaIdentifier)); + String soundIdentifier = removeMinecraftNamespace(javaIdentifier); + SoundMapping soundMapping = Registries.SOUNDS.get(soundIdentifier); if (soundMapping == null || soundMapping.getPlaysound() == null) { // no mapping GeyserImpl.getInstance().getLogger().debug("[PlaySound] Defaulting to sound server gave us for " + javaIdentifier); - return javaIdentifier; + return soundIdentifier; } return soundMapping.getPlaysound(); } - private static String trim(String identifier) { - // Drop any namespace if applicable - int i = identifier.indexOf(':'); - if (i >= 0) { - return identifier.substring(i + 1); + private static String removeMinecraftNamespace(String identifier) { + // Drop any minecraft namespace if applicable + if (identifier.startsWith("minecraft:")) { + return identifier.substring("minecraft:".length()); } return identifier; } @@ -101,12 +101,12 @@ public final class SoundUtils { * @param pitch the pitch */ public static void playSound(GeyserSession session, Sound javaSound, Vector3f position, float volume, float pitch) { - String packetSound = javaSound.getName(); + String soundIdentifier = removeMinecraftNamespace(javaSound.getName()); - SoundMapping soundMapping = Registries.SOUNDS.get(packetSound); + SoundMapping soundMapping = Registries.SOUNDS.get(soundIdentifier); if (soundMapping == null) { - session.getGeyser().getLogger().debug("[Builtin] Sound mapping for " + packetSound + " not found; assuming custom."); - playSound(session, packetSound, position, volume, pitch); + session.getGeyser().getLogger().debug("[Builtin] Sound mapping for " + soundIdentifier + " not found; assuming custom."); + playSound(session, soundIdentifier, position, volume, pitch); return; } @@ -128,10 +128,10 @@ public final class SoundUtils { LevelSoundEventPacket soundPacket = new LevelSoundEventPacket(); SoundEvent sound = SoundUtils.toSoundEvent(soundMapping.getBedrock()); if (sound == null) { - sound = SoundUtils.toSoundEvent(packetSound); + sound = SoundUtils.toSoundEvent(soundIdentifier); } if (sound == null) { - session.getGeyser().getLogger().debug("[Builtin] Sound for original '" + packetSound + "' to mappings '" + soundMapping.getBedrock() + session.getGeyser().getLogger().debug("[Builtin] Sound for original '" + soundIdentifier + "' to mappings '" + soundMapping.getBedrock() + "' was not a playable level sound, or has yet to be mapped to an enum in SoundEvent."); return; }