diff --git a/src/main/java/me/totalfreedom/totalfreedommod/EntityWiper.java b/src/main/java/me/totalfreedom/totalfreedommod/EntityWiper.java deleted file mode 100644 index 2ec46083..00000000 --- a/src/main/java/me/totalfreedom/totalfreedommod/EntityWiper.java +++ /dev/null @@ -1,213 +0,0 @@ -package me.totalfreedom.totalfreedommod; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import lombok.Getter; -import me.totalfreedom.totalfreedommod.config.ConfigEntry; -import me.totalfreedom.totalfreedommod.util.FUtil; -import org.bukkit.Bukkit; -import org.bukkit.Chunk; -import org.bukkit.World; -import org.bukkit.entity.AreaEffectCloud; -import org.bukkit.entity.ArmorStand; -import org.bukkit.entity.Boat; -import org.bukkit.entity.DragonFireball; -import org.bukkit.entity.EnderCrystal; -import org.bukkit.entity.EnderPearl; -import org.bukkit.entity.EnderSignal; -import org.bukkit.entity.Entity; -import org.bukkit.entity.ExperienceOrb; -import org.bukkit.entity.Explosive; -import org.bukkit.entity.FallingBlock; -import org.bukkit.entity.Fireball; -import org.bukkit.entity.Firework; -import org.bukkit.entity.Item; -import org.bukkit.entity.Minecart; -import org.bukkit.entity.Projectile; -import org.bukkit.entity.ThrownExpBottle; -import org.bukkit.entity.ThrownPotion; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.entity.ItemSpawnEvent; -import org.bukkit.event.player.PlayerDropItemEvent; -import org.bukkit.scheduler.BukkitRunnable; -import org.bukkit.scheduler.BukkitTask; - -public class EntityWiper extends FreedomService -{ - - @Getter - private boolean enabled; - public static final long ENTITY_WIPE_RATE = 5 * 20L; - public static final long ITEM_DESPAWN_RATE = 20L * 20L; - public static final int CHUNK_ENTITY_MAX = 20; - // - private final List> wipables = new ArrayList<>(); - // - private BukkitTask wipeTask; - - public EntityWiper(TotalFreedomMod plugin) - { - super(plugin); - wipables.add(EnderCrystal.class); - wipables.add(EnderSignal.class); - wipables.add(EnderPearl.class); - wipables.add(ExperienceOrb.class); - wipables.add(Projectile.class); - wipables.add(FallingBlock.class); - wipables.add(Firework.class); - wipables.add(Item.class); - wipables.add(ThrownPotion.class); - wipables.add(ThrownExpBottle.class); - wipables.add(AreaEffectCloud.class); - wipables.add(Minecart.class); - wipables.add(Boat.class); - wipables.add(FallingBlock.class); - wipables.add(ArmorStand.class); - wipables.add(Fireball.class); - wipables.add(DragonFireball.class); - wipables.add(Minecart.class); - } - - @Override - protected void onStart() - { - if (!ConfigEntry.AUTO_ENTITY_WIPE.getBoolean()) - { - return; - } - - wipeTask = new BukkitRunnable() - { - - @Override - public void run() - { - wipeEntities(false); - } - }.runTaskTimer(plugin, ENTITY_WIPE_RATE, ENTITY_WIPE_RATE); - - } - - @Override - protected void onStop() - { - FUtil.cancel(wipeTask); - wipeTask = null; - } - - public boolean isWipeable(Entity entity) - { - for (Class c : wipables) - { - if (c.isAssignableFrom(entity.getClass())) - { - return true; - } - } - - return false; - } - - public int wipeEntities(boolean force) - { - int removed = 0; - Iterator worlds = Bukkit.getWorlds().iterator(); - while (worlds.hasNext()) - { - removed += wipeEntities(worlds.next(), force); - } - - return removed; - } - - public int wipeEntities(World world, boolean force) - { - int removed = 0; - - boolean wipeExpl = !ConfigEntry.ALLOW_EXPLOSIONS.getBoolean(); - Iterator entities = world.getEntities().iterator(); - - // Organise the entities in the world - Map> cem = new HashMap<>(); - while (entities.hasNext()) - { - final Entity entity = entities.next(); - - // Explosives - if (wipeExpl && Explosive.class.isAssignableFrom(entity.getClass())) - { - entity.remove(); - removed++; - } - - // Only wipeable entities can be wiped (duh!) - if (!isWipeable(entity)) - { - continue; - } - - Chunk c = entity.getLocation().getChunk(); - List cel = cem.get(c); - if (cel == null) - { - cem.put(c, new ArrayList<>(Arrays.asList(entity))); - } - else - { - cel.add(entity); - } - } - - // Now purge the entities if necessary - for (Chunk c : cem.keySet()) - { - List cel = cem.get(c); - - if (!force && cel.size() < CHUNK_ENTITY_MAX) - { - continue; - } - - // Too many entities in this chunk, wipe them all - for (Entity e : cel) - { - e.remove(); - removed++; - } - } - - return removed; - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onItemSpawn(ItemSpawnEvent event) - { - final Item entity = event.getEntity(); - - new BukkitRunnable() - { - - @Override - public void run() - { - entity.remove(); - } - }.runTaskLater(plugin, ITEM_DESPAWN_RATE); - - } - - @EventHandler - public void onDrop(PlayerDropItemEvent event) - { - enabled = ConfigEntry.AUTO_ENTITY_WIPE.getBoolean(); - if (enabled) - { - event.setCancelled(true); - } - } -} diff --git a/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java b/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java index 48893d42..43895c14 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java @@ -113,7 +113,6 @@ public class TotalFreedomMod extends AeroPlugin public AutoEject ae; public Monitors mo; public MovementValidator mv; - public EntityWiper ew; public ServerPing sp; public CurseListener cul; public ItemFun it; @@ -228,7 +227,6 @@ public class TotalFreedomMod extends AeroPlugin mv = services.registerService(MovementValidator.class); - ew = services.registerService(EntityWiper.class); sp = services.registerService(ServerPing.class); pv = services.registerService(PlayerVerification.class); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_entitywipe.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_entitywipe.java index 2d834163..ceca6734 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_entitywipe.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_entitywipe.java @@ -2,8 +2,11 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; +import org.bukkit.Bukkit; +import org.bukkit.World; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH) @@ -15,7 +18,16 @@ public class Command_entitywipe extends FreedomCommand public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { FUtil.adminAction(sender.getName(), "Removing all server entities", true); - msg((plugin.ew.wipeEntities(true)) + " entities removed."); + int removed = 0; + for (World world : Bukkit.getWorlds()) + { + for (Entity entity : world.getEntities()) + { + entity.remove(); + removed++; + } + } + msg(removed + " entities removed."); return true; } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_purgeall.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_purgeall.java index cc4df7c6..091b972c 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_purgeall.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_purgeall.java @@ -3,8 +3,11 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; +import org.bukkit.Bukkit; +import org.bukkit.World; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffect; @@ -19,7 +22,13 @@ public class Command_purgeall extends FreedomCommand FUtil.adminAction(sender.getName(), "Purging all player data", true); // Purge entities - plugin.ew.wipeEntities(true); + for (World world : Bukkit.getWorlds()) + { + for (Entity entity : world.getEntities()) + { + entity.remove(); + } + } for (Player player : server.getOnlinePlayers()) {