public static Iterable<Player> detectTargets(CommandSender sender, CommandContext args, String perm) throws CommandException { List<Player> targets; // Detect targets based on the number of arguments provided if (args.argsLength() == 0) { targets = Lists.newArrayList(PlayerUtil.checkPlayer(sender)); } else { targets = InputUtil.PlayerParser.matchPlayers(sender, args.getString(0)); } InputUtil.PlayerParser.checkPlayerMatch(targets); // Check permissions! for (Player player : targets) { if (player.equals(sender)) { CommandBook.inst().checkPermission(sender, perm); } else { CommandBook.inst().checkPermission(sender, perm + ".other"); break; } } return targets; }
public void remove(String name, World world, CommandSender sender) throws CommandException { NamedLocation loc = getManager().get(world, name); if (loc == null) { throw new CommandException("No " + this.name.toLowerCase() + " by that name could be found in " + world.getName() + "."); } if (!(sender instanceof Player) || !((Player) sender).getUniqueId().equals(loc.getCreatorID())) { CommandBook.inst().checkPermission(sender, "commandbook." + this.name.toLowerCase() + ".remove.other"); } getManager().remove(world, name); sender.sendMessage(ChatColor.YELLOW + this.name + ": " + name.toUpperCase() + " removed."); }
@Command(aliases = {"compass"}, usage = "[player]", desc = "Show your current compass direction", flags = "", min = 0, max = 1) @CommandPermissions({"commandbook.whereami.compass"}) public void compass(CommandContext args, CommandSender sender) throws CommandException { Player player; if (args.argsLength() == 0) { player = PlayerUtil.checkPlayer(sender); } else { player = InputUtil.PlayerParser.matchSinglePlayer(sender, args.getString(0)); if (player != sender) { CommandBook.inst().checkPermission(sender, "commandbook.whereami.compass.other"); } } sender.sendMessage(ChatColor.YELLOW + String.format("Your direction: %s", getCardinalDirection(player))); }
@Command(aliases = {"put", "place"}, usage = "<target>", desc = "Put a player at where you are looking", min = 1, max = 1) @CommandPermissions({"commandbook.teleport.other"}) public void put(CommandContext args, CommandSender sender) throws CommandException { Iterable<Player> targets = InputUtil.PlayerParser.matchPlayers(sender, args.getString(0)); Location loc = InputUtil.LocationParser.matchLocation(sender, "#target"); for (Player target : targets) { // We have already checked the from and current locations, we must now check the to if the world does not match if (!loc.getWorld().equals(target.getWorld())) { CommandBook.inst().checkPermission(sender, target.getWorld(), "commandbook.teleport.other"); } } (new TeleportPlayerIterator(sender, loc)).iterate(targets); }
CommandBook.inst().checkPermission(sender, "commandbook.spawn.other"); break;
if (player != sender) { CommandBook.inst().checkPermission(sender, "commandbook.slay.other"); } else { CommandBook.inst().checkPermission(sender, "commandbook.slay");
@Command(aliases = {"biome"}, usage = "[player]", desc = "Get your current biome", flags = "", min = 0, max = 1) @CommandPermissions({"commandbook.biome"}) public void biome(CommandContext args, CommandSender sender) throws CommandException { Player player; if (args.argsLength() == 0) { player = PlayerUtil.checkPlayer(sender); } else { player = InputUtil.PlayerParser.matchSinglePlayer(sender, args.getString(0)); if (player != sender) { CommandBook.inst().checkPermission(sender, "commandbook.biome.other"); } } Location loc = player.getLocation(); String biomeName = loc.getWorld().getBiome(loc.getBlockX(), loc.getBlockZ()).name().toLowerCase().replace("_"," "); if (player.equals(sender)) { sender.sendMessage(ChatColor.YELLOW + "You are in the " + biomeName + " biome."); } else { sender.sendMessage(ChatColor.YELLOW + ChatUtil.toColoredName(player, ChatColor.YELLOW) + " is in the " + biomeName + " biome."); } } }
@Command(aliases = {"call", "tpa"}, usage = "<target>", desc = "Request a teleport", min = 1, max = 1) @CommandPermissions({"commandbook.call"}) public void requestTeleport(CommandContext args, CommandSender sender) throws CommandException { Player player = PlayerUtil.checkPlayer(sender); Player target = InputUtil.PlayerParser.matchSinglePlayer(sender, args.getString(0)); CommandBook.inst().checkPermission(sender, target.getWorld(), "commandbook.call"); sessions.getSession(TeleportSession.class, player).checkLastTeleportRequest(target); sessions.getSession(TeleportSession.class, target).addBringable(player); String senderMessage = ChatUtil.replaceColorMacros( ChatUtil.replaceMacros(sender, config.callMessageSender)) .replaceAll("%ctarget%", ChatUtil.toColoredName(target, null)) .replaceAll("%target%", ChatUtil.toName(target)); String targetMessage = ChatUtil.replaceColorMacros( ChatUtil.replaceMacros(sender, config.callMessageTarget)) .replaceAll("%ctarget%", ChatUtil.toColoredName(target, null)) .replaceAll("%target%", ChatUtil.toName(target)); sender.sendMessage(senderMessage); target.sendMessage(targetMessage); }
if (player != sender) { CommandBook.inst().checkPermission(sender, "commandbook.thor.other"); } else { CommandBook.inst().checkPermission(sender, "commandbook.thor");
if (player != sender) { CommandBook.inst().checkPermission(sender, "commandbook.thor.other"); } else { CommandBook.inst().checkPermission(sender, "commandbook.thor");
@Command(aliases = {"take"}, usage = "<target> <item[:data]> [amount]", desc = "Take an item", flags = "", min = 2, max = 3) @CommandPermissions({"commandbook.take"}) public void take(CommandContext args, CommandSender sender) throws CommandException { ItemStack item = null; int amt = config.defaultItemStackSize; Player target = null; // Two arguments: Player, item type if (args.argsLength() == 2) { target = InputUtil.PlayerParser.matchSinglePlayer(sender, args.getString(0)); item = matchItem(args.getString(1)); // Three arguments: Player, item type, and item amount } else if (args.argsLength() == 3) { target = InputUtil.PlayerParser.matchSinglePlayer(sender, args.getString(0)); item = matchItem(args.getString(1)); amt = args.getInteger(2); } if (target != sender) { // Check permissions! CommandBook.inst().checkPermission(sender, "commandbook.take.other"); } else { CommandBook.inst().checkPermission(sender, "commandbook.take"); } if (item == null) { throw new CommandException("Something went wrong parsing the item info!"); } takeItem(sender, item, amt, target); }
CommandBook.inst().checkPermission(sender, "commandbook.home.set.other"); CommandBook.inst().checkPermission(sender, "commandbook.home.set.other");
CommandBook.inst().checkPermission(sender, "commandbook.intro.other"); break;
CommandBook.inst().checkPermission(sender, "commandbook.give.other"); } else { CommandBook.inst().checkPermission(sender, "commandbook.give");
@Command(aliases = {"whereami", "getpos", "pos", "where"}, usage = "[player]", desc = "Show your current location", flags = "", min = 0, max = 1) @CommandPermissions({"commandbook.whereami"}) public void whereAmI(CommandContext args, CommandSender sender) throws CommandException { Player player; if (args.argsLength() == 0) { player = PlayerUtil.checkPlayer(sender); } else { player = InputUtil.PlayerParser.matchSinglePlayer(sender, args.getString(0)); if (player != sender) { CommandBook.inst().checkPermission(sender, "commandbook.whereami.other"); } } Location pos = player.getLocation(); sender.sendMessage(ChatColor.YELLOW + "Player: " + player.getName() + (player == sender ? "(That's you!)" : "")); sender.sendMessage(ChatColor.YELLOW + "World: " + player.getWorld().getName()); sender.sendMessage(ChatColor.YELLOW + String.format("Location: (%.4f, %.4f, %.4f)", pos.getX(), pos.getY(), pos.getZ())); sender.sendMessage(ChatColor.YELLOW + "Depth: " + (int) Math.floor(pos.getY())); if (CommandBook.inst().hasPermission(sender, "commandbook.whereami.compass")) { sender.sendMessage(ChatColor.YELLOW + String.format("Direction: %s", getCardinalDirection(player))); } }
CommandBook.inst().checkPermission(sender, "commandbook.give.other");
player = InputUtil.PlayerParser.matchSinglePlayer(sender, args.getString(0)); if (player != sender) { CommandBook.inst().checkPermission(sender, "commandbook.return.other");
player = PlayerUtil.checkPlayer(sender); CommandBook.inst().checkPermission(sender, "commandbook.speed.walk" + (player.equals(sender) ? "" : ".other")); final float walkSpeed = DEFAULT_WALK_SPEED * walkMultiplier; // Apply multiplier
player = PlayerUtil.checkPlayer(sender); CommandBook.inst().checkPermission(sender, "commandbook.speed.flight" + (player.equals(sender) ? "" : ".other")); final float flightSpeed = DEFAULT_FLIGHT_SPEED * flightMultiplier; // Apply multiplier
if (existing != null) { if (!existing.getCreatorName().equals(sender.getName())) { CommandBook.inst().checkPermission(sender, "commandbook.warp.set.override");