From 7d7b6226a0a00e1172626167a50a7acee69cc19c Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 11 Feb 2024 19:13:47 +0100 Subject: [PATCH] Potential Border rejoin fix Signed-off-by: Lixfel --- .../steamwar/fightsystem/fight/FightTeam.java | 2 +- .../steamwar/fightsystem/listener/Border.java | 39 ++++++++++++------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index 136ede0..4a2b1be 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -203,7 +203,7 @@ public class FightTeam { Set playerSet = new HashSet<>(players.keySet()); playerSet.removeIf(uuid -> { Player player = Bukkit.getPlayer(uuid); - if(player == null || !player.isOnline()) { + if(player == null) { removePlayer(players.get(uuid).getEntity()); return true; } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Border.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Border.java index 02c395a..6ab6605 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Border.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Border.java @@ -27,21 +27,19 @@ import de.steamwar.fightsystem.states.StateDependentTask; import de.steamwar.fightsystem.utils.FlatteningWrapper; import de.steamwar.fightsystem.utils.Region; import net.md_5.bungee.api.ChatMessageType; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Player; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.logging.Level; public class Border { - private final Map> ghostBarriers = new HashMap<>(); - private final Map lastLocation = new HashMap<>(); + private final Map> ghostBarriers = new HashMap<>(); + private final Map lastLocation = new HashMap<>(); private final boolean contain; private final String resetMessage; private final String name; @@ -61,22 +59,22 @@ public class Border { } public void addPlayer(Player player) { - if(ghostBarriers.containsKey(player) || !player.isOnline()) + if(ghostBarriers.containsKey(player.getUniqueId())) return; - ghostBarriers.put(player, new HashSet<>()); - lastLocation.put(player, player.getLocation()); + ghostBarriers.put(player.getUniqueId(), new HashSet<>()); + lastLocation.put(player.getUniqueId(), player.getLocation()); FightSystem.getPlugin().getLogger().log(Level.INFO, () -> player.getName() + " was added to border " + name); } public boolean contains(Player player) { - return ghostBarriers.containsKey(player); + return ghostBarriers.containsKey(player.getUniqueId()); } public void removePlayer(Player player) { FightSystem.getPlugin().getLogger().log(Level.INFO, () -> player.getName() + " was removed from border " + name); - lastLocation.remove(player); - Set blocks = ghostBarriers.remove(player); + lastLocation.remove(player.getUniqueId()); + Set blocks = ghostBarriers.remove(player.getUniqueId()); if(blocks == null || !player.isOnline()) return; @@ -85,11 +83,18 @@ public class Border { } private void run() { - for(Map.Entry> entry : ghostBarriers.entrySet()) { - Player player = entry.getKey(); + List offline = new ArrayList<>(); + for(Map.Entry> entry : ghostBarriers.entrySet()) { + UUID uuid = entry.getKey(); + Player player = Bukkit.getPlayer(uuid); + if(player == null) { + offline.add(uuid); + continue; + } + Location location = player.getLocation(); if(region.playerInRegion(location) != contain) { - player.teleport(lastLocation.get(player)); + player.teleport(lastLocation.get(uuid)); FightSystem.getMessage().sendPrefixless(resetMessage, player, ChatMessageType.ACTION_BAR); return; } @@ -122,6 +127,10 @@ public class Border { lastLocation.put(entry.getKey(), location); } + + offline.forEach(uuid -> FightSystem.getPlugin().getLogger().log(Level.INFO, () -> uuid + " was removed from border " + name)); + offline.forEach(ghostBarriers::remove); + offline.forEach(lastLocation::remove); } private void borderIteration(Player player, Set ghostBlocks, Region border) {