@Override public void setSpectatorTarget(Entity entity) { teleport(entity.getLocation(), PlayerTeleportEvent.TeleportCause.SPECTATE); spectating = entity; }
@Override public int compare(Entity e1, Entity e2) { int r = ((Double) (e1.getLocation().distanceSquared(source))) .compareTo(e2.getLocation().distanceSquared(source)); if (reversed) { r = -r; } return r; } }
@Override public boolean teleport(Entity destination) { return teleport(destination.getLocation()); }
@Override public boolean teleport(Entity destination, TeleportCause cause) { return teleport(destination.getLocation(), cause); }
@Override public Location getLocation() { org.bukkit.entity.Entity entity = entityRef.get(); if (entity != null) { return BukkitAdapter.adapt(entity.getLocation()); } else { return new Location(NullWorld.getInstance()); } }
private double distanceTo(Entity entity) { return RayUtil.getRayBetween(location, entity.getLocation()).length(); }
private double distanceToSquared(Entity entity) { return RayUtil.getRayBetween(location, entity.getLocation()).lengthSquared(); }
@Override public List<com.sk89q.worldedit.entity.Entity> getEntities(Region region) { World world = getWorld(); List<Entity> ents = world.getEntities(); List<com.sk89q.worldedit.entity.Entity> entities = new ArrayList<>(); for (Entity ent : ents) { if (region.contains(BukkitAdapter.asBlockVector(ent.getLocation()))) { entities.add(BukkitAdapter.adapt(ent)); } } return entities; }
private GlowItem getFirstDroppedItem(Location location) { for (Entity entity : location.getChunk().getEntities()) { if (location.getBlockX() != entity.getLocation().getBlockX() || location.getBlockY() != entity.getLocation().getBlockY() || location.getBlockZ() != entity.getLocation().getBlockZ()) { continue; } if (entity.getType() != EntityType.DROPPED_ITEM) { continue; } return ((GlowItem) entity); } return null; }
/** * Checks whether the entity is within the specified distance from the block. * * @param entity the entity * @param block the block * @param x maximum distance on x axis * @param y maximum distance on y axis * @param z maximum distance on z axis * @return Whether the entity is within distance */ private boolean isWithinDistance(Entity entity, Block block, int x, int y, int z) { Location loc = entity.getLocation(); return Math.abs(loc.getX() - block.getX()) <= x && Math.abs(loc.getY() - block.getY()) <= y && Math.abs(loc.getZ() - block.getZ()) <= z; } }
@Override public void pulse() { super.pulse(); radius += radiusPerTick; waitTime--; duration--; if (duration <= 0 || radius <= 0) { remove(); } if (waitTime <= 0) { long currentTick = world.getFullTime(); for (Entity entity : world.getNearbyEntities(location, radius, radius, radius)) { if (entity instanceof LivingEntity && temporaryImmunities.getOrDefault(entity, Long.MIN_VALUE) <= currentTick && location.distanceSquared(entity.getLocation()) < radius * radius) { customEffects.values().forEach( effect -> EntityUtils.applyPotionEffectWithIntensity( effect, (LivingEntity) entity, 0.5, 0.25)); temporaryImmunities.put((LivingEntity) entity, currentTick + reapplicationDelay); } } } }
/** * Gets the location that is "~ ~ ~" for a command sender. * * @param sender a command sender * @return the sender's location if the sender is a block or entity, or the default world's * coordinate origin otherwise. */ public static Location getLocation(CommandSender sender) { if (sender instanceof Entity) { return ((Entity) sender).getLocation(); } else if (sender instanceof BlockCommandSender) { return ((BlockCommandSender) sender).getBlock().getLocation(); } return new Location(getDefaultWorld(), 0, 0, 0); }
@Override public void start(GlowLivingEntity entity) { target = null; List<Entity> nearbyEntities = entity.getNearbyEntities(RANGE, RANGE / 2, RANGE); double nearestSquared = Double.MAX_VALUE; for (Entity nearbyEntity : nearbyEntities) { if (nearbyEntity.getType() != EntityType.PLAYER) { continue; } double dist = nearbyEntity.getLocation().distanceSquared(entity.getLocation()); if (dist < nearestSquared) { target = (GlowPlayer) nearbyEntity; nearestSquared = dist; } } }
@Override public void start(GlowLivingEntity entity) { target = null; List<Entity> nearbyEntities = entity.getNearbyEntities(RANGE, RANGE / 2, RANGE); double nearestSquared = Double.MAX_VALUE; for (Entity nearbyEntity : nearbyEntities) { if (nearbyEntity.getType() != EntityType.PLAYER) { continue; } double dist = nearbyEntity.getLocation().distanceSquared(entity.getLocation()); if (dist < nearestSquared) { target = (GlowPlayer) nearbyEntity; nearestSquared = dist; } } }
.filter(LivingEntity.class::isInstance) .forEach(entity -> { Location entityLoc = entity.getLocation(); double distFractionSquared = entityLoc.distanceSquared(location) / MAX_DISTANCE_SQUARED;
.filter(entity -> entity instanceof LivingEntity && !entity.isDead()) .forEach(entity -> { Vector pos = entity.getLocation().toVector(); int minY = getHighestBlockYAt(pos.getBlockX(), pos.getBlockZ()); if (pos.getBlockY() >= minY) {
String yaw = args[4]; String pitch = args[5]; targetLocation = CommandUtils.getRotation(target.getLocation(), yaw, pitch); } else { targetLocation.setYaw(target.getLocation().getYaw()); targetLocation.setPitch(target.getLocation().getPitch());
spawnLocation = sender instanceof Entity ? ((Entity) sender).getLocation() : ((BlockCommandSender) sender).getBlock().getLocation(); } else { return false; } else { senderLocation = sender instanceof Entity ? ((Entity) sender).getLocation() : ((BlockCommandSender) sender).getBlock().getLocation();
private void explode() { if (!EventFactory.getInstance().callEvent(new FireworkExplodeEvent(this)).isCancelled()) { this.playEffect(EntityEffect.FIREWORK_EXPLODE); int effectsSize = getFireworkMeta().getEffectsSize(); if (effectsSize > 0) { if (boostedEntity != null) { boostedEntity.damage((5 + effectsSize * 2), DamageCause.ENTITY_EXPLOSION); } List<Entity> nearbyEntities = this.getNearbyEntities(2.5, 2.5, 2.5); for (Entity nearbyEntity : nearbyEntities) { if (!(nearbyEntity instanceof LivingEntity)) { continue; } if (this.getLocation().distanceSquared(nearbyEntity.getLocation()) > 25) { continue; } // "The explosion of firework rockets deals 2.5 hearts of damage, per firework // star." ((LivingEntity) nearbyEntity) .damage((effectsSize * 5), DamageCause.ENTITY_EXPLOSION); } } } remove(); }
Location destination = getLocation(); Entity entity = (Entity) source; Location entityLocation = entity.getLocation();