mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-09 11:44:19 +01:00
Add getEntitesByClass(Class<T>), getEntitiesByClasses(Class<?>...), deprecate getEntitiesByClass(Class<T>...)
By: Mike Primm <mike@primmhome.com>
This commit is contained in:
parent
fa547512af
commit
00c54bbbb6
1 changed files with 29 additions and 1 deletions
|
@ -531,9 +531,37 @@ public class CraftWorld implements World {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
@Deprecated
|
||||||
public <T extends Entity> Collection<T> getEntitiesByClass(Class<T>... classes) {
|
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>();
|
Collection<T> list = new ArrayList<T>();
|
||||||
|
|
||||||
|
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<Entity> getEntitiesByClasses(Class<?>... classes) {
|
||||||
|
Collection<Entity> list = new ArrayList<Entity>();
|
||||||
|
|
||||||
for (Object entity: world.entityList) {
|
for (Object entity: world.entityList) {
|
||||||
if (entity instanceof net.minecraft.server.Entity) {
|
if (entity instanceof net.minecraft.server.Entity) {
|
||||||
Entity bukkitEntity = ((net.minecraft.server.Entity) entity).getBukkitEntity();
|
Entity bukkitEntity = ((net.minecraft.server.Entity) entity).getBukkitEntity();
|
||||||
|
@ -546,7 +574,7 @@ public class CraftWorld implements World {
|
||||||
|
|
||||||
for (Class<?> clazz : classes) {
|
for (Class<?> clazz : classes) {
|
||||||
if (clazz.isAssignableFrom(bukkitClass)) {
|
if (clazz.isAssignableFrom(bukkitClass)) {
|
||||||
list.add((T) bukkitEntity);
|
list.add(bukkitEntity);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue