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-25 06:27:16 +00:00
|
|
|
import org.bukkit.entity.LivingEntity;
|
|
|
|
import org.bukkit.entity.Player;
|
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.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-25 06:27:16 +00:00
|
|
|
wipeEntities(false);
|
2020-01-09 11:56:25 +00:00
|
|
|
}
|
2020-01-25 06:27:16 +00:00
|
|
|
}.runTaskTimer(plugin, 600L, 600L); // 30 second delay after startup + run every 30 seconds
|
2020-01-09 11:56:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onStop()
|
|
|
|
{
|
|
|
|
wiper.cancel();
|
|
|
|
wiper = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Methods for wiping
|
|
|
|
|
2020-01-25 06:27:16 +00:00
|
|
|
public int wipeEntities(boolean bypassBlacklist)
|
2020-01-09 11:56:25 +00:00
|
|
|
{
|
|
|
|
int removed = 0;
|
|
|
|
for (World world : Bukkit.getWorlds())
|
|
|
|
{
|
|
|
|
for (Entity entity : world.getEntities())
|
|
|
|
{
|
2020-01-25 06:27:16 +00:00
|
|
|
if (!(entity instanceof Player))
|
2020-01-09 11:56:25 +00:00
|
|
|
{
|
2020-04-22 08:23:51 +00:00
|
|
|
if ((!bypassBlacklist && BLACKLIST.contains(entity.getType())) || Groups.MOB_TYPES.contains(entity.getType()))
|
2020-01-25 06:27:16 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2020-01-09 11:56:25 +00:00
|
|
|
entity.remove();
|
|
|
|
removed++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return removed;
|
|
|
|
}
|
2020-01-25 06:27:16 +00:00
|
|
|
|
|
|
|
public int wipeEntities(EntityType entityType)
|
|
|
|
{
|
|
|
|
int removed = 0;
|
|
|
|
for (World world : Bukkit.getWorlds())
|
|
|
|
{
|
|
|
|
for (Entity entity : world.getEntities())
|
|
|
|
{
|
|
|
|
if (!entity.getType().equals(entityType))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
entity.remove();
|
|
|
|
removed++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return removed;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int purgeMobs(EntityType type)
|
|
|
|
{
|
|
|
|
int removed = 0;
|
|
|
|
for (World world : Bukkit.getWorlds())
|
|
|
|
{
|
|
|
|
for (Entity entity : world.getLivingEntities())
|
|
|
|
{
|
|
|
|
if (entity instanceof LivingEntity && !(entity instanceof Player))
|
|
|
|
{
|
|
|
|
if (type != null && !entity.getType().equals(type))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
entity.remove();
|
|
|
|
removed++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return removed;
|
|
|
|
}
|
|
|
|
|
2020-01-22 03:37:51 +00:00
|
|
|
}
|