private Collection<Entity> getNearbyEntities() { return location.getWorld().getNearbyEntities(location, power, power, power); }
/** * Get all LeashHitch Entities in the specified block. * * @param block the Block to search LeashHitch Entities in * @return a Stream of all found LeashHitch Entities */ private static Stream<LeashHitch> getExistingLeashHitches(Block block) { Location location = block.getLocation().add(0.5, 0.5, 0.5); Collection<Entity> nearbyEntities = block.getWorld() .getNearbyEntities(location, 0.49, 0.49, 0.49); return nearbyEntities.stream() .filter(e -> e instanceof LeashHitch) .map(e -> (LeashHitch) e); }
if ((newTarget.isEmpty() || type == null || type.canAbsorb(target, face, holding)) && (upper.isEmpty() || up == null || up.canAbsorb(target, face, holding)) && loc.getWorld().getNearbyEntities(loc.clone().add(0, 0.5, 0), 0.5, 0.5, 0.5).isEmpty() && loc.getWorld().getNearbyEntities(loc.clone().add(0, 1.5, 0), 0.5, 0.5, 0.5) .isEmpty()) { newTarget.setType(Material.AIR);
for (Entity entity : targetLocation.getWorld().getNearbyEntities(targetLocation, 3, 3, 3)) { switch (entity.getType()) { case PLAYER:
/** * Applies an action to all players within a given radius of a point * * @param center the point * @param radius the radius * @param consumer the action to apply */ public static void forEachInRange(Location center, double radius, Consumer<Player> consumer) { center.getWorld().getNearbyEntities(center, radius, radius, radius).stream() .filter(e -> e instanceof Player) .map(e -> ((Player) e)) .forEach(consumer); }
/** * Gets a stream of all players within a given radius of a point * * @param center the point * @param radius the radius * @return a stream of players */ public static Stream<Player> streamInRange(Location center, double radius) { return center.getWorld().getNearbyEntities(center, radius, radius, radius).stream() .filter(e -> e instanceof Player) .map(e -> ((Player) e)); }
/** * Gets a stream of all players within a given radius of a point * * @param center the point * @param radius the radius * @return a stream of players */ public static Stream<Player> streamInRange(Location center, double radius) { return center.getWorld().getNearbyEntities(center, radius, radius, radius).stream() .filter(e -> e instanceof Player) .map(e -> ((Player) e)); }
/** * Applies an action to all players within a given radius of a point * * @param center the point * @param radius the radius * @param consumer the action to apply */ public static void forEachInRange(Location center, double radius, Consumer<Player> consumer) { center.getWorld().getNearbyEntities(center, radius, radius, radius).stream() .filter(e -> e instanceof Player) .map(e -> ((Player) e)) .forEach(consumer); }
/** * Clear an area of mobs as per world rules. Radius is 5 blocks in every direction. * @param loc - location to clear */ public void clearArea(Location loc) { loc.getWorld().getNearbyEntities(loc, 5D, 5D, 5D).stream() .filter(en -> (en instanceof Monster)) .filter(en -> !plugin.getIWM().getRemoveMobsWhitelist(loc.getWorld()).contains(en.getType())) .forEach(Entity::remove); }
@Override public List<MCEntity> GetEntitiesAt(MCLocation location, double radius) { if(location == null) { return Collections.EMPTY_LIST; } if(radius <= 0) { radius = 1; } Location l = (Location) location.getHandle(); Collection<Entity> near = l.getWorld().getNearbyEntities(l, radius, radius, radius); List<MCEntity> entities = new ArrayList<>(); for(Entity e : near) { entities.add(BukkitGetCorrectEntity(e)); } return entities; }
public static List<Entity> getNearbyEntities(Power power, Location l, Player player, double radius, double dx, double dy, double dz) { List<Entity> entities = new ArrayList<>(); for (Entity e : l.getWorld().getNearbyEntities(l, dx, dy, dz)) { if (l.distance(e.getLocation()) <= radius) { entities.add(e); } } power.getItem().getPowers().stream().filter(pow -> pow instanceof PowerSelector).forEach( selector -> { if (power.getSelectors().contains(((PowerSelector) selector).id())) { ((PowerSelector) selector).inPlaceFilter(player, entities); } } ); return entities; }
/** * Supports Bukkit earlier than Spigot Bukkit-1.8.4 */ public static Collection<Entity> getNearbyEntities(Location location, double x, double y, double z) { World world = location.getWorld(); try { return world.getNearbyEntities(location, x, y, z); } catch (NoSuchMethodError ignored) { Entity entity = world.spawnEntity(location, EntityType.EXPERIENCE_ORB); Collection<Entity> result = entity.getNearbyEntities(x, y, z); entity.remove(); return result; } }
private Collection<Entity> getNearbyEntities(CommandSender sender, int radius) { Location center; if (sender instanceof Player) { center = ((Player) sender).getLocation(); } else { center = ((BlockCommandSender) sender).getBlock().getLocation().add(0.5, 0, 0.5); } return center.getWorld().getNearbyEntities(center, radius, radius, radius); }
public void addEffectToFieldEntities(Field field) { List<String> types = field.getSettings().getPotionTargets(); if (types.size() == 0) { return; } int longestRadius = field.getLongestSide() / 2; int height = field.getHeight(); Collection<Entity> nearbyEntities = field.getLocation().getWorld().getNearbyEntities(field.getLocation(), longestRadius, height, longestRadius); for (Entity entity : nearbyEntities) { if (entity instanceof LivingEntity) { addEffectToEntity(field, (LivingEntity) entity, types); } } }
public void removeEffectFromFieldEntities(Field field) { List<String> types = field.getSettings().getPotionTargets(); if (types.size() == 0) { return; } int longestRadius = field.getLongestSide() / 2; int height = field.getHeight(); Collection<Entity> nearbyEntities = field.getLocation().getWorld().getNearbyEntities(field.getLocation(), longestRadius, height, longestRadius); for (Entity entity : nearbyEntities) { if (entity instanceof LivingEntity) { removeEffectFromEntity(field, (LivingEntity) entity, types); } } }
@Override public void run() { for (Entity e : banner.getLocation().getWorld().getNearbyEntities(banner.getLocation(), radius, 255, radius)) { if (e instanceof Player) { Player player = (Player) e; FPlayer fplayer = FPlayers.getInstance().getByPlayer(player); if (fplayer.getFaction() == bannerFaction) { for (String effect : effects) { String[] components = effect.split(":"); player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(components[0]), 100, Integer.parseInt(components[1]))); } ParticleEffect.LAVA.display(1, 1, 1, 1, 10, banner.getLocation(), 16); ParticleEffect.FLAME.display(1, 1, 1, 1, 10, banner.getLocation(), 16); if (banner.getType() != bannerType) { banner.setType(bannerType); } } } } } }, 0L, 20L);
avoidanceList.clear(); double range = sentinel.avoidRange + 10; for (Entity entity : getLivingEntity().getWorld().getNearbyEntities(getLivingEntity().getLocation(), range, 16, range)) { if (!(entity instanceof LivingEntity)) { continue;
boolean wasLos = false; double range = rangesquared; for (Entity loopEnt : getLivingEntity().getWorld().getNearbyEntities(pos, range, range, range)) { if (!(loopEnt instanceof LivingEntity)) { continue;
private void tickNpcs() { for (NPC npc : this.npcRegistry) { if (!npc.isSpawned() || !npc.hasTrait(ClickableTrait.class)) continue; Npc helperNpc = npc.getTrait(ClickableTrait.class).npc; // ensure npcs stay in the same position Location loc = npc.getEntity().getLocation(); if (loc.getBlockX() != helperNpc.getInitialSpawn().getBlockX() || loc.getBlockZ() != helperNpc.getInitialSpawn().getBlockZ()) { npc.teleport(helperNpc.getInitialSpawn().clone(), PlayerTeleportEvent.TeleportCause.PLUGIN); } // don't let players stand near npcs for (Entity entity : npc.getStoredLocation().getWorld().getNearbyEntities(npc.getStoredLocation(), 1.0, 1.0, 1.0)) { if (!(entity instanceof Player) || this.npcRegistry.isNPC(entity)) continue; final Player p = (Player) entity; if (p.getGameMode() == GameMode.CREATIVE || p.getGameMode() == GameMode.SPECTATOR) { continue; } if (npc.getEntity().getLocation().distance(p.getLocation()) < 3.5) { p.setVelocity(p.getLocation().getDirection().multiply(-0.5).setY(0.4)); } } } }
private void tickNpcs() { for (NPC npc : this.npcRegistry) { if (!npc.isSpawned() || !npc.hasTrait(ClickableTrait.class)) continue; Npc helperNpc = npc.getTrait(ClickableTrait.class).npc; // ensure npcs stay in the same position Location loc = npc.getEntity().getLocation(); if (loc.getBlockX() != helperNpc.getInitialSpawn().getBlockX() || loc.getBlockZ() != helperNpc.getInitialSpawn().getBlockZ()) { npc.teleport(helperNpc.getInitialSpawn().clone(), PlayerTeleportEvent.TeleportCause.PLUGIN); } // don't let players stand near npcs for (Entity entity : npc.getStoredLocation().getWorld().getNearbyEntities(npc.getStoredLocation(), 1.0, 1.0, 1.0)) { if (!(entity instanceof Player) || this.npcRegistry.isNPC(entity)) continue; final Player p = (Player) entity; if (p.getGameMode() == GameMode.CREATIVE || p.getGameMode() == GameMode.SPECTATOR) { continue; } if (npc.getEntity().getLocation().distance(p.getLocation()) < 3.5) { p.setVelocity(p.getLocation().getDirection().multiply(-0.5).setY(0.4)); } } } }