rewrote the entitywiper

This commit is contained in:
Super_ 2020-01-09 06:56:25 -05:00
parent 81621d260d
commit cf21b8d07e
3 changed files with 81 additions and 12 deletions

View File

@ -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;
}
}

View File

@ -126,6 +126,7 @@ public class TotalFreedomMod extends AeroPlugin<TotalFreedomMod>
public MasterBuilderWorldRestrictions mbwr; public MasterBuilderWorldRestrictions mbwr;
public SignBlocker snp; public SignBlocker snp;
public PlayerVerification pv; public PlayerVerification pv;
public EntityWiper ew;
//public HubWorldRestrictions hwr; //public HubWorldRestrictions hwr;
// //
// Bridges // Bridges
@ -210,6 +211,7 @@ public class TotalFreedomMod extends AeroPlugin<TotalFreedomMod>
pa = services.registerService(ProtectArea.class); pa = services.registerService(ProtectArea.class);
gr = services.registerService(GameRuleHandler.class); gr = services.registerService(GameRuleHandler.class);
snp = services.registerService(SignBlocker.class); snp = services.registerService(SignBlocker.class);
ew = services.registerService(EntityWiper.class);
// Single admin utils // Single admin utils
rb = services.registerService(RollbackManager.class); rb = services.registerService(RollbackManager.class);

View File

@ -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) public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{ {
FUtil.adminAction(sender.getName(), "Removing all server entities", true); FUtil.adminAction(sender.getName(), "Removing all server entities", true);
int removed = 0; int removed = plugin.ew.wipe();
for (World world : Bukkit.getWorlds())
{
for (Entity entity : world.getEntities())
{
if (!(entity instanceof Player))
{
entity.remove();
removed++;
}
}
}
msg(removed + " entities removed."); msg(removed + " entities removed.");
return true; return true;