mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-27 21:19:00 +01:00
[Bleeding] Implemented World.getEntitiesByClass(Class<T>... classes)
This commit is contained in:
parent
29096577b6
commit
f7585e552d
@ -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 <T extends Entity> Collection<T> getEntitiesByClass(Class<T>... classes) {
|
||||
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();
|
||||
|
||||
for (Class<?> clazz : classes) {
|
||||
if (clazz.isAssignableFrom(bukkitClass)) {
|
||||
list.add((T) bukkitEntity);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<Player> getPlayers() {
|
||||
List<Player> list = new ArrayList<Player>();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user