/** * Creates a new explosion * * @param source The entity causing this explosion * @param location The location this explosion is occuring at. Must contain a GlowWorld * @param power The power of the explosion * @param incendiary Whether or not blocks should be set on fire * @param breakBlocks Whether blocks should break through this explosion */ public Explosion( Entity source, Location location, float power, boolean incendiary, boolean breakBlocks) { if (!(location.getWorld() instanceof GlowWorld)) { throw new IllegalArgumentException("Supplied location does not have a valid GlowWorld"); } this.source = source; this.location = location.clone(); this.power = power; this.incendiary = incendiary; this.breakBlocks = breakBlocks; this.world = (GlowWorld) location.getWorld(); }
public void setProperty(final String path, final Location loc) { set((path == null ? "" : path + ".") + "world", loc.getWorld().getName()); set((path == null ? "" : path + ".") + "x", loc.getX()); set((path == null ? "" : path + ".") + "y", loc.getY()); set((path == null ? "" : path + ".") + "z", loc.getZ()); set((path == null ? "" : path + ".") + "yaw", loc.getYaw()); set((path == null ? "" : path + ".") + "pitch", loc.getPitch()); }
/** * Checks if the location is near a block in the list on the same layer. * * @param location the location * @param blocks the collection of blocks to search * @param radius the radius to search * @return boolean */ public static boolean isLocationNearBlock( Location location, Collection<Integer> blocks, int radius) { World world = location.getWorld(); int x = (int) location.getX(), y = (int) location.getY(), z = (int) location.getZ(); for (int ox = radius; ox > -radius; ox--) for (int oz = radius; oz > -radius; oz--) if (blocks.contains(world.getBlockAt(x + ox, y, z + oz).getTypeId())) return false; return true; }
public Location getSurfaceAt(Location origin) { Chunk chunky = origin.getChunk(); int x = origin.getBlockX(), z = origin.getBlockZ(), surface = 0, envid = origin.getWorld().getEnvironment().getId(); Set dimmap = Sets.newHashSet(envid == 0 ? new int[] {1, 2, 3, 7, 15, 16} : envid == -1 ? 87 : 121); for (int y = 0; y != 256; y++) if (dimmap.contains(chunky.getBlock(x, y, z).getTypeId())) surface = y; return chunky.getBlock(x, surface, z).getLocation(); }
public WorldEditorException(final String msg, final Location loc) { super( msg + " at " + loc.getWorld().getName() + ":" + loc.getBlockX() + ":" + loc.getBlockY() + ":" + loc.getBlockZ()); this.loc = loc; }
/** * Gets player within range. * * @param location the centre of the range * @param radius the radius of the range * @return a set of Bukkit player objects */ public static Set<Player> getNearbyPlayers(Location location, double radius) { Set<Player> playerList = new HashSet<Player>(); World locWorld = location.getWorld(); radius *= radius; for (Player p : Bukkit.getServer().getOnlinePlayers()) { if (p.getWorld().equals(locWorld)) { if (p.getLocation().distanceSquared(location) <= radius) { playerList.add(p); } } } return playerList; }
/* * getMSG (String id, [char color1, char color2], Object param1, Object param2, Object param3... ) */ public String getMSG(Object... s) { String str = "&4Unknown message"; String color1 = "&" + this.c1; String color2 = "&" + this.c2; if (s.length > 0) { String id = s[0].toString(); str = "&4Unknown message (" + id + ")"; if (msg.containsKey(id)) { int px = 1; if ((s.length > 1) && (s[1] instanceof Character)) { px = 2; color1 = "&" + s[1]; if ((s.length > 2) && (s[2] instanceof Character)) { px = 3; color2 = "&" + s[2]; } } str = color1 + msg.get(id); if (px < s.length) for (int i = px; i < s.length; i++) { String f = s[i].toString(); if (s[i] instanceof Location) { Location loc = (Location) s[i]; f = loc.getWorld().getName() + "[" + loc.getBlockX() + ", " + loc.getBlockY() + ", " + loc.getBlockZ() + "]"; } str = str.replace("%" + Integer.toString(i - px + 1) + "%", color2 + f + color1); } } else if (this.savelng) { addMSG(id, str); SaveMSG(); } } return ChatColor.translateAlternateColorCodes('&', str); }
public static Location getSurface(Location location, int tolerance) { // TODO Make better return location.getWorld().getHighestBlockAt(location).getLocation(); }
/** * Checks if a location is exposed to sky, i.e. above ground. * * @param loc Bukkit location object * @return boolean */ public static boolean isLocationUnderSky(Location loc) { return loc.getWorld().getHighestBlockYAt(loc) <= loc.getBlockY(); }
/* * Проверяет, есть ли игроки в пределах заданного радиуса */ public boolean isPlayerAround(Location loc, int radius) { for (Player p : loc.getWorld().getPlayers()) { if (p.getLocation().distance(loc) <= radius) return true; } return false; }