Add precautions to prevent stack traces on incomplete/unknown place sounds (#1717)

This commit is contained in:
Camotoy 2020-12-20 20:42:14 -05:00 committed by GitHub
parent f5c0c549ef
commit dbfdae63f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 4 deletions

View file

@ -34,8 +34,8 @@ import com.nukkitx.protocol.bedrock.packet.LevelSoundEventPacket;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator; 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.sound.SoundRegistry;
import org.geysermc.connector.network.translators.world.block.BlockTranslator;
@Translator(packet = ServerPlayBuiltinSoundPacket.class) @Translator(packet = ServerPlayBuiltinSoundPacket.class)
public class JavaPlayBuiltinSoundTranslator extends PacketTranslator<ServerPlayBuiltinSoundPacket> { public class JavaPlayBuiltinSoundTranslator extends PacketTranslator<ServerPlayBuiltinSoundPacket> {
@ -82,7 +82,11 @@ public class JavaPlayBuiltinSoundTranslator extends PacketTranslator<ServerPlayB
// Bedrock has a number for each type of note, then proceeds up the scale by adding to that number // 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); soundPacket.setExtraData(soundMapping.getExtraData() + (int)(Math.round((Math.log10(packet.getPitch()) / Math.log10(2)) * 12)) + 12);
} else if (sound == SoundEvent.PLACE && soundMapping.getExtraData() == -1) { } 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(":"); soundPacket.setIdentifier(":");
} else { } else {
soundPacket.setExtraData(soundMapping.getExtraData()); soundPacket.setExtraData(soundMapping.getExtraData());

View file

@ -343,8 +343,12 @@ public class BlockTranslator {
return BLOCK_STATE_VERSION; 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) { 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) { public static boolean isWaterlogged(int state) {

@ -1 +1 @@
Subproject commit 2d14c9dc3d75df7463fc7605a6cff63b5926a03e Subproject commit 3f4707c0d26427dfe2ac79eca68e6048732f4412