fix: make the lists actually thread-safe (maybe, but pretty likely)

https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/Collections.html#synchronizedList(java.util.List)
> It is imperative that the user manually synchronize on the returned list when traversing it via Iterator, Spliterator or Stream
> Failure to follow this advice may result in non-deterministic behavior.
This commit is contained in:
ChomeNS
2025-04-21 20:15:47 +07:00
parent 1bb4d1713e
commit b8ea989026
9 changed files with 121 additions and 91 deletions

View File

@@ -15,8 +15,8 @@ import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.spaw
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.level.ServerboundAcceptTeleportationPacket;
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundMovePlayerPosPacket;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
// some part of the code used to be in a test plugin but i thought it would be useful in the future so i moved it here
public class PositionPlugin implements Listener {
@@ -28,9 +28,9 @@ public class PositionPlugin implements Listener {
private long tpCommandCooldownTime = 0;
private final Map<Integer, PlayerEntry> entityIdMap = new HashMap<>();
private final Map<Integer, Vector3d> positionMap = new HashMap<>();
private final Map<Integer, Rotation> rotationMap = new HashMap<>();
private final Map<Integer, PlayerEntry> entityIdMap = new ConcurrentHashMap<>();
private final Map<Integer, Vector3d> positionMap = new ConcurrentHashMap<>();
private final Map<Integer, Rotation> rotationMap = new ConcurrentHashMap<>();
public PositionPlugin (final Bot bot) {
this.bot = bot;