TotalFreedomMod/src/main/java/me/totalfreedom/totalfreedommod/EntityWiper.java

70 lines
1.6 KiB
Java
Raw Normal View History

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()
{
// 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()
{
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-12 02:59:12 +00:00
if (!BLACKLIST.contains(entity.getType()) && !Groups.MOB_TYPES.contains(entity.getType()))
2020-01-09 11:56:25 +00:00
{
entity.remove();
removed++;
}
}
}
return removed;
}
}