2020-01-09 11:56:25 +00:00
|
|
|
package me.totalfreedom.totalfreedommod;
|
|
|
|
|
2020-01-10 01:02:28 +00:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
|
|
|
import me.totalfreedom.totalfreedommod.util.Groups;
|
2020-01-09 11:56:25 +00:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.World;
|
|
|
|
import org.bukkit.entity.Entity;
|
2020-01-10 01:02:28 +00:00
|
|
|
import org.bukkit.entity.EntityType;
|
2020-01-09 11:56:25 +00:00
|
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
|
|
|
import org.bukkit.scheduler.BukkitTask;
|
|
|
|
|
|
|
|
public class EntityWiper extends FreedomService
|
|
|
|
{
|
|
|
|
private BukkitTask wiper;
|
|
|
|
|
|
|
|
public EntityWiper(TotalFreedomMod plugin)
|
|
|
|
{
|
|
|
|
super(plugin);
|
|
|
|
}
|
|
|
|
|
2020-01-10 01:02:28 +00:00
|
|
|
public List<EntityType> BLACKLIST = Arrays.asList(
|
|
|
|
EntityType.ARMOR_STAND,
|
|
|
|
EntityType.PAINTING,
|
|
|
|
EntityType.BOAT,
|
|
|
|
EntityType.PLAYER,
|
|
|
|
EntityType.LEASH_HITCH,
|
|
|
|
EntityType.ITEM_FRAME
|
|
|
|
);
|
|
|
|
|
2020-01-09 11:56:25 +00:00
|
|
|
@Override
|
|
|
|
protected void onStart()
|
|
|
|
{
|
2020-01-10 01:02:28 +00:00
|
|
|
BLACKLIST.addAll(Groups.MOB_TYPES);
|
2020-01-09 11:56:25 +00:00
|
|
|
// Continuous Entity Wiper
|
|
|
|
wiper = new BukkitRunnable()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void run()
|
|
|
|
{
|
2020-01-10 01:02:28 +00:00
|
|
|
wipe();
|
2020-01-09 11:56:25 +00:00
|
|
|
}
|
2020-01-10 01:02:28 +00:00
|
|
|
}.runTaskTimer(plugin, 1L, 300 * 5); // 5 minutes
|
2020-01-09 11:56:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onStop()
|
|
|
|
{
|
2020-01-10 01:02:28 +00:00
|
|
|
BLACKLIST.removeAll(Groups.MOB_TYPES);
|
2020-01-09 11:56:25 +00:00
|
|
|
wiper.cancel();
|
|
|
|
wiper = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Methods for wiping
|
|
|
|
|
|
|
|
public int wipe()
|
|
|
|
{
|
|
|
|
int removed = 0;
|
|
|
|
for (World world : Bukkit.getWorlds())
|
|
|
|
{
|
|
|
|
for (Entity entity : world.getEntities())
|
|
|
|
{
|
2020-01-10 01:02:28 +00:00
|
|
|
if (!BLACKLIST.contains(entity.getType()))
|
2020-01-09 11:56:25 +00:00
|
|
|
{
|
|
|
|
entity.remove();
|
|
|
|
removed++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return removed;
|
|
|
|
}
|
|
|
|
}
|