From 7e9fc36a81ed6b09dfab2c032af85516ab7890a0 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 11 Mar 2022 20:38:09 +0100 Subject: [PATCH] No NPC respawning, No Fightservers, Potential portal depth fix --- src/de/steamwar/lobby/display/NPC.java | 8 ++++++ .../lobby/portal/FightserverPortal.java | 26 +++++++++++++------ src/de/steamwar/lobby/portal/Portal.java | 4 +-- 3 files changed, 28 insertions(+), 10 deletions(-) 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