Skip to content

Commit

Permalink
Add precautions to prevent stack traces on incomplete/unknown place s…
Browse files Browse the repository at this point in the history
…ounds (GeyserMC#1717)
  • Loading branch information
Camotoy authored Dec 21, 2020
1 parent f5c0c54 commit dbfdae6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator;
import org.geysermc.connector.network.translators.world.block.BlockTranslator;
import org.geysermc.connector.network.translators.sound.SoundRegistry;
import org.geysermc.connector.network.translators.world.block.BlockTranslator;

@Translator(packet = ServerPlayBuiltinSoundPacket.class)
public class JavaPlayBuiltinSoundTranslator extends PacketTranslator<ServerPlayBuiltinSoundPacket> {
Expand Down Expand Up @@ -82,7 +82,11 @@ public void translate(ServerPlayBuiltinSoundPacket packet, GeyserSession session
// Bedrock has a number for each type of note, then proceeds up the scale by adding to that number
soundPacket.setExtraData(soundMapping.getExtraData() + (int)(Math.round((Math.log10(packet.getPitch()) / Math.log10(2)) * 12)) + 12);
} else if (sound == SoundEvent.PLACE && soundMapping.getExtraData() == -1) {
soundPacket.setExtraData(BlockTranslator.getBedrockBlockId(BlockTranslator.getJavaBlockState(soundMapping.getIdentifier())));
if (!soundMapping.getIdentifier().equals(":")) {
soundPacket.setExtraData(BlockTranslator.getBedrockBlockId(BlockTranslator.getJavaBlockState(soundMapping.getIdentifier())));
} else {
session.getConnector().getLogger().debug("PLACE sound mapping identifier was invalid! Please report: " + packet.toString());
}
soundPacket.setIdentifier(":");
} else {
soundPacket.setExtraData(soundMapping.getExtraData());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,12 @@ public static int getBlockStateVersion() {
return BLOCK_STATE_VERSION;
}

/**
* @param javaId the Java string identifier to search for
* @return the Java block state integer, or {@link #JAVA_AIR_ID} if there is no valid entry.
*/
public static int getJavaBlockState(String javaId) {
return JAVA_ID_BLOCK_MAP.get(javaId);
return JAVA_ID_BLOCK_MAP.getOrDefault(javaId, JAVA_AIR_ID);
}

public static boolean isWaterlogged(int state) {
Expand Down
2 changes: 1 addition & 1 deletion connector/src/main/resources/mappings
Submodule mappings updated 1 files
+2 −1 sounds.json

0 comments on commit dbfdae6

Please sign in to comment.