Skip to content

Commit

Permalink
Fix stopsound bug (GeyserMC#1771)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: Camotoy <[email protected]>
  • Loading branch information
3 people authored Jan 2, 2021
1 parent 396d1b6 commit 1a08e11
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
import org.geysermc.connector.network.translators.sound.SoundRegistry;

@Translator(packet = ServerPlaySoundPacket.class)
public class JavaPlayerPlaySoundTranslator extends PacketTranslator<ServerPlaySoundPacket> {
public class JavaPlaySoundTranslator extends PacketTranslator<ServerPlaySoundPacket> {

@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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,26 +35,35 @@
import org.geysermc.connector.network.translators.sound.SoundRegistry;

@Translator(packet = ServerStopSoundPacket.class)
public class JavaPlayerStopSoundTranslator extends PacketTranslator<ServerStopSoundPacket> {
public class JavaStopSoundTranslator extends PacketTranslator<ServerStopSoundPacket> {

@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.");
Expand Down

0 comments on commit 1a08e11

Please sign in to comment.