diff --git a/src/main/java/me/totalfreedom/totalfreedommod/EntityWiper.java b/src/main/java/me/totalfreedom/totalfreedommod/EntityWiper.java new file mode 100644 index 00000000..d2bbd94b --- /dev/null +++ b/src/main/java/me/totalfreedom/totalfreedommod/EntityWiper.java @@ -0,0 +1,78 @@ +package me.totalfreedom.totalfreedommod; + +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; + +public class EntityWiper extends FreedomService +{ + private BukkitTask wiper; + + public EntityWiper(TotalFreedomMod plugin) + { + super(plugin); + } + + @Override + protected void onStart() + { + // Continuous Entity Wiper + wiper = new BukkitRunnable() + { + @Override + public void run() + { + for (World world : Bukkit.getWorlds()) + { + if (world.getEntities().size() > 400) + { + world.getEntities().clear(); + } + } + } + }.runTaskTimer(plugin, 0, 1); + } + + @Override + protected void onStop() + { + wiper.cancel(); + wiper = null; + } + + // Methods for wiping + + public int wipe() + { + int removed = 0; + for (World world : Bukkit.getWorlds()) + { + for (Entity entity : world.getEntities()) + { + if (!(entity instanceof Player)) + { + entity.remove(); + removed++; + } + } + } + return removed; + } + + public int wipe(World world) + { + int removed = 0; + for (Entity entity : world.getEntities()) + { + if (!(entity instanceof Player)) + { + entity.remove(); + removed++; + } + } + return removed; + } +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java b/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java index 43895c14..fcb4913f 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java @@ -126,6 +126,7 @@ public class TotalFreedomMod extends AeroPlugin public MasterBuilderWorldRestrictions mbwr; public SignBlocker snp; public PlayerVerification pv; + public EntityWiper ew; //public HubWorldRestrictions hwr; // // Bridges @@ -210,6 +211,7 @@ public class TotalFreedomMod extends AeroPlugin pa = services.registerService(ProtectArea.class); gr = services.registerService(GameRuleHandler.class); snp = services.registerService(SignBlocker.class); + ew = services.registerService(EntityWiper.class); // Single admin utils rb = services.registerService(RollbackManager.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 805f4446..617798d8 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_entitywipe.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_entitywipe.java @@ -18,18 +18,7 @@ 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); - int removed = 0; - for (World world : Bukkit.getWorlds()) - { - for (Entity entity : world.getEntities()) - { - if (!(entity instanceof Player)) - { - entity.remove(); - removed++; - } - } - } + int removed = plugin.ew.wipe(); msg(removed + " entities removed."); return true;