Fixed moblimiter

This commit is contained in:
Steven Lawson 2011-11-21 00:54:11 -05:00
parent e621290fae
commit d8f2433c5b
3 changed files with 30 additions and 17 deletions

View File

@ -20,9 +20,9 @@ public class Command_mp extends TFM_Command
int removed = 0; int removed = 0;
for (World world : Bukkit.getWorlds()) for (World world : Bukkit.getWorlds())
{ {
for (Entity ent : world.getEntities()) for (Entity ent : world.getLivingEntities())
{ {
if (ent instanceof Creature || ent instanceof Ghast || ent instanceof Slime) if (ent instanceof Creature || ent instanceof Ghast || ent instanceof Slime || ent instanceof EnderDragon)
{ {
ent.remove(); ent.remove();
removed++; removed++;

View File

@ -3,7 +3,14 @@ package me.StevenLawson.TotalFreedomMod.Listener;
import me.StevenLawson.TotalFreedomMod.TFM_UserInfo; import me.StevenLawson.TotalFreedomMod.TFM_UserInfo;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Creature;
import org.bukkit.entity.EnderDragon;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Ghast;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Slime;
import org.bukkit.event.entity.*; import org.bukkit.event.entity.*;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
@ -83,11 +90,31 @@ public class TFM_EntityListener extends EntityListener
{ {
if (TotalFreedomMod.mobLimiterEnabled) if (TotalFreedomMod.mobLimiterEnabled)
{ {
if (event.getEntity() instanceof Ghast || event.getEntity() instanceof Slime || event.getEntity() instanceof EnderDragon)
{
event.setCancelled(true);
return;
}
if (TotalFreedomMod.mobLimiterMax > 0) if (TotalFreedomMod.mobLimiterMax > 0)
{ {
if (TFM_Util.getMobAmount(event.getEntity().getWorld()) > TotalFreedomMod.mobLimiterMax) int mobcount = 0;
for (World world : Bukkit.getWorlds())
{
for (Entity ent : world.getLivingEntities())
{
if (ent instanceof Creature || ent instanceof Ghast || ent instanceof Slime || ent instanceof EnderDragon)
{
mobcount++;
}
}
}
if (mobcount > TotalFreedomMod.mobLimiterMax)
{ {
event.setCancelled(true); event.setCancelled(true);
return;
} }
} }
} }

View File

@ -580,18 +580,4 @@ public class TFM_Util
} }
} }
} }
public static int getMobAmount(World world)
{
List<LivingEntity> mobs = world.getLivingEntities();
for (int j = 0; j < mobs.size(); j++)
{
if (!Creature.class.isInstance(mobs.get(j)))
{
mobs.remove(j);
j--;
}
}
return mobs.size();
}
} }