Package com.sk89q.minecraft.util.commands

Examples of com.sk89q.minecraft.util.commands.CommandException


         */
        @Deprecated
        public static List<Player> checkPlayerMatch(List<Player> players) throws CommandException {
            // Check to see if there were any matches
            if (players.isEmpty()) {
                throw new CommandException("No players matched query.");
            }
            return players;
        }
View Full Code Here


         * @throws CommandException
         */
        public static <T extends Collection<? extends Player>> T checkPlayerMatch(T players) throws CommandException {
            // Check to see if there were any matches
            if (players.isEmpty()) {
                throw new CommandException("No players matched query.");
            }
            return players;
        }
View Full Code Here

         * @return
         * @throws CommandException
         */
        public static Player checkSinglePlayerMatch(List<Player> players) throws CommandException {
            if (players.size() > 1) {
                throw new CommandException("More than one player found! Use @<name> for exact matching.");
            }
            return players.get(0);
        }
View Full Code Here

                        try {
                            mode = GameMode.getByValue(Integer.parseInt(modeString));
                        } catch (NumberFormatException ignored) {}
                    }
                    if (mode == null) {
                        throw new CommandException("Unrecognized gamemode: " + modeString + ".");
                    }
                }
            }

            if (player == null || mode == null) {
                throw new CommandException("Something went wrong, please try again.");
            }

            String message;
            if (change) {
                if (player.getGameMode() == mode) {
View Full Code Here

                        if (world.getEnvironment() == World.Environment.NORMAL) {
                            return world;
                        }
                    }

                    throw new CommandException("No normal world found.");

                    // #nether for the first nether world
                } else if (filter.equalsIgnoreCase("#nether")) {
                    for (World world : worlds) {
                        if (world.getEnvironment() == World.Environment.NETHER) {
                            return world;
                        }
                    }

                    throw new CommandException("No nether world found.");

                    // #theend for the first end world
                } else if (filter.equalsIgnoreCase("#theend") || filter.equalsIgnoreCase("#end")) {
                    for (World world : worlds) {
                        if (world.getEnvironment() == World.Environment.THE_END) {
                            return world;
                        }
                    }

                    throw new CommandException("No end world found.");
                    // Handle getting a world from a player
                } else if (filter.matches("^#player$")) {
                    String parts[] = filter.split(":", 2);

                    // They didn't specify an argument for the player!
                    if (parts.length == 1) {
                        throw new CommandException("Argument expected for #player.");
                    }

                    return PlayerParser.matchPlayers(sender, parts[1]).iterator().next().getWorld();
                } else {
                    throw new CommandException("Invalid identifier '" + filter + "'.");
                }
            }

            for (World world : worlds) {
                if (world.getName().equals(filter)) {
                    return world;
                }
            }

            throw new CommandException("No world by that exact name found.");
        }
View Full Code Here

     */
    public static Player checkPlayer(CommandSender sender) throws CommandException {
        if (sender instanceof Player) {
            return (Player) sender;
        } else {
            throw new CommandException("A player context is required. (Specify a world or player if the command supports it.)");
        }
    }
View Full Code Here

                try {
                    x = Double.parseDouble(parts[0]);
                    y = Double.parseDouble(parts[1]);
                    z = Double.parseDouble(parts[2]);
                } catch (NumberFormatException e) {
                    throw new CommandException("Coordinates expected numbers!");
                }

                if (args.length > 1) {
                    return Lists.newArrayList(new Location(matchWorld(source, args[1]), x, y, z));
                } else {
                    Player player = checkPlayer(source);
                    return Lists.newArrayList(new Location(player.getWorld(), x, y, z));
                }

                // Handle special hash tag groups
            } else if (filter.charAt(0) == '#') {
                String[] args = filter.split(":");

                // Handle #world, which matches player of the same world as the
                // calling source
                if (args[0].equalsIgnoreCase("#spawn")) {
                    CommandBook.inst().checkPermission(source, "commandbook.spawn");
                    if (args.length > 1) {
                        return Lists.newArrayList(matchWorld(source, args[1]).getSpawnLocation());
                    } else {
                        Player sourcePlayer = checkPlayer(source);
                        return Lists.newArrayList(sourcePlayer.getLocation().getWorld().getSpawnLocation());
                    }

                    // Handle #target, which matches the player's target position
                } else if (args[0].equalsIgnoreCase("#target")) {
                    CommandBook.inst().checkPermission(source, "commandbook.locations.target");
                    Player player = checkPlayer(source);
                    Location playerLoc = player.getLocation();
                    Block targetBlock = player.getTargetBlock(null, 100);

                    if (targetBlock == null) {
                        throw new CommandException("Failed to find a block in your target!");
                    } else {
                        Location loc = targetBlock.getLocation();
                        playerLoc.setX(loc.getX());
                        playerLoc.setY(loc.getY());
                        playerLoc.setZ(loc.getZ());
                        return Lists.newArrayList(LocationUtil.findFreePosition(playerLoc));
                    }
                    // Handle #home and #warp, which matches a player's home or a warp point
                } else if (args[0].equalsIgnoreCase("#home")
                        || args[0].equalsIgnoreCase("#warp")) {
                    String type = args[0].substring(1);
                    CommandBook.inst().checkPermission(source, "commandbook.locations." + type);
                    LocationsComponent component = type.equalsIgnoreCase("warp")
                            ? CommandBook.inst().getComponentManager().getComponent(WarpsComponent.class)
                            : CommandBook.inst().getComponentManager().getComponent(HomesComponent.class);
                    if (component == null)  {
                        throw new CommandException("This type of location is not enabled!");
                    }
                    RootLocationManager<NamedLocation> manager = component.getManager();
                    if (args.length == 1) {
                        if (type.equalsIgnoreCase("warp")) {
                            throw new CommandException("Please specify a warp name.");
                        }
                        // source player home
                        Player ply = checkPlayer(source);
                        NamedLocation loc = manager.get(ply.getWorld(), ply.getName());
                        if (loc == null) {
                            throw new CommandException("You have not set your home yet.");
                        }
                        return Lists.newArrayList(loc.getLocation());
                    } else if (args.length == 2) {
                        if (source instanceof Player) {
                            Player player = (Player) source;
                            NamedLocation loc = manager.get(player.getWorld(), args[1]);
                            if (loc != null && !(loc.getCreatorName().equalsIgnoreCase(player.getName()))) {
                                CommandBook.inst().checkPermission(source, "commandbook.locations." + type + ".other");
                            }
                        }
                        return Lists.newArrayList(LocationUtil.getManagedLocation(manager, checkPlayer(source).getWorld(), args[1]));
                    } else if (args.length == 3) {
                        if (source instanceof Player) {
                            Player player = (Player) source;
                            NamedLocation loc = manager.get(matchWorld(source, args[2]), args[1]);
                            if (loc != null && !(loc.getCreatorName().equalsIgnoreCase(player.getName()))) {
                                CommandBook.inst().checkPermission(source, "commandbook.locations." + type + ".other");
                            }
                        }
                        return Lists.newArrayList(LocationUtil.getManagedLocation(manager, matchWorld(source, args[2]), args[1]));
                    }
                    // Handle #me, which is for when a location argument is required
                } else if (args[0].equalsIgnoreCase("#me")) {
                    return Lists.newArrayList(checkPlayer(source).getLocation());
                } else {
                    throw new CommandException("Invalid group '" + filter + "'.");
                }
            }

            List<Player> players;
View Full Code Here

       
        if (partialMatch != null) {
            return partialMatch;
        }

        throw new CommandException("Unknown mob specified! You can "
                + "choose from the list of: "
                + getCreatureNameList(requireSpawnable));
    }
View Full Code Here

        flags = "cp:", min = 0, max = 1)
        @CommandPermissions({"commandbook.help", "commandbook.help.command", "commandbook.help.topic"})
        public void help(CommandContext args, CommandSender sender) throws CommandException {
            if (args.hasFlag('c')) { // Looking up command help
                if (!config.commandHelp) {
                    throw new CommandException("Help for commands is not enabled!");
                }

                if (args.argsLength() == 0) {
                    Collection<org.bukkit.command.Command> serverCommands = getServerCommands();
                    for (Iterator<org.bukkit.command.Command> i = serverCommands.iterator(); i.hasNext();) {
                        final String permission = i.next().getPermission();
                        if (!(permission == null || permission.length() == 0 || CommandBook.inst().hasPermission(sender, permission))) {
                            i.remove();
                        }
                    }
                    new PaginatedResult<org.bukkit.command.Command>("Usage - Description") {
                        @Override
                        public String format(org.bukkit.command.Command entry) {
                            return entry.getUsage() + " - "
                                    + entry.getDescription();
                        }
                    }.display(sender, serverCommands, args.getFlagInteger('p', 1));
                } else {
                    org.bukkit.command.Command cmd = getCommand(args.getString(0));
                    if (cmd == null) {
                        throw new CommandException("Unknown command '" + args.getString(0) + "'; no help available");
                    } else {
                        CommandBook.inst().checkPermission(sender, "commandbook.help.command." + cmd.getName());
                        printCommandHelp(sender, cmd);
                    }
                }
View Full Code Here

    public void info(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() + ".");
        }

        // Resolve the world name
        String worldN = loc.getWorldName();
        if (worldN == null) {
View Full Code Here

TOP

Related Classes of com.sk89q.minecraft.util.commands.CommandException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.