From 699402e635919fdd1680cf7361cd4042264c382c Mon Sep 17 00:00:00 2001 From: AJ Ferguson Date: Mon, 6 Jul 2020 15:52:38 -0800 Subject: [PATCH] Fix bug with maps --- .../connector/network/session/GeyserSession.java | 3 ++- .../bedrock/BedrockMapInfoRequestTranslator.java | 11 +++++------ .../translators/java/world/JavaMapDataTranslator.java | 6 +----- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index 666820cc..6b51c892 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -48,6 +48,7 @@ import com.nukkitx.protocol.bedrock.BedrockServerSession; import com.nukkitx.protocol.bedrock.data.*; import com.nukkitx.protocol.bedrock.packet.*; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; +import it.unimi.dsi.fastutil.longs.Long2ObjectMaps; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2LongMap; import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap; @@ -107,7 +108,7 @@ public class GeyserSession implements CommandSender { private TeleportCache teleportCache; @Getter - private final Long2ObjectMap storedMaps = new Long2ObjectOpenHashMap<>(); + private final Long2ObjectMap storedMaps = Long2ObjectMaps.synchronize(new Long2ObjectOpenHashMap<>()); /** * A map of Vector3i positions to Java entity IDs. diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMapInfoRequestTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMapInfoRequestTranslator.java index 247021f1..11dfe46e 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMapInfoRequestTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMapInfoRequestTranslator.java @@ -25,6 +25,7 @@ package org.geysermc.connector.network.translators.bedrock; +import com.nukkitx.protocol.bedrock.packet.ClientboundMapItemDataPacket; import com.nukkitx.protocol.bedrock.packet.MapInfoRequestPacket; import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.network.session.GeyserSession; @@ -39,16 +40,14 @@ public class BedrockMapInfoRequestTranslator extends PacketTranslator { - session.sendUpstreamPacket(session.getStoredMaps().get(finalMapID)); - session.getStoredMaps().remove(finalMapID); + ClientboundMapItemDataPacket mapPacket = session.getStoredMaps().remove(mapID); + if (mapPacket != null) { + session.sendUpstreamPacket(mapPacket); + } }, 100, TimeUnit.MILLISECONDS); } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaMapDataTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaMapDataTranslator.java index 12ef1053..2aee7bc0 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaMapDataTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaMapDataTranslator.java @@ -85,11 +85,7 @@ public class JavaMapDataTranslator extends PacketTranslator // Store the map to send when the client requests it, as bedrock expects the data after a MapInfoRequestPacket if (shouldStore) { - long uniqueMapId = mapItemDataPacket.getUniqueMapId(); - if (uniqueMapId <= -1l) { - uniqueMapId = 0l; - } - session.getStoredMaps().put(uniqueMapId, mapItemDataPacket); + session.getStoredMaps().put(mapItemDataPacket.getUniqueMapId(), mapItemDataPacket); } // Send anyway just in case