mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2025-07-02 04:56:40 +00:00
rewrote the entitywiper
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user