Package com.sk89q.minecraft.util.commands

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


            DyeColor match = DyeColor.valueOf(filter.toUpperCase());
            if (match != null) {
                return match;
            }
        } catch (IllegalArgumentException ignored) {}
        throw new CommandException("Unknown dye color name of '" + filter + "'.");
    }
View Full Code Here


        @Command(aliases = {"reply", "r"}, usage = "<message...>", desc = "Reply to last user", min = 1, max = -1)
        @CommandPermissions({"commandbook.msg"})
        public void reply(CommandContext args, CommandSender sender) throws CommandException {
            String lastRecipient = sessions.getSession(UserSession.class, sender).getLastRecipient();
            if (lastRecipient == null) {
                throw new CommandException("You haven't messaged anyone.");
            }

            messagePlayer(sender, lastRecipient, args.getJoinedStrings(0));
        }
View Full Code Here

            Player player = InputUtil.PlayerParser.matchSinglePlayer(sender, args.getString(0));

            if (CommandBook.inst().hasPermission(player, "commandbook.mute.exempt")
                    && !(args.hasFlag('o')
                    && CommandBook.inst().hasPermission(sender, "commandbook.mute.exempt.override"))) {
                throw new CommandException("Player " + ChatUtil.toName(sender) + " is exempt from being muted!");
            }

            if (!sessions.getSession(AdministrativeSession.class, player).setMute(true)) {

                if (player != sender) {
                    player.sendMessage(ChatColor.YELLOW + "You've been muted by "
                            + ChatUtil.toColoredName(sender, ChatColor.YELLOW));
                }
                sender.sendMessage(ChatColor.YELLOW + "You've muted "
                        + ChatUtil.toColoredName(player, ChatColor.YELLOW));
            } else {
                throw new CommandException("Player " + ChatUtil.toName(player) + " is already muted!");
            }
    }
View Full Code Here

                        + ChatUtil.toColoredName(sender, ChatColor.YELLOW));
                }
                sender.sendMessage(ChatColor.YELLOW + "You've unmuted "
                        + ChatUtil.toColoredName(player, ChatColor.YELLOW));
            } else {
                throw new CommandException("Player " + ChatUtil.toName(player) + " was not muted!");
            }
        }
View Full Code Here

        component.checkAllowedItem(sender, item.getTypeId(), item.getDurability());

        // Check for invalid amounts
        if (amt == 0 || amt < -1) {
            throw new CommandException("Invalid item amount!");
        } else if (amt == -1) {
            // Check to see if the player can give infinite items
            CommandBook.inst().checkPermission(sender, "commandbook.give.infinite");
            infinite = true;
        } else if (overrideStackSize) {
            CommandBook.inst().checkPermission(sender, "commandbook.override.maxstacksize");
        } else if (amt > maxStackSize * 5) {
            // Check to see if the player can give stacks of this size
            if (!CommandBook.inst().hasPermission(sender, "commandbook.give.stacks.unlimited")) {
                throw new CommandException("More than 5 stacks is too excessive.");
            }
        } else if (amt > maxStackSize /* && amt < max * 5 */) {
            // Check to see if the player can give stacks
            CommandBook.inst().checkPermission(sender, "commandbook.give.stacks");
        }
View Full Code Here

                                Player target)
            throws CommandException {

        // Check for invalid amounts
        if (amt <= 0) {
            throw new CommandException("Invalid item amount!");
        }


        item.setAmount(amt);
        if (target.getInventory().contains(item.getTypeId())) {
View Full Code Here

        public static long matchDate(String filter) throws CommandException {
            if (filter == null) return 0L;
            if (filter.equalsIgnoreCase("now")) return System.currentTimeMillis();
            String[] groupings = filter.split("-");
            if (groupings.length == 0) throw new CommandException("Invalid date specified");
            Calendar cal = new GregorianCalendar();
            cal.setTimeInMillis(0);
            for (String str : groupings) {
                int type;
                switch (str.charAt(str.length() - 1)) {
                    case 'm':
                        type = Calendar.MINUTE;
                        break;
                    case 'h':
                        type = Calendar.HOUR;
                        break;
                    case 'd':
                        type = Calendar.DATE;
                        break;
                    case 'w':
                        type = Calendar.WEEK_OF_YEAR;
                        break;
                    case 'y':
                        type = Calendar.YEAR;
                        break;
                    default:
                        throw new CommandException("Unknown date value specified");
                }
                cal.add(type, Integer.valueOf(str.substring(0, str.length() -1)));
            }
            return cal.getTimeInMillis();
        }
View Full Code Here

                    shift = 0;
                } else if (period.equalsIgnoreCase("pm")
                        || period.equalsIgnoreCase("p.m.")) {
                    shift = 12;
                } else {
                    throw new CommandException("'am' or 'pm' expected, got '"
                            + period + "'.");
                }

                String[] parts = time.split(":");
                int hours = Integer.parseInt(parts[0]);
                int mins = parts.length >= 2 ? Integer.parseInt(parts[1]) : 0;
                return (int) ((((hours % 12) + shift - 8) % 24) * 1000
                        + (mins % 60) / 60.0 * 1000);

                // Or some shortcuts
            } else if (timeStr.equalsIgnoreCase("dawn")) {
                return (6 - 8 + 24) * 1000;
            } else if (timeStr.equalsIgnoreCase("sunrise")) {
                return (7 - 8 + 24) * 1000;
            } else if (timeStr.equalsIgnoreCase("morning")) {
                return (24) * 1000;
            } else if (timeStr.equalsIgnoreCase("day")) {
                return (24) * 1000;
            } else if (timeStr.equalsIgnoreCase("midday")
                    || timeStr.equalsIgnoreCase("noon")) {
                return (12 - 8 + 24) * 1000;
            } else if (timeStr.equalsIgnoreCase("afternoon")) {
                return (14 - 8 + 24) * 1000;
            } else if (timeStr.equalsIgnoreCase("evening")) {
                return (16 - 8 + 24) * 1000;
            } else if (timeStr.equalsIgnoreCase("sunset")) {
                return (21 - 8 + 24) * 1000;
            } else if (timeStr.equalsIgnoreCase("dusk")) {
                return (21 - 8 + 24) * 1000 + (int) (30 / 60.0 * 1000);
            } else if (timeStr.equalsIgnoreCase("night")) {
                return (22 - 8 + 24) * 1000;
            } else if (timeStr.equalsIgnoreCase("midnight")) {
                return (0 - 8 + 24) * 1000;
            }

            throw new CommandException("Time input format unknown.");
        }
View Full Code Here

         * @throws CommandException no matches found
         */
        public static List<Player> matchPlayers(CommandSender source, String filter) throws CommandException {

            if (CommandBook.server().getOnlinePlayers().isEmpty()) {
                throw new CommandException("No players matched query.");
            }

            if (filter.equals("*")) {
                CommandBook.inst().checkPermission(source, "commandbook.targets.everyone");
                return checkPlayerMatch(Lists.newArrayList(CommandBook.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")) {
                    World sourceWorld = checkPlayer(source).getWorld();
                    CommandBook.inst().checkPermission(source, "commandbook.targets.world." + sourceWorld.getName());
                    return checkPlayerMatch(sourceWorld.getPlayers());

                    // Handle #near, which is for nearby players.
                } else if (filter.startsWith("#near")) {
                    CommandBook.inst().checkPermission(source, "commandbook.targets.near");
                    List<Player> players = new ArrayList<Player>();
                    Player sourcePlayer = checkPlayer(source);
                    World sourceWorld = sourcePlayer.getWorld();
                    Location sourceLocation = sourcePlayer.getLocation();

                    double targetDistance = 30;

                    String[] split = filter.split(":");
                    if (split.length == 2) {
                        try {
                            targetDistance = Double.parseDouble(split[1]);
                        } catch (NumberFormatException ignored) { }
                    }

                    // Square the target distance so that we don't have to calculate the
                    // square root in this distance calculation
                    targetDistance = Math.pow(targetDistance, 2);

                    Location k = sourceLocation.clone(); // Included for optimization
                    for (Player player : CommandBook.server().getOnlinePlayers()) {
                        if (!player.getWorld().equals(sourceWorld)) continue;
                        if (player.getLocation(k).distanceSquared(sourceLocation) < targetDistance) {
                            players.add(player);
                        }
                    }

                    return checkPlayerMatch(players);

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

            return checkPlayerMatch(matchPlayerNames(source, filter));
        }
View Full Code Here

                        && player.getDisplayName().equalsIgnoreCase(filter))) {
                    return player;
                }
            }

            throw new CommandException("No player found!");
        }
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.