@Command( command = "tp", aliases = {"teleport"}, arguments = {"target player[s]", "world name", "x", "y", "z"}, tabCompletions = { TabCompleteType.PLAYER, TabCompleteType.WORLD, TabCompleteType.NUMBER, TabCompleteType.NUMBER, TabCompleteType.NUMBER }, description = "teleports <player[s]> to the given coordinates in the given world", permissions = {"othercoords"}) public static boolean teleport( CommandSender sender, String targetPlayer, String worldName, float x, float y, float z) throws EssentialsCommandException { // make sure the world exists World targetWorld = Bukkit.getServer().getWorld(worldName); if (targetWorld == null) { throw new EssentialsCommandException("I couldn't find world '%s' to teleport to!", worldName); } // get a list of all target players ArrayList<Player> targetPlayers = PlayerSelector.selectPlayers(targetPlayer); // make sure we have at least one target player if (targetPlayers.size() == 0) { throw new EssentialsCommandException( "I couldn't find target player[s] '%s' to teleport!", targetPlayer); } // loop through all target players for (Iterator<Player> it = targetPlayers.iterator(); it.hasNext(); ) { // get the player Player target = it.next(); // make sure that player doesn't have teleporting disabled if (tpDisabled(target) && !PermissionsManager.playerHasPermission(sender, "teleport.toggle.override")) { ColourHandler.sendMessage( sender, "%s &cdoesn't have teleporting enabled!", target.getName()); continue; } // build their destination Location destination = new Location( targetWorld, x, y, z, target.getLocation().getYaw(), target.getLocation().getPitch()); // do it! target.teleport(destination); // alert everyone ColourHandler.sendMessage( target, "&6You have been teleported to (" + destination.getBlockX() + ", " + destination.getBlockY() + ", " + destination.getBlockZ() + ") in world: " + destination.getWorld().getName() + " by " + sender.getName()); if (!target.getName().equals(sender.getName())) { ColourHandler.sendMessage( sender, "&6" + target.getName() + " has been teleported to (" + destination.getBlockX() + ", " + destination.getBlockY() + ", " + destination.getBlockZ() + ") in world: " + destination.getWorld().getName()); } } return true; }
@Command( command = "tp", aliases = {"teleport"}, arguments = {"target player[s]", "destination player"}, tabCompletions = {TabCompleteType.PLAYER, TabCompleteType.PLAYER}, description = "teleports <target player[s]> to <destination player>", permissions = {"other"}) public static boolean teleport( CommandSender sender, String targetPlayer, String destinationPlayer) throws EssentialsCommandException { // try to find the destination player Player destination = Bukkit.getServer().getPlayer(destinationPlayer); if (destination == null) { throw new EssentialsCommandException( "&cI couldn't find player '%s' to teleport to!", destination); } // make sure that player doesn't have teleporting disabled if (tpDisabled(destination) && !PermissionsManager.playerHasPermission(sender, "teleport.toggle.override")) { throw new EssentialsCommandException("%s &chas disabled teleports!", destination.getName()); } // get a list of all target players ArrayList<Player> targetPlayers = PlayerSelector.selectPlayers(targetPlayer); // make sure we have at least one target player if (targetPlayers.size() == 0) { throw new EssentialsCommandException( "I couldn't find target player[s] '%s' to teleport!", targetPlayer); } // loop through all target players for (Iterator<Player> it = targetPlayers.iterator(); it.hasNext(); ) { // get the player Player target = it.next(); // make sure that player doesn't have teleporting disabled if (tpDisabled(target) && !PermissionsManager.playerHasPermission(sender, "teleport.toggle.override")) { ColourHandler.sendMessage( sender, "%s &cdoesn't have teleporting enabled!", target.getName()); continue; } // do it! target.teleport(destination); // alert everyone ColourHandler.sendMessage( target, "&6You have been teleported to " + destination.getName() + " by " + sender.getName()); if (!destination.getName().equals(sender.getName())) { ColourHandler.sendMessage( destination, "&6" + target.getName() + " has been teleported to you by " + sender.getName()); } if (!target.getName().equals(sender.getName())) { ColourHandler.sendMessage( sender, "&6" + target.getName() + " has been teleported to " + destination.getName()); } } return true; }