From 1a08e1104d357315d1103a7e641fc8053b4c677d Mon Sep 17 00:00:00 2001 From: YHDiamond <47502993+YHDiamond@users.noreply.github.com> Date: Sat, 2 Jan 2021 18:51:41 -0500 Subject: [PATCH] Fix stopsound bug (#1771) * Fix stopsound not working bug * removed extra imports * Update JavaPlayerStopSoundTranslator.java * Update JavaPlayerStopSoundTranslator.java * Update JavaPlayerStopSoundTranslator.java * Fix packet names and fix specific sounds not stopping Co-authored-by: YHDiamond <47502993+yehudahrrs@users.noreply.github.com> Co-authored-by: Camotoy <20743703+Camotoy@users.noreply.github.com> --- ...ator.java => JavaPlaySoundTranslator.java} | 6 +++--- .../JavaStopSoundTranslator.java} | 21 +++++++++++++------ 2 files changed, 18 insertions(+), 9 deletions(-) rename connector/src/main/java/org/geysermc/connector/network/translators/java/world/{JavaPlayerPlaySoundTranslator.java => JavaPlaySoundTranslator.java} (93%) rename connector/src/main/java/org/geysermc/connector/network/translators/java/{entity/player/JavaPlayerStopSoundTranslator.java => world/JavaStopSoundTranslator.java} (82%) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaPlayerPlaySoundTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaPlaySoundTranslator.java similarity index 93% rename from connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaPlayerPlaySoundTranslator.java rename to connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaPlaySoundTranslator.java index bce96f65d..238e9ba32 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaPlayerPlaySoundTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaPlaySoundTranslator.java @@ -36,14 +36,14 @@ import org.geysermc.connector.network.translators.Translator; import org.geysermc.connector.network.translators.sound.SoundRegistry; @Translator(packet = ServerPlaySoundPacket.class) -public class JavaPlayerPlaySoundTranslator extends PacketTranslator { +public class JavaPlaySoundTranslator extends PacketTranslator { @Override public void translate(ServerPlaySoundPacket packet, GeyserSession session) { String packetSound; - if(packet.getSound() instanceof BuiltinSound) { + if (packet.getSound() instanceof BuiltinSound) { packetSound = ((BuiltinSound) packet.getSound()).getName(); - } else if(packet.getSound() instanceof CustomSound) { + } else if (packet.getSound() instanceof CustomSound) { packetSound = ((CustomSound) packet.getSound()).getName(); } else { session.getConnector().getLogger().debug("Unknown sound packet, we were unable to map this. " + packet.toString()); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerStopSoundTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaStopSoundTranslator.java similarity index 82% rename from connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerStopSoundTranslator.java rename to connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaStopSoundTranslator.java index 61856755f..d7d0f0738 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerStopSoundTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaStopSoundTranslator.java @@ -23,7 +23,7 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.connector.network.translators.java.entity.player; +package org.geysermc.connector.network.translators.java.world; import com.github.steveice10.mc.protocol.data.game.world.sound.BuiltinSound; import com.github.steveice10.mc.protocol.data.game.world.sound.CustomSound; @@ -35,26 +35,35 @@ import org.geysermc.connector.network.translators.Translator; import org.geysermc.connector.network.translators.sound.SoundRegistry; @Translator(packet = ServerStopSoundPacket.class) -public class JavaPlayerStopSoundTranslator extends PacketTranslator { +public class JavaStopSoundTranslator extends PacketTranslator { @Override public void translate(ServerStopSoundPacket packet, GeyserSession session) { + // Runs if all sounds are stopped + if (packet.getSound() == null) { + StopSoundPacket stopPacket = new StopSoundPacket(); + stopPacket.setStoppingAllSound(true); + stopPacket.setSoundName(""); + session.sendUpstreamPacket(stopPacket); + return; + } + String packetSound; - if(packet.getSound() instanceof BuiltinSound) { + if (packet.getSound() instanceof BuiltinSound) { packetSound = ((BuiltinSound) packet.getSound()).getName(); - } else if(packet.getSound() instanceof CustomSound) { + } else if (packet.getSound() instanceof CustomSound) { packetSound = ((CustomSound) packet.getSound()).getName(); } else { session.getConnector().getLogger().debug("Unknown sound packet, we were unable to map this. " + packet.toString()); return; } - SoundRegistry.SoundMapping soundMapping = SoundRegistry.fromJava(packetSound); + SoundRegistry.SoundMapping soundMapping = SoundRegistry.fromJava(packetSound.replace("minecraft:", "")); session.getConnector().getLogger() .debug("[StopSound] Sound mapping " + packetSound + " -> " + soundMapping + (soundMapping == null ? "[not found]" : "") + " - " + packet.toString()); String playsound; - if(soundMapping == null || soundMapping.getPlaysound() == null) { + if (soundMapping == null || soundMapping.getPlaysound() == null) { // no mapping session.getConnector().getLogger() .debug("[StopSound] Defaulting to sound server gave us.");