Package com.sk89q.minecraft.util.commands

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


        throw new CommandException("File selection aborted.");
    }

    @ExceptionMatch
    public void convert(WorldEditException e) throws CommandException {
        throw new CommandException(e.getMessage(), e);
    }
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

     *
     * @throws CommandException
     */
    protected static Iterable<? extends Player> checkPlayerMatch(Collection<? extends 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 no matches found
     */
    public static Iterable<? extends Player> matchPlayers(CommandSender source, String filter) throws CommandException {

        if (CraftBookPlugin.server().getOnlinePlayers().size() == 0)
            throw new CommandException("No players matched query.");

        if (filter.equals("*")) return checkPlayerMatch(CraftBookPlugin.server().getOnlinePlayers());

        // Handle special hash tag groups
        if (filter.charAt(0) == '#') // Handle #world, which matches player of the same world as the
            // calling source
            if (filter.equalsIgnoreCase("#world")) {
                List<Player> players = new ArrayList<Player>();
                Player sourcePlayer = checkPlayer(source);
                World sourceWorld = sourcePlayer.getWorld();

                for (Player player : CraftBookPlugin.server().getOnlinePlayers()) {
                    if (player.getWorld().equals(sourceWorld)) {
                        players.add(player);
                    }
                }

                return checkPlayerMatch(players);

                // Handle #near, which is for nearby players.
            } else if (filter.equalsIgnoreCase("#near")) {
                List<Player> players = new ArrayList<Player>();
                Player sourcePlayer = checkPlayer(source);

                for (Player player : CraftBookPlugin.server().getOnlinePlayers()) {
                    if (player.getWorld().equals(sourcePlayer.getWorld()) && LocationUtil.getDistanceSquared(player.getLocation(), sourcePlayer.getLocation()) < 900)
                        players.add(player);
                }

                return checkPlayerMatch(players);

            } else throw new CommandException("Invalid group '" + filter + "'.");

        List<Player> players = matchPlayerNames(filter);

        return checkPlayerMatch(players);
    }
View Full Code Here

        for (Player player : players) {
            if (player.getName().equalsIgnoreCase(filter) || player.getDisplayName().equalsIgnoreCase(filter))
                return player;
        }

        throw new CommandException("No player found!");
    }
View Full Code Here

        // We don't want to match the wrong person, so fail if if multiple
        // players were found (we don't want to just pick off the first one,
        // as that may be the wrong player)
        if (players.hasNext())
            throw new CommandException("More than one player found! " + "Use @<name> for exact matching.");

        return match;
    }
View Full Code Here

            throws CommandException {

        if (sender instanceof Player) {
            return (Player) sender;
        } else {
            throw new CommandException("A player is expected.");
        }
    }
View Full Code Here

        String namespace = player.getCraftBookId();
        boolean personal = true;

        if (context.hasFlag('n')) {
            if (!player.hasPermission("craftbook.mech.area.save." + context.getFlag('n')))
                throw new CommandException("You do not have permission to use this namespace.");
            namespace = context.getFlag('n');
            personal = false;
        } else if (!player.hasPermission("craftbook.mech.area.save.self"))
            throw new CommandPermissionsException();

        if (Area.instance.shortenNames && namespace.length() > 14)
            namespace = namespace.substring(0, 14);

        if (!CopyManager.isValidNamespace(namespace))
            throw new CommandException("Invalid namespace. Needs to be between 1 and 14 letters long.");

        if (personal) {
            namespace = "~" + namespace;
        }

        id = context.getString(0);

        if (!CopyManager.isValidName(id))
            throw new CommandException("Invalid area name. Needs to be between 1 and 13 letters long.");

        try {
            WorldEditPlugin worldEdit = CraftBookPlugin.plugins.getWorldEdit();

            World world = ((Player) sender).getWorld();
            Selection sel = worldEdit.getSelection((Player) sender);
            if(sel == null) {
                sender.sendMessage(ChatColor.RED + "You have not made a selection!");
                return;
            }
            Vector min = BukkitUtil.toVector(sel.getMinimumPoint());
            Vector max = BukkitUtil.toVector(sel.getMaximumPoint());
            Vector size = max.subtract(min).add(1, 1, 1);

            // Check maximum size
            if (Area.instance.maxAreaSize != -1 && size.getBlockX() * size.getBlockY() * size.getBlockZ()
                    > Area.instance.maxAreaSize) {
                throw new CommandException("Area is larger than allowed " + Area.instance.maxAreaSize + " blocks.");
            }

            // Check to make sure that a user doesn't have too many toggle
            // areas (to prevent flooding the server with files)
            if (Area.instance.maxAreasPerUser >= 0 && !namespace.equals("global") && !player.hasPermission("craftbook.mech.area.bypass-limit")) {
                int count = copyManager.meetsQuota(world, namespace, id,
                        Area.instance.maxAreasPerUser);

                if (count > -1) {
                    throw new CommandException("You are limited to " + Area.instance.maxAreasPerUser + " toggle area(s). "
                            + "You have " + count + " areas.");
                }
            }

            // Copy
            CuboidCopy copy;

            if (Area.instance.useSchematics) {
                copy = new MCEditCuboidCopy(min, size, world);
            } else {
                copy = new FlatCuboidCopy(min, size, world);
            }

            copy.copy();

            plugin.getServer().getLogger().info(player.getName() + " saving toggle area with folder '" + namespace +
                    "' and ID '" + id + "'.");

            // Save
            try {
                CopyManager.getInstance().save(world, namespace, id.toLowerCase(Locale.ENGLISH), copy);
                player.print("Area saved as '" + id + "' under the '" + namespace + "' namespace.");
            } catch (IOException e) {
                player.printError("Could not save area: " + e.getMessage());
            } catch (DataException e) {
                player.print(e.getMessage());
            }
        } catch (NoClassDefFoundError e) {
            throw new CommandException("WorldEdit.jar does not exist in plugins/, or is outdated. (Or you are using an outdated version of CraftBook)");
        }
    }
View Full Code Here

        String namespace = "~" + player.getCraftBookId();

        // get the namespace from the flag (if set)
        if (context.hasFlag('n')) {
            if(!player.hasPermission("craftbook.mech.area.list." + context.getFlag('n')))
                throw new CommandException("You do not have permission to use this namespace.");
            namespace = context.getFlag('n');
        } else if (context.hasFlag('a') && player.hasPermission("craftbook.mech.area.list.all")) {
            namespace = "";
        } else if (!player.hasPermission("craftbook.mech.area.list.self")) throw new CommandPermissionsException();

        if (Area.instance.shortenNames && namespace.length() > 15)
            namespace = namespace.substring(0, 15);

        int page = 1;
        try {
            page = context.getInteger(0);
        } catch (Exception ignored) {
            // use default page: 1
        }

        // get the areas for the defined namespace
        File areas = new File(CraftBookPlugin.inst().getDataFolder(), "areas");

        if (!areas.exists()) throw new CommandException("There are no saved areas.");

        File folder = null;
        if (!namespace.isEmpty()) {
            folder = new File(areas, namespace);
        }

        if (folder != null && !folder.exists())
            throw new CommandException("The namespace '" + namespace + "' does not exist.");

        List<String> areaList = new ArrayList<String>();

        FilenameFilter fnf = new FilenameFilter() {
View Full Code Here

        } else if (sender instanceof Player) {
            world = ((Player) sender).getWorld();
        }

        if (world == null) {
            throw new CommandException("You must be a player or specify a valid world to use this command.");
        }

        int[] xyz = new int[3];
        String[] loc = context.getString(0).split(",");

        if (loc.length != 3) {
            throw new CommandException("Invalid location specified.");
        }

        try {
            for (int i = 0; i < xyz.length; i++) {
                xyz[i] = Integer.parseInt(loc[i]);
            }
        } catch (NumberFormatException ex) {
            throw new CommandException("Invalid location specified.");
        }

        Block block = world.getBlockAt(xyz[0], xyz[1], xyz[2]);
        if (!SignUtil.isSign(block)) throw new CommandException("No sign found at the specified location.");

        if (!Area.toggleCold(BukkitUtil.toChangedSign(block))) {
            throw new CommandException("Failed to toggle an area at the specified location.");
        }
        // TODO Make a sender wrap for this
        if (!context.hasFlag('s')) sender.sendMessage(ChatColor.YELLOW + "Area toggled!");
    }
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.