diff options
author | Mike Primm <mike@primmhome.com> | 2012-01-27 21:49:55 -0600 |
---|---|---|
committer | EvilSeph <evilseph@gmail.com> | 2012-02-18 16:34:53 -0500 |
commit | 5316c43a82718eaa30a0fb93bb9421b7a64c87ff (patch) | |
tree | 5b844025a1861d303e97a63d63ab1bf1840946d7 /src | |
parent | 137880b727a4870ead5e2f113c045685e5ff8222 (diff) | |
download | craftbukkit-5316c43a82718eaa30a0fb93bb9421b7a64c87ff.tar craftbukkit-5316c43a82718eaa30a0fb93bb9421b7a64c87ff.tar.gz craftbukkit-5316c43a82718eaa30a0fb93bb9421b7a64c87ff.tar.lz craftbukkit-5316c43a82718eaa30a0fb93bb9421b7a64c87ff.tar.xz craftbukkit-5316c43a82718eaa30a0fb93bb9421b7a64c87ff.zip |
Add getEntitesByClass(Class<T>), getEntitiesByClasses(Class<?>...), deprecate getEntitiesByClass(Class<T>...)
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/CraftWorld.java | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 26abc175..e4cc45aa 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -531,7 +531,13 @@ public class CraftWorld implements World { } @SuppressWarnings("unchecked") + @Deprecated public <T extends Entity> Collection<T> getEntitiesByClass(Class<T>... classes) { + return (Collection<T>)getEntitiesByClasses(classes); + } + + @SuppressWarnings("unchecked") + public <T extends Entity> Collection<T> getEntitiesByClass(Class<T> clazz) { Collection<T> list = new ArrayList<T>(); for (Object entity: world.entityList) { @@ -544,9 +550,31 @@ public class CraftWorld implements World { Class<?> bukkitClass = bukkitEntity.getClass(); + if (clazz.isAssignableFrom(bukkitClass)) { + list.add((T) bukkitEntity); + } + } + } + + return list; + } + + public Collection<Entity> getEntitiesByClasses(Class<?>... classes) { + Collection<Entity> list = new ArrayList<Entity>(); + + 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); + list.add(bukkitEntity); break; } } |