From b2619fa7c79e58fea9e05c68a5bd7a9ecc2b5f46 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Tue, 13 Jul 2021 18:12:55 -0400 Subject: [PATCH] Address some null pointers (fixes #2378, #2380) --- .../world/JavaPlayBuiltinSoundTranslator.java | 4 +- .../world/JavaSpawnParticleTranslator.java | 37 ++++++++++--------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaPlayBuiltinSoundTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaPlayBuiltinSoundTranslator.java index b4873d7e7..ec7adc034 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaPlayBuiltinSoundTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaPlayBuiltinSoundTranslator.java @@ -34,6 +34,7 @@ import com.nukkitx.protocol.bedrock.packet.LevelSoundEventPacket; 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.BlockStateValues; import org.geysermc.connector.registry.BlockRegistries; import org.geysermc.connector.utils.SoundUtils; import org.geysermc.connector.registry.Registries; @@ -85,7 +86,8 @@ public class JavaPlayBuiltinSoundTranslator extends PacketTranslator { LevelEventPacket packet = new LevelEventPacket(); - packet.setType(typeParticle); + packet.setType(particleMapping.getLevelEventType()); packet.setPosition(position); return packet; }; + } else if (particleMapping.getIdentifier() != null) { + int dimensionId = DimensionUtils.javaToBedrock(session.getDimension()); + return (position) -> { + SpawnParticleEffectPacket stringPacket = new SpawnParticleEffectPacket(); + stringPacket.setIdentifier(particleMapping.getIdentifier()); + stringPacket.setDimensionId(dimensionId); + stringPacket.setPosition(position); + return stringPacket; + }; } else { - String stringParticle = Registries.PARTICLES.get(particle.getType()).getIdentifier(); - if (stringParticle != null) { - int dimensionId = DimensionUtils.javaToBedrock(session.getDimension()); - return (position) -> { - SpawnParticleEffectPacket stringPacket = new SpawnParticleEffectPacket(); - stringPacket.setIdentifier(stringParticle); - stringPacket.setDimensionId(dimensionId); - stringPacket.setPosition(position); - return stringPacket; - }; - } else { - return null; - } + return null; } + } } } } \ No newline at end of file