private Location getSafeLocation(Location loc) { int blockY = loc.getBlockY(); World world = loc.getWorld(); if (blockY > world.getHighestBlockYAt(loc)) { blockY = world.getHighestBlockYAt(loc) + 1; Block current = world.getBlockAt(loc.getBlockX(), blockY, loc.getBlockZ()); if (current.isEmpty() && current.getRelative(BlockFace.UP).isEmpty()) { hadSpace = true; } else if (hadSpace) { if (current.getType().isSolid()) { found = true; blockY++; loc.setY(blockY); loc.setX(loc.getBlockX() + 0.5); loc.setZ(loc.getBlockZ() + 0.5); return loc; } else {
private void playOutExplosion(GlowPlayer player, Iterable<Block> blocks) { Collection<Record> records = new ArrayList<>(); for (Block block : blocks) { Location blockLocation = block.getLocation(); byte x = (byte) (blockLocation.getBlockX() - (int) this.location.getX()); byte y = (byte) (blockLocation.getBlockY() - (int) this.location.getY()); byte z = (byte) (blockLocation.getBlockZ() - (int) this.location.getZ()); records.add(new Record(x, y, z)); } Vector velocity = player.getVelocity(); ExplosionMessage message = new ExplosionMessage( (float) location.getX(), (float) location.getY(), (float) location.getZ(), power, (float) velocity.getX(), (float) velocity.getY(), (float) velocity.getZ(), records); player.getSession().send(message); }
/** * Find a a Location obove or below the specified Location, which is on ground. * * <p>The returned Location will be at the center of the block, X and Y wise. * * @param spawn The Location a safe spawn position should be found at. * @return The location to spawn the player at. */ private static Location findSafeSpawnLocation(Location spawn) { World world = spawn.getWorld(); int blockX = spawn.getBlockX(); int blockY = spawn.getBlockY(); int blockZ = spawn.getBlockZ(); int highestY = world.getHighestBlockYAt(blockX, blockZ); int y = blockY; boolean wasPreviousSafe = false; for (; y <= highestY; y++) { Material type = world.getBlockAt(blockX, y, blockZ).getType(); boolean safe = Material.AIR.equals(type); if (wasPreviousSafe && safe) { y--; break; } wasPreviousSafe = safe; } return new Location(world, blockX + 0.5, y, blockZ + 0.5); }
Location targetLocation = new Location("");//provider name is unecessary targetLocation.setLatitude(0.0d);//your coords of course targetLocation.setLongitude(0.0d); float distanceInMeters = targetLocation.distanceTo(myLocation);
Location location = new Location(""); location.setLatitude(lat); location.setLongitude(lon);
/** * Constructs the BlockIterator. * * @param loc The location for the start of the ray trace * @param yOffset The trace begins vertically offset from the start vector * by this value */ public BlockIterator(Location loc, double yOffset) { this(loc.getWorld(), loc.toVector(), loc.getDirection(), yOffset, 0); }
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true) public void onLeavesDecay(LeavesDecayEvent event) { Location loc = event.getBlock().getLocation(); String wn = getWorld(loc.getWorld()).getName(); sscache.invalidateSnapshot(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); if(onleaves) { mapManager.touch(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), "leavesdecay"); } } };
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true) public void onBlockBreak(BlockBreakEvent evt) { Block b = evt.getBlock(); if(b == null) return; /* Work around for stupid mods.... */ Location l = b.getLocation(); core.listenerManager.processBlockEvent(EventType.BLOCK_BREAK, b.getType().getId(), getWorld(l.getWorld()).getName(), l.getBlockX(), l.getBlockY(), l.getBlockZ()); } }, DynmapPlugin.this);
@Override protected ItemStack dispenseStack(GlowBlock block, ItemStack stack) { BlockFace facing = BlockDispenser.getFacing(block); Location targetLocation = block.getLocation().clone() .add(facing.getModX(), facing.getModY(), facing.getModZ()); for (Entity entity : targetLocation.getWorld().getNearbyEntities(targetLocation, 3, 3, 3)) { switch (entity.getType()) { case PLAYER: targetLocationTest1 = (player.getLocation().getBlockX() == targetLocation.getX() && player.getLocation().getBlockY() == targetLocation.getY() && player.getLocation().getBlockZ() == targetLocation.getZ()); targetLocationTest2 = (player.getEyeLocation().getBlockX() == targetLocation.getX() && player.getEyeLocation().getBlockY() == targetLocation.getY() && player.getEyeLocation().getBlockZ() == targetLocation.getZ()); if ((targetLocationTest1 || targetLocationTest2)) { return ((GlowInventory) ((Player) player).getInventory()) .tryToFillSlots(stack, 36, 40);
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true) public void onPlayerMove(PlayerMoveEvent event) { Location loc = event.getPlayer().getLocation(); mapManager.touch(getWorld(loc.getWorld()).getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), "playermove"); } };
final String playerArg = args[1]; final Player player = Bukkit.getPlayerExact(playerArg); if (player == null) { sender.sendMessage(ChatColor.RED + "Can't find player " + playerArg); final Location location = player.getLocation(); double x = Math.floor(location.getX()); double y = Math.floor(location.getY() + 0.5D); double z = Math.floor(location.getZ()); double volume = 1.0D; double pitch = 1.0D; final Location soundLocation = new Location(player.getWorld(), x, y, z); if (location.distanceSquared(soundLocation) > fixedVolume * fixedVolume) { if (minimumVolume <= 0.0D) { sender.sendMessage(ChatColor.RED + playerArg + " is too far away to hear the sound"); final double deltaX = x - location.getX(); final double deltaY = y - location.getY(); final double deltaZ = z - location.getZ(); final double delta = Math.sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ) / 2.0D; location.add(deltaX / delta, deltaY / delta, deltaZ / delta);
/** * @param event */ @EventHandler public void onPlayerKick(PlayerKickEvent event) { if (plugin.getSettingsManager().isBlacklistedWorld(event.getPlayer().getLocation().getWorld().getName())) { return; } plugin.getClanManager().updateLastSeen(event.getPlayer()); } }
player = Bukkit.getPlayerExact(args[0]); Player target = Bukkit.getPlayerExact(args[args.length - 1]); if (target == null) { sender.sendMessage("Can't find player " + args[args.length - 1] + ". No tp."); return true; player.teleport(target, TeleportCause.COMMAND); Command.broadcastCommandMessage(sender, "Teleported " + player.getDisplayName() + " to " + target.getDisplayName()); } else if (player.getWorld() != null) { Location playerLocation = player.getLocation(); double x = getCoordinate(sender, playerLocation.getX(), args[args.length - 3]); double y = getCoordinate(sender, playerLocation.getY(), args[args.length - 2], 0, 0); double z = getCoordinate(sender, playerLocation.getZ(), args[args.length - 1]); playerLocation.setX(x); playerLocation.setY(y); playerLocation.setZ(z); player.teleport(playerLocation, TeleportCause.COMMAND);
@SuppressWarnings("deprecation") @EventHandler public void onPlayerMove(PlayerMoveEvent event) { Block block, control; if (event.getTo().getY() > event.getFrom().getY()) { block = event.getPlayer().getWorld().getBlockAt(new Location(event.getPlayer().getWorld(), event.getTo().getX(), event.getTo().getY() + 2, event.getTo().getZ())); control = event.getPlayer().getWorld().getBlockAt(new Location(event.getPlayer().getWorld(), event.getTo().getX(), event.getTo().getY() - 2, event.getTo().getZ())); if (!(block.getTypeId() != 0 || control.getTypeId() == 0)) { EvtJump custom = new EvtJump(event.getPlayer()); Bukkit.getServer().getPluginManager().callEvent(custom); if (custom.isCancelled()) { event.setCancelled(true); } } } }
: ((BlockCommandSender) sender).getBlock().getLocation(); final Entity[] entities = new CommandTarget(sender, args[0]).getMatched(location); targets = new ArrayList<>(); final Player player = Bukkit.getPlayerExact(playerPattern); } else { currentLocation = sender instanceof Entity ? ((Entity) sender).getLocation() : ((BlockCommandSender) sender).getBlock().getLocation(); currentLocation = new Location(world, 0, 0, 0); if (spawnLocation.getY() < 0) { sender.sendMessage(ChatColor.RED + "The y coordinate (" + spawnLocation.getY() + ") is too small, it must be at least 0."); return false; } else if (spawnLocation.getBlockY() > world.getMaxHeight()) { sender.sendMessage(ChatColor.RED + "'" + spawnLocation.getY() + "' is too high for the current world. Max value is '" + world.getMaxHeight() + "'."); return false; target.setBedSpawnLocation(spawnLocation, true); sender.sendMessage("Set " + target.getName() + "'s spawn point to " + spawnLocation.getBlockX() + ", " + spawnLocation.getBlockY() + ", " + spawnLocation.getBlockZ() + ".");
if (sender instanceof Player) { player = (Player) sender; world = player.getWorld(); } else { world = Bukkit.getWorlds().get(0); Location location = player.getLocation(); x = location.getBlockX(); y = location.getBlockY(); z = location.getBlockZ(); } else if (args.length == 3) { try { x = getInteger(sender, args[0], MIN_COORD, MAX_COORD, true); y = getInteger(sender, args[1], 0, world.getMaxHeight(), true); z = getInteger(sender, args[2], MIN_COORD, MAX_COORD, true); } catch (NumberFormatException ex) { world.setSpawnLocation(x, y, z); Command.broadcastCommandMessage(sender, "Set world " + world.getName() + "'s spawnpoint to (" + x + ", " + y + ", " + z + ")"); return true;
player = Bukkit.getPlayerExact(args[0]); if (player == null) { sender.sendMessage("Can't find player " + args[0]); World world = player.getWorld(); try { x = getInteger(sender, args[pos++], MIN_COORD, MAX_COORD, true); y = getInteger(sender, args[pos++], 0, world.getMaxHeight()); z = getInteger(sender, args[pos], MIN_COORD, MAX_COORD, true); } catch(NumberFormatException ex) { player.setBedSpawnLocation(new Location(world, x, y, z), true); Command.broadcastCommandMessage(sender, "Set " + player.getDisplayName() + "'s spawnpoint to " + x + ", " + y + ", " + z); Location location = player.getLocation(); player.setBedSpawnLocation(location, true); Command.broadcastCommandMessage(sender, "Set " + player.getDisplayName() + "'s spawnpoint to " + location.getX() + ", " + location.getY() + ", " + location.getZ()); } else { sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
targets = new CommandTarget(sender, args[0]).getMatched(location); } else { Player targetPlayer = Bukkit.getPlayerExact(args[0]); if (targetPlayer != null) { location = targetPlayer.getLocation(); targetLocation = CommandUtils.getRotation(target.getLocation(), yaw, pitch); } else { targetLocation.setYaw(target.getLocation().getYaw()); targetLocation.setPitch(target.getLocation().getPitch()); "Teleported " + target.getName() + " to " + targetLocation.getX() + " " + targetLocation.getY() + " " + targetLocation.getZ());