Refine search
/** * Gets whether there has been a position change between the two Locations. * * @param first The initial location. * @param second The final location. * @return A boolean. */ public static boolean hasMoved(Location first, Location second) { return first.getX() != second.getX() || first.getY() != second.getY() || first.getZ() != second.getZ(); }
/** * Creates a {@link WorldBorderMessage} containing information to initialize the world border on * the client-side. * * @return a new {@link WorldBorderMessage} for this world border. */ public WorldBorderMessage createMessage() { return new WorldBorderMessage( WorldBorderMessage.Action.INITIALIZE, center.getX(), center.getZ(), size, sizeLerpTarget, sizeLerpTime * 1000, 29999984, warningTime, warningDistance); }
/** * Write a Location to the "Pos" and "Rotation" children of a tag. * * <p>Does not save world information, use writeWorld instead. * * @param loc The location to write. * @param tag The tag to write to. */ public static void locationToListTags(Location loc, CompoundTag tag) { tag.putDoubleList("Pos", Arrays.asList(loc.getX(), loc.getY(), loc.getZ())); tag.putFloatList("Rotation", Arrays.asList(loc.getYaw(), loc.getPitch())); }
@Override public boolean isInside(Location location) { Location max = center.clone().add(size / 2, 0, size / 2); Location min = center.clone().subtract(size / 2, 0, size / 2); return location.getX() <= max.getX() && location.getZ() <= max.getZ() && location.getX() >= min.getX() && location.getZ() >= min.getZ(); }
/** * Checks if this entity is within the visible radius of a location. * * @param loc The location. * @return {@code true} if the entities can see each other, {@code false} if not. */ public boolean isWithinDistance(Location loc) { double dx = Math.abs(location.getX() - loc.getX()); double dz = Math.abs(location.getZ() - loc.getZ()); return loc.getWorld() == getWorld() && dx <= server.getViewDistance() * GlowChunk.WIDTH && dz <= server.getViewDistance() * GlowChunk.HEIGHT; }
/** * Creates the spawn messages given the shooter ID on the receiving end (which is different for * the shooter than for everyone else). * * @param shooterId the shooter's ID, according to the receiving client * @return the spawn messages */ private List<Message> createSpawnMessage(int shooterId) { List<Message> spawnMessage = super.createSpawnMessage(); double x = location.getX(); double y = location.getY(); double z = location.getZ(); int intPitch = Position.getIntPitch(location); int intHeadYaw = Position.getIntHeadYaw(location.getYaw()); spawnMessage.set(0, new SpawnObjectMessage(getEntityId(), getUniqueId(), SpawnObjectMessage.FISHING_HOOK, x, y, z, intPitch, intHeadYaw, shooterId, velocity)); return spawnMessage; }
/** * Starts an entity moving horizontally toward a location (may overshoot). * * @param entity the entity to move * @param direction the destination to move toward * @param speed the speed to move */ public static void moveTowards(GlowLivingEntity entity, Location direction, double speed) { Location location = entity.getLocation(); double deltaX = (direction.getX() - location.getX()); double deltaZ = (direction.getZ() - location.getZ()); entity.setSpeed(speed); entity.setMovement(new Vector(deltaX, 0, deltaZ)); } }
/** * Copy the contents of one Location to another. * * @param source The Location to read from. * @param dest The Location to modify. May be null. * @return The dest parameter, modified if not null. */ public static Location copyLocation(Location source, Location dest) { if (dest == null) { return null; } dest.setWorld(source.getWorld()); dest.setX(source.getX()); dest.setY(source.getY()); dest.setZ(source.getZ()); dest.setPitch(source.getPitch()); dest.setYaw(source.getYaw()); return dest; }
private double spread(World world, List<Player> list, Location[] locations, boolean teams) { double distance = 0.0D; int i = 0; Map<Team, Location> hashmap = Maps.newHashMap(); for (int j = 0; j < list.size(); ++j) { Player player = list.get(j); Location location; if (teams) { Team team = player.getScoreboard().getPlayerTeam(player); if (!hashmap.containsKey(team)) { hashmap.put(team, locations[i++]); } location = hashmap.get(team); } else { location = locations[i++]; } player.teleport(new Location(world, Math.floor(location.getX()) + 0.5D, world.getHighestBlockYAt((int) location.getX(), (int) location.getZ()), Math.floor(location.getZ()) + 0.5D)); double value = Double.MAX_VALUE; for (int k = 0; k < locations.length; ++k) { if (location != locations[k]) { double d = location.distanceSquared(locations[k]); value = Math.min(d, value); } } distance += value; } distance /= list.size(); return distance; }
/** * Create a WorldEdit BlockVector from a Bukkit location. * * @param location The Bukkit location * @return a WorldEdit vector */ public static BlockVector3 asBlockVector(org.bukkit.Location location) { checkNotNull(location); return BlockVector3.at(location.getX(), location.getY(), location.getZ()); }