Skip to content

Commit

Permalink
Fix bug with maps
Browse files Browse the repository at this point in the history
  • Loading branch information
AJ-Ferguson committed Jul 6, 2020
1 parent 02905c2 commit 699402e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
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;
Expand Down Expand Up @@ -107,7 +108,7 @@ public class GeyserSession implements CommandSender {
private TeleportCache teleportCache;

@Getter
private final Long2ObjectMap<ClientboundMapItemDataPacket> storedMaps = new Long2ObjectOpenHashMap<>();
private final Long2ObjectMap<ClientboundMapItemDataPacket> storedMaps = Long2ObjectMaps.synchronize(new Long2ObjectOpenHashMap<>());

/**
* A map of Vector3i positions to Java entity IDs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -39,16 +40,14 @@ public class BedrockMapInfoRequestTranslator extends PacketTranslator<MapInfoReq
@Override
public void translate(MapInfoRequestPacket packet, GeyserSession session) {
long mapID = packet.getUniqueMapId();
if (mapID <= -1l) {
mapID = 0l;
}

if (session.getStoredMaps().containsKey(mapID)) {
// Delay the packet 100ms to prevent the client from ignoring the packet
long finalMapID = mapID;
GeyserConnector.getInstance().getGeneralThreadPool().schedule(() -> {
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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,7 @@ public void translate(ServerMapDataPacket packet, GeyserSession session) {

// 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
Expand Down

0 comments on commit 699402e

Please sign in to comment.