Skip to content

Commit

Permalink
Address some null pointers (fixes #2378, #2380)
Browse files Browse the repository at this point in the history
  • Loading branch information
Camotoy committed Jul 13, 2021
1 parent f7ef902 commit b2619fa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
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;
Expand Down Expand Up @@ -85,7 +86,8 @@ public void translate(ServerPlayBuiltinSoundPacket packet, GeyserSession session
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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
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;
Expand Down Expand Up @@ -129,30 +130,32 @@ private Function<Vector3f, BedrockPacket> createParticle(GeyserSession session,
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 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;
}
}
}
}
}

0 comments on commit b2619fa

Please sign in to comment.