From 64d9068d3d7ccd5ebb9b3f872c972976e8151651 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 6 Apr 2023 20:02:06 +0200 Subject: [PATCH] Hotfix TeamPlayer infinite Villager glitch --- src/de/steamwar/lobby/LobbySystem.java | 1 - src/de/steamwar/lobby/team/TeamPlayer.java | 13 ++++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) 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);