diff --git a/src/de/steamwar/lobby/LobbySystem.java b/src/de/steamwar/lobby/LobbySystem.java index 383d657..f87d9d4 100644 --- a/src/de/steamwar/lobby/LobbySystem.java +++ b/src/de/steamwar/lobby/LobbySystem.java @@ -84,7 +84,6 @@ public class LobbySystem extends JavaPlugin { @Override public void onDisable() { - TeamPlayer.cleanup(); } public static LobbySystem getPlugin() { diff --git a/src/de/steamwar/lobby/team/TeamPlayer.java b/src/de/steamwar/lobby/team/TeamPlayer.java index 040f842..75ddff8 100644 --- a/src/de/steamwar/lobby/team/TeamPlayer.java +++ b/src/de/steamwar/lobby/team/TeamPlayer.java @@ -79,11 +79,6 @@ public class TeamPlayer extends BasicListener { entities.put(name, npc); } - public static void cleanup() { - villagers.values().forEach(Entity::remove); - entities.values().forEach(NPC::delete); - } - { SteamwarUser.getServerTeam().forEach(user -> { spawnTeamPlayer(world, user); @@ -92,6 +87,14 @@ public class TeamPlayer extends BasicListener { AtomicInteger count = new AtomicInteger(); LobbySystem.getPlugin().getLogger().log(Level.INFO, "Loaded " + entities.size() + " team players"); Bukkit.getScheduler().runTaskTimer(LobbySystem.getPlugin(), () -> { + Collection active = world.getEntitiesByClass(Villager.class); + if (active.size() > entities.size()) { + Set duplicates = new HashSet<>(); + active.stream() + .filter(villager -> !duplicates.add(villager.getCustomName())) + .forEach(Entity::remove); + } + count.incrementAndGet(); if (count.get() % (20 * 60 * 60) == 0) { count.set(0);