diff --git a/src/dev/w1zzrd/invtweaks/command/MagnetCommandExecutor.java b/src/dev/w1zzrd/invtweaks/command/MagnetCommandExecutor.java index ac43459..36c1f46 100644 --- a/src/dev/w1zzrd/invtweaks/command/MagnetCommandExecutor.java +++ b/src/dev/w1zzrd/invtweaks/command/MagnetCommandExecutor.java @@ -3,7 +3,6 @@ package dev.w1zzrd.invtweaks.command; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; import org.bukkit.Location; -import org.bukkit.World; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -137,6 +136,28 @@ public class MagnetCommandExecutor implements CommandExecutor { } } + /** + * Remove all given UUIDs from the list of active magnets + * @param uuids UUIDs to remove from active magnets + * @return True if a call to this method changed the list of active magnets + */ + public boolean removeMagnets(final Iterable uuids) { + try { + boolean changed = false; + for(final UUID uuid : uuids) { + final int index = Collections.binarySearch(activeMagnets, uuid); + if (index < 0) + continue; + + activeMagnets.remove(index); + changed = true; + } + return changed; + } finally { + updateMagnetismTask(); + } + } + /** * Add a player to the list of active magnets * @param player Player to mark as a magnet @@ -236,7 +257,7 @@ public class MagnetCommandExecutor implements CommandExecutor { } // Remove logged-out players - toRemove.forEach(this::removeMagnet); + removeMagnets(toRemove); // Update subdivision to check next iteration divIndex = (divIndex + 1) % subdivide;