3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-11-03 14:50:19 +01:00

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

Dieser Commit ist enthalten in:
Camotoy 2021-07-13 18:12:55 -04:00
Ursprung f7ef90278b
Commit b2619fa7c7
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 7EEFB66FE798081F
2 geänderte Dateien mit 23 neuen und 18 gelöschten Zeilen

Datei anzeigen

@ -34,6 +34,7 @@ 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.BlockStateValues;
import org.geysermc.connector.registry.BlockRegistries; import org.geysermc.connector.registry.BlockRegistries;
import org.geysermc.connector.utils.SoundUtils; import org.geysermc.connector.utils.SoundUtils;
import org.geysermc.connector.registry.Registries; 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); 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) {
if (!soundMapping.getIdentifier().equals(":")) { 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 { } else {
session.getConnector().getLogger().debug("PLACE sound mapping identifier was invalid! Please report: " + packet.toString()); session.getConnector().getLogger().debug("PLACE sound mapping identifier was invalid! Please report: " + packet.toString());
} }

Datei anzeigen

@ -39,6 +39,7 @@ 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.item.ItemTranslator; import org.geysermc.connector.network.translators.item.ItemTranslator;
import org.geysermc.connector.registry.Registries; import org.geysermc.connector.registry.Registries;
import org.geysermc.connector.registry.type.ParticleMapping;
import org.geysermc.connector.utils.DimensionUtils; import org.geysermc.connector.utils.DimensionUtils;
import java.util.Random; import java.util.Random;
@ -129,30 +130,32 @@ public class JavaSpawnParticleTranslator extends PacketTranslator<ServerSpawnPar
return packet; return packet;
}; };
} }
default: default: {
LevelEventType typeParticle = Registries.PARTICLES.get(particle.getType()).getLevelEventType(); ParticleMapping particleMapping = Registries.PARTICLES.get(particle.getType());
if (typeParticle != null) { if (particleMapping == null) { //TODO ensure no particle can be null
return null;
}
if (particleMapping.getLevelEventType() != null) {
return (position) -> { return (position) -> {
LevelEventPacket packet = new LevelEventPacket(); LevelEventPacket packet = new LevelEventPacket();
packet.setType(typeParticle); packet.setType(particleMapping.getLevelEventType());
packet.setPosition(position); packet.setPosition(position);
return packet; 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 { } else {
String stringParticle = Registries.PARTICLES.get(particle.getType()).getIdentifier(); return null;
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;
}
} }
}
} }
} }
} }