diff --git a/src/de/steamwar/lobby/display/NPC.java b/src/de/steamwar/lobby/display/NPC.java index 426ca54..4a56d02 100644 --- a/src/de/steamwar/lobby/display/NPC.java +++ b/src/de/steamwar/lobby/display/NPC.java @@ -104,6 +104,14 @@ public class NPC { display = new Displayable(location, this::show, this::hide); } + public Location getLocation() { + return location; + } + + public UUID getUuid() { + return uuid; + } + private void show(Player player) { TinyProtocol.instance.sendPacket(player, addPlayerInfo); TinyProtocol.instance.sendPacket(player, namedSpawn); diff --git a/src/de/steamwar/lobby/portal/FightserverPortal.java b/src/de/steamwar/lobby/portal/FightserverPortal.java index 24ec55d..8b0873a 100644 --- a/src/de/steamwar/lobby/portal/FightserverPortal.java +++ b/src/de/steamwar/lobby/portal/FightserverPortal.java @@ -31,6 +31,7 @@ import org.bukkit.util.Vector; import java.util.*; import java.util.logging.Level; +import java.util.stream.Collectors; public class FightserverPortal implements PortalHandler, Comparable { @@ -121,15 +122,25 @@ public class FightserverPortal implements PortalHandler, Comparable locations, List npcs, List players) { - npcs.forEach(NPC::delete); - npcs.clear(); + List remainingPlayers = players.stream().map(SteamwarUser::get).collect(Collectors.toList()); + List remainingLocations = new ArrayList<>(locations); + npcs.removeIf(npc -> { + SteamwarUser user = SteamwarUser.get(npc.getUuid()); + if(remainingPlayers.contains(user)) { + remainingPlayers.remove(user); + remainingLocations.remove(npc.getLocation()); + return false; + } else { + npc.delete(); + return true; + } + }); - for(int i = 0; i < players.size(); i++) { - if(i >= locations.size()) + for(SteamwarUser user : remainingPlayers) { + if(remainingLocations.isEmpty()) break; - SteamwarUser user = SteamwarUser.get(players.get(i)); - npcs.add(new NPC(locations.get(i), user.getUUID(), user.getUserName())); + npcs.add(new NPC(remainingLocations.remove(0), user.getUUID(), user.getUserName())); } } @@ -206,14 +217,13 @@ public class FightserverPortal implements PortalHandler, Comparable