Address some null pointers (fixes #2378, #2380)

This commit is contained in:
Camotoy 2021-07-13 18:12:55 -04:00
parent f7ef90278b
commit b2619fa7c7
No known key found for this signature in database
GPG key ID: 7EEFB66FE798081F
2 changed files with 23 additions and 18 deletions

View file

@ -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<ServerPlayB
soundPacket.setExtraData(soundMapping.getExtraData() + (int)(Math.round((Math.log10(packet.getPitch()) / Math.log10(2)) * 12)) + 12);
} else if (sound == SoundEvent.PLACE && soundMapping.getExtraData() == -1) {
if (!soundMapping.getIdentifier().equals(":")) {
soundPacket.setExtraData(session.getBlockMappings().getBedrockBlockId(BlockRegistries.JAVA_IDENTIFIERS.get(soundMapping.getIdentifier())));
soundPacket.setExtraData(session.getBlockMappings().getBedrockBlockId(
BlockRegistries.JAVA_IDENTIFIERS.getOrDefault(soundMapping.getIdentifier(), BlockStateValues.JAVA_AIR_ID)));
} else {
session.getConnector().getLogger().debug("PLACE sound mapping identifier was invalid! Please report: " + packet.toString());
}

View file

@ -39,6 +39,7 @@ import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator;
import org.geysermc.connector.network.translators.item.ItemTranslator;
import org.geysermc.connector.registry.Registries;
import org.geysermc.connector.registry.type.ParticleMapping;
import org.geysermc.connector.utils.DimensionUtils;
import java.util.Random;
@ -129,22 +130,24 @@ public class JavaSpawnParticleTranslator extends PacketTranslator<ServerSpawnPar
return packet;
};
}
default:
LevelEventType typeParticle = Registries.PARTICLES.get(particle.getType()).getLevelEventType();
if (typeParticle != null) {
default: {
ParticleMapping particleMapping = Registries.PARTICLES.get(particle.getType());
if (particleMapping == null) { //TODO ensure no particle can be null
return null;
}
if (particleMapping.getLevelEventType() != null) {
return (position) -> {
LevelEventPacket packet = new LevelEventPacket();
packet.setType(typeParticle);
packet.setType(particleMapping.getLevelEventType());
packet.setPosition(position);
return packet;
};
} else {
String stringParticle = Registries.PARTICLES.get(particle.getType()).getIdentifier();
if (stringParticle != null) {
} else if (particleMapping.getIdentifier() != null) {
int dimensionId = DimensionUtils.javaToBedrock(session.getDimension());
return (position) -> {
SpawnParticleEffectPacket stringPacket = new SpawnParticleEffectPacket();
stringPacket.setIdentifier(stringParticle);
stringPacket.setIdentifier(particleMapping.getIdentifier());
stringPacket.setDimensionId(dimensionId);
stringPacket.setPosition(position);
return stringPacket;