kuper kant kode

This commit is contained in:
ZeroEpoch1969
2020-01-09 18:02:28 -07:00
parent cf21b8d07e
commit f989b34ada
3 changed files with 174 additions and 24 deletions

View File

@ -1,9 +1,12 @@
package me.totalfreedom.totalfreedommod;
import java.util.Arrays;
import java.util.List;
import me.totalfreedom.totalfreedommod.util.Groups;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.EntityType;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
@ -16,29 +19,34 @@ public class EntityWiper extends FreedomService
super(plugin);
}
public List<EntityType> BLACKLIST = Arrays.asList(
EntityType.ARMOR_STAND,
EntityType.PAINTING,
EntityType.BOAT,
EntityType.PLAYER,
EntityType.LEASH_HITCH,
EntityType.ITEM_FRAME
);
@Override
protected void onStart()
{
BLACKLIST.addAll(Groups.MOB_TYPES);
// Continuous Entity Wiper
wiper = new BukkitRunnable()
{
@Override
public void run()
{
for (World world : Bukkit.getWorlds())
{
if (world.getEntities().size() > 400)
{
world.getEntities().clear();
}
}
wipe();
}
}.runTaskTimer(plugin, 0, 1);
}.runTaskTimer(plugin, 1L, 300 * 5); // 5 minutes
}
@Override
protected void onStop()
{
BLACKLIST.removeAll(Groups.MOB_TYPES);
wiper.cancel();
wiper = null;
}
@ -52,7 +60,7 @@ public class EntityWiper extends FreedomService
{
for (Entity entity : world.getEntities())
{
if (!(entity instanceof Player))
if (!BLACKLIST.contains(entity.getType()))
{
entity.remove();
removed++;
@ -61,18 +69,4 @@ public class EntityWiper extends FreedomService
}
return removed;
}
public int wipe(World world)
{
int removed = 0;
for (Entity entity : world.getEntities())
{
if (!(entity instanceof Player))
{
entity.remove();
removed++;
}
}
return removed;
}
}