Fix bug where players could remove other players on zone change

This commit is contained in:
kuroppoi 2022-08-09 01:39:16 +02:00
parent 5f8e9c78ff
commit 1adb97a10c
2 changed files with 12 additions and 4 deletions

View file

@ -151,6 +151,7 @@ public class Player extends Entity implements CommandExecutor {
private int teleportY;
private long lastHeartbeat;
private long lastTrackedEntityUpdate;
private Zone nextZone;
private Connection connection;
@ConstructorProperties({"documentId", "name", "current_zone"})
@ -339,6 +340,12 @@ public class Player extends Entity implements CommandExecutor {
zone.removeEntity(this);
}
// Are we switching zones? Then set the new zone.
if(nextZone != null) {
zone = nextZone;
nextZone = null;
}
dialogs.clear();
activeChunks.clear();
@ -394,8 +401,7 @@ public class Player extends Entity implements CommandExecutor {
}
public void changeZone(Zone zone) {
this.zone.removeEntity(this);
this.zone = zone;
nextZone = zone;
sendMessage(new EventMessage("playerWillChangeZone", null));
kick("Teleporting...", true);
}

View file

@ -226,6 +226,10 @@ public class EntityManager {
public void removeEntity(Entity entity) {
int entityId = entity.getId();
if(!entities.remove(entityId, entity)) {
return;
}
if(entity instanceof Player) {
players.remove(entityId);
playersByName.remove(entity.getName());
@ -233,8 +237,6 @@ public class EntityManager {
} else {
npcs.remove(entityId);
}
entities.remove(entityId);
}
public Entity getEntity(int entityId) {