Example #1
0
 /**
  * @param types
  * @param type
  * @param worlds worlds or null for all
  * @return All entities of this type in the given worlds
  */
 @SuppressWarnings({"null", "unchecked"})
 public static final <E extends Entity> E[] getAll(
     final EntityData<?>[] types, final Class<E> type, @Nullable World[] worlds) {
   assert types.length > 0;
   if (type == Player.class) {
     if (worlds == null
         && types.length == 1
         && types[0] instanceof PlayerData
         && ((PlayerData) types[0]).op == 0) return (E[]) Bukkit.getOnlinePlayers();
     final List<Player> list = new ArrayList<Player>();
     for (final Player p : Bukkit.getOnlinePlayers()) {
       if (worlds != null && !CollectionUtils.contains(worlds, p.getWorld())) continue;
       for (final EntityData<?> t : types) {
         if (t.isInstance(p)) {
           list.add(p);
           break;
         }
       }
     }
     return (E[]) list.toArray(new Player[list.size()]);
   }
   final List<E> list = new ArrayList<E>();
   if (worlds == null) worlds = Bukkit.getWorlds().toArray(new World[0]);
   for (final World w : worlds) {
     for (final E e : w.getEntitiesByClass(type)) {
       for (final EntityData<?> t : types) {
         if (t.isInstance(e)) {
           list.add(e);
           break;
         }
       }
     }
   }
   return list.toArray((E[]) Array.newInstance(type, list.size()));
 }