From f7585e552d2ff2cf5fbec7a255b6358d60d2513a Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Sun, 11 Dec 2011 17:27:53 -0600 Subject: [PATCH] [Bleeding] Implemented World.getEntitiesByClass(Class... classes) --- .../org/bukkit/craftbukkit/CraftWorld.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 41090e7778..dd5388e44d 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -8,6 +8,7 @@ import org.bukkit.entity.*; import org.bukkit.entity.Entity; import java.util.ArrayList; +import java.util.Collection; import java.util.HashSet; import java.util.concurrent.ConcurrentMap; import java.util.List; @@ -525,6 +526,32 @@ public class CraftWorld implements World { return list; } + @SuppressWarnings("unchecked") + public Collection getEntitiesByClass(Class... classes) { + Collection list = new ArrayList(); + + for (Object entity: world.entityList) { + if (entity instanceof net.minecraft.server.Entity) { + Entity bukkitEntity = ((net.minecraft.server.Entity) entity).getBukkitEntity(); + + if (bukkitEntity == null) { + continue; + } + + Class bukkitClass = bukkitEntity.getClass(); + + for (Class clazz : classes) { + if (clazz.isAssignableFrom(bukkitClass)) { + list.add((T) bukkitEntity); + break; + } + } + } + } + + return list; + } + public List getPlayers() { List list = new ArrayList();