This commit is contained in:
ZeroEpoch1969
2020-01-24 23:27:16 -07:00
parent 47a62753d1
commit a37d8ecb31
23 changed files with 1243 additions and 189 deletions

View File

@ -7,6 +7,8 @@ import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
@ -23,7 +25,6 @@ public class EntityWiper extends FreedomService
EntityType.ARMOR_STAND,
EntityType.PAINTING,
EntityType.BOAT,
EntityType.PLAYER,
EntityType.LEASH_HITCH,
EntityType.ITEM_FRAME
);
@ -37,9 +38,9 @@ public class EntityWiper extends FreedomService
@Override
public void run()
{
wipe();
wipeEntities(false);
}
}.runTaskTimer(plugin, 1L, 300 * 5); // 5 minutes
}.runTaskTimer(plugin, 600L, 600L); // 30 second delay after startup + run every 30 seconds
}
@Override
@ -51,15 +52,19 @@ public class EntityWiper extends FreedomService
// Methods for wiping
public int wipe()
public int wipeEntities(boolean bypassBlacklist)
{
int removed = 0;
for (World world : Bukkit.getWorlds())
{
for (Entity entity : world.getEntities())
{
if (!BLACKLIST.contains(entity.getType()) || !Groups.MOB_TYPES.contains(entity.getType()))
if (!(entity instanceof Player))
{
if (!bypassBlacklist && (BLACKLIST.contains(entity.getType()) || Groups.MOB_TYPES.contains(entity.getType())))
{
continue;
}
entity.remove();
removed++;
}
@ -67,4 +72,44 @@ public class EntityWiper extends FreedomService
}
return removed;
}
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;
}
}