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

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