From d8f2433c5b5ae98988da5c9ed0d780563d40d6fb Mon Sep 17 00:00:00 2001 From: Steven Lawson Date: Mon, 21 Nov 2011 00:54:11 -0500 Subject: [PATCH] Fixed moblimiter --- .../TotalFreedomMod/Commands/Command_mp.java | 4 +-- .../Listener/TFM_EntityListener.java | 29 ++++++++++++++++++- .../TotalFreedomMod/TFM_Util.java | 14 --------- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_mp.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_mp.java index f35985bf..4ce46165 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_mp.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_mp.java @@ -20,9 +20,9 @@ public class Command_mp extends TFM_Command int removed = 0; 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(); removed++; diff --git a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_EntityListener.java b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_EntityListener.java index d7004066..e3818ce5 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_EntityListener.java +++ b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_EntityListener.java @@ -3,7 +3,14 @@ package me.StevenLawson.TotalFreedomMod.Listener; import me.StevenLawson.TotalFreedomMod.TFM_UserInfo; import me.StevenLawson.TotalFreedomMod.TFM_Util; 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.Slime; import org.bukkit.event.entity.*; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; @@ -83,11 +90,31 @@ public class TFM_EntityListener extends EntityListener { 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 (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); + return; } } } diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java b/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java index 1fde91d0..5214ad13 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java @@ -580,18 +580,4 @@ public class TFM_Util } } } - - public static int getMobAmount(World world) - { - List 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(); - } }