Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-11-19 14:30:17 +01:00
fix some NPEs caused by race conditions in chunk conversion (#1396)
* fix some NPEs caused by race conditions in chunk conversion tbh the whole session should be read-write locked for every operation * fix code style issues
Dieser Commit ist enthalten in:
Ursprung
191777773c
Commit
73bec588fa
@ -66,11 +66,11 @@ public class JavaChunkDataTranslator extends PacketTranslator<ServerChunkDataPac
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GeyserConnector.getInstance().getGeneralThreadPool().execute(() -> {
|
||||||
|
try {
|
||||||
// Non-full chunks don't have all the chunk data, and Bedrock won't accept that
|
// Non-full chunks don't have all the chunk data, and Bedrock won't accept that
|
||||||
final boolean isNonFullChunk = (packet.getColumn().getBiomeData() == null);
|
final boolean isNonFullChunk = (packet.getColumn().getBiomeData() == null);
|
||||||
|
|
||||||
GeyserConnector.getInstance().getGeneralThreadPool().execute(() -> {
|
|
||||||
try {
|
|
||||||
ChunkUtils.ChunkData chunkData = ChunkUtils.translateToBedrock(session, packet.getColumn(), isNonFullChunk);
|
ChunkUtils.ChunkData chunkData = ChunkUtils.translateToBedrock(session, packet.getColumn(), isNonFullChunk);
|
||||||
ByteBuf byteBuf = Unpooled.buffer(32);
|
ByteBuf byteBuf = Unpooled.buffer(32);
|
||||||
ChunkSection[] sections = chunkData.sections;
|
ChunkSection[] sections = chunkData.sections;
|
||||||
|
@ -25,12 +25,14 @@
|
|||||||
|
|
||||||
package org.geysermc.connector.network.translators.world;
|
package org.geysermc.connector.network.translators.world;
|
||||||
|
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.chunk.Column;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
|
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
|
||||||
import com.github.steveice10.mc.protocol.data.game.setting.Difficulty;
|
import com.github.steveice10.mc.protocol.data.game.setting.Difficulty;
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientChatPacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientChatPacket;
|
||||||
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
|
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
|
||||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
|
import org.geysermc.connector.network.session.cache.ChunkCache;
|
||||||
import org.geysermc.connector.utils.GameRule;
|
import org.geysermc.connector.utils.GameRule;
|
||||||
|
|
||||||
public class GeyserWorldManager extends WorldManager {
|
public class GeyserWorldManager extends WorldManager {
|
||||||
@ -39,14 +41,25 @@ public class GeyserWorldManager extends WorldManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getBlockAt(GeyserSession session, int x, int y, int z) {
|
public int getBlockAt(GeyserSession session, int x, int y, int z) {
|
||||||
return session.getChunkCache().getBlockAt(x, y, z);
|
ChunkCache chunkCache = session.getChunkCache();
|
||||||
|
if (chunkCache != null) { // Chunk cache can be null if the session is closed asynchronously
|
||||||
|
return chunkCache.getBlockAt(x, y, z);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int[] getBiomeDataAt(GeyserSession session, int x, int z) {
|
public int[] getBiomeDataAt(GeyserSession session, int x, int z) {
|
||||||
if (!session.getConnector().getConfig().isCacheChunks())
|
if (session.getConnector().getConfig().isCacheChunks()) {
|
||||||
|
ChunkCache chunkCache = session.getChunkCache();
|
||||||
|
if (chunkCache != null) { // Chunk cache can be null if the session is closed asynchronously
|
||||||
|
Column column = chunkCache.getChunk(x, z);
|
||||||
|
if (column != null) { // Column can be null if the server sent a partial chunk update before the first ground-up-continuous one
|
||||||
|
return column.getBiomeData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return new int[1024];
|
return new int[1024];
|
||||||
return session.getChunkCache().getChunk(x, z).getBiomeData();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren