diff --git a/src/main/java/net/citizensnpcs/util/PlayerUpdateTask.java b/src/main/java/net/citizensnpcs/util/PlayerUpdateTask.java index df97fc679..0d108ac44 100644 --- a/src/main/java/net/citizensnpcs/util/PlayerUpdateTask.java +++ b/src/main/java/net/citizensnpcs/util/PlayerUpdateTask.java @@ -1,10 +1,11 @@ package net.citizensnpcs.util; import java.util.ArrayList; -import java.util.HashSet; +import java.util.HashMap; import java.util.Iterator; import java.util.List; -import java.util.Set; +import java.util.Map; +import java.util.UUID; import org.bukkit.scheduler.BukkitRunnable; @@ -24,11 +25,17 @@ public class PlayerUpdateTask extends BukkitRunnable { @Override public void run() { - TICKERS.removeAll(TICKERS_PENDING_REMOVE); - TICKERS.addAll(TICKERS_PENDING_ADD); + for (int i = 0; i < TICKERS_PENDING_ADD.size(); i++) { + org.bukkit.entity.Entity ent = TICKERS_PENDING_ADD.get(i); + TICKERS.put(ent.getUniqueId(), ent); + } + for (int i = 0; i < TICKERS_PENDING_REMOVE.size(); i++) { + org.bukkit.entity.Entity ent = TICKERS_PENDING_REMOVE.get(i); + TICKERS.remove(ent.getUniqueId()); + } TICKERS_PENDING_ADD.clear(); TICKERS_PENDING_REMOVE.clear(); - Iterator itr = TICKERS.iterator(); + Iterator itr = TICKERS.values().iterator(); while (itr.hasNext()) { Entity entity = NMS.getHandle(itr.next()); Entity entity1 = entity.by(); @@ -57,14 +64,17 @@ public class PlayerUpdateTask extends BukkitRunnable { } public static void addOrRemove(org.bukkit.entity.Entity entity, boolean remove) { + boolean contains = TICKERS.containsKey(entity.getUniqueId()); if (!remove) { - TICKERS_PENDING_REMOVE.add(entity); - } else { + if (contains) { + TICKERS_PENDING_REMOVE.add(entity); + } + } else if (!contains) { TICKERS_PENDING_ADD.add(entity); } } - private static Set TICKERS = new HashSet(); + private static Map TICKERS = new HashMap(); private static List TICKERS_PENDING_ADD = new ArrayList(); private static List TICKERS_PENDING_REMOVE = new ArrayList(); }