From 5316c43a82718eaa30a0fb93bb9421b7a64c87ff Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Fri, 27 Jan 2012 21:49:55 -0600 Subject: [PATCH] Add getEntitesByClass(Class), getEntitiesByClasses(Class...), deprecate getEntitiesByClass(Class...) --- .../org/bukkit/craftbukkit/CraftWorld.java | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 26abc17566..e4cc45aa10 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -531,9 +531,37 @@ public class CraftWorld implements World { } @SuppressWarnings("unchecked") + @Deprecated public Collection getEntitiesByClass(Class... classes) { + return (Collection)getEntitiesByClasses(classes); + } + + @SuppressWarnings("unchecked") + public Collection getEntitiesByClass(Class clazz) { 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(); + + if (clazz.isAssignableFrom(bukkitClass)) { + list.add((T) bukkitEntity); + } + } + } + + return list; + } + + public Collection getEntitiesByClasses(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(); @@ -546,7 +574,7 @@ public class CraftWorld implements World { for (Class clazz : classes) { if (clazz.isAssignableFrom(bukkitClass)) { - list.add((T) bukkitEntity); + list.add(bukkitEntity); break; } }