forked from GeyserMC/Geyser
Fix bug with maps
This commit is contained in:
parent
02905c2a35
commit
699402e635
3 changed files with 8 additions and 12 deletions
|
@ -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<ClientboundMapItemDataPacket> storedMaps = new Long2ObjectOpenHashMap<>();
|
||||
private final Long2ObjectMap<ClientboundMapItemDataPacket> storedMaps = Long2ObjectMaps.synchronize(new Long2ObjectOpenHashMap<>());
|
||||
|
||||
/**
|
||||
* A map of Vector3i positions to Java entity IDs.
|
||||
|
|
|
@ -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<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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,11 +85,7 @@ public class JavaMapDataTranslator extends PacketTranslator<ServerMapDataPacket>
|
|||
|
||||
// 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
|
||||
|
|
Loading…
Reference in a new issue