Package com.sk89q.minecraft.util.commands

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



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

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

        boolean deleteAll = false;
        if (context.argsLength() > 0 && !context.hasFlag('a')) {
            areaId = context.getString(0);
        } else if (context.hasFlag('a') && player.hasPermission("craftbook.mech.area.delete." + namespace + ".all")) {
            deleteAll = true;
        } else throw new CommandException("You need to define an area or -a to delete all areas.");

        // add the area suffix
        areaId = areaId + (Area.instance.useSchematics ? ".schematic" : ".cbcopy");

        File areas = null;
        try {
            areas = new File(plugin.getDataFolder(), "areas/" + namespace);
        } catch (Exception ignored) {
        }

        if (areas == null || !areas.exists())
            throw new CommandException("The namespace " + namespace + " does not exist.");

        if (deleteAll) {
            if (deleteDir(areas)) {
                player.print("All areas in the namespace " + namespace + " have been deleted.");
            }
View Full Code Here


        Player player = null;

        if(context.hasFlag('p'))
            player = Bukkit.getPlayer(context.getFlag('p'));
        else if(!(sender instanceof Player))
            throw new CommandException("Please provide a player! (-p flag)");
        else
            player = (Player) sender;

        if(player == null)
            throw new CommandException("Unknown Player!");

        if(CommandItems.INSTANCE == null)
            throw new CommandException("CommandItems are not enabled!");

        if(!sender.hasPermission("craftbook.mech.commanditems.give" + (context.hasFlag('p') ? ".others" : "") + "." + context.getString(0)))
            throw new CommandPermissionsException();

        CommandItemDefinition def = CommandItems.INSTANCE.getDefinitionByName(context.getString(0));
        if(def == null)
            throw new CommandException("Invalid CommandItem!");

        ItemStack stack = ItemUtil.makeItemValid(def.getItem().clone());
        if(context.hasFlag('a'))
            stack.setAmount(stack.getAmount() * context.getFlagInteger('a', 1));

        if(!player.getInventory().addItem(stack).isEmpty())
            throw new CommandException("Failed to add item to inventory!");

        if(!context.hasFlag('s'))
            sender.sendMessage(ChatColor.YELLOW + "Gave CommandItem " + ChatColor.BLUE + def.getName() + ChatColor.YELLOW + " to " + player.getName());
    }
View Full Code Here

    @Command(aliases = {"spawn"}, desc = "Spawns the item at the coordinates", flags = "w:a:s", usage = "<CommandItem Name> <x> <y> <z> [-w world] [-a amount] [-s]", min = 4)
    public void spawnItem(CommandContext context, CommandSender sender) throws CommandException {

        if(CommandItems.INSTANCE == null)
            throw new CommandException("CommandItems are not enabled!");

        if(!sender.hasPermission("craftbook.mech.commanditems.spawn" + context.getString(0)))
            throw new CommandPermissionsException();

        CommandItemDefinition def = CommandItems.INSTANCE.getDefinitionByName(context.getString(0));
        if(def == null)
            throw new CommandException("Invalid CommandItem!");

        World world = null;
        if(context.hasFlag('w'))
            world = Bukkit.getWorld(context.getFlag('w'));
        else if(sender instanceof Player)
            world = ((Player) sender).getWorld();
        else
            throw new CommandException("Either a player or world is required!");

        ItemStack stack = def.getItem().clone();

        stack = ItemUtil.makeItemValid(stack);
        if(context.hasFlag('a'))
View Full Code Here

            sender.sendMessage("CommandItems are not enabled!");
            return;
        }

        if(!(sender instanceof Player))
            throw new CommandException("Can only add CommandItems as a player!");
        if(((Player) sender).getInventory().getItemInHand() == null)
            throw new CommandException("Invalid Item for CommandItems!");
        Conversation convo = conversationFactory.buildConversation((Conversable) sender);
        convo.getContext().setSessionData("item", ((HumanEntity) sender).getInventory().getItemInHand());
        List<ItemStack> consumables = new ArrayList<ItemStack>();
        for(int i = 0; i <= 8; i++) {
            if(i == ((HumanEntity) sender).getInventory().getHeldItemSlot())
View Full Code Here

    @Command (aliases = {"ic","circuit"}, desc = "Information for a specific IC", usage = "<ic> (Further arguments depend on IC)", min = 1)
    public void icCmd(CommandContext args, CommandSender sender) throws CommandException {

        if(ICManager.inst() == null)
            throw new CommandException("ICs are not enabled!");
        if(args.getString(0).equalsIgnoreCase("list")) {

            String list = "";

            for(RegisteredICFactory factory : ICManager.inst().registered.values()) {
                if(factory.getFactory() instanceof CommandIC) {

                    if(list.isEmpty())
                        list = factory.getId();
                    else
                        list = list + ", " + factory.getId();
                }
            }

            sender.sendMessage(ChatColor.YELLOW + "Command IC List: " + list);
        } else {

            RegisteredICFactory factory = ICManager.inst().registered.get(args.getString(0));

            if(factory != null && factory.getFactory() instanceof CommandIC) {
                if(((CommandIC) factory.getFactory()).getMinCommandArgs()+1 > args.argsLength())
                    throw new CommandException();
                ((CommandIC) factory.getFactory()).onICCommand(args, sender);
            }
        }
    }
View Full Code Here

    @Command(aliases = {"docs"}, desc = "Documentation on CraftBook IC's",
            usage = "<ic>", min = 1, max = 1)
    public void docsCmd(CommandContext args, CommandSender sender) throws CommandException {

        if(ICManager.inst() == null)
            throw new CommandException("ICs are not enabled!");
        if (!(sender instanceof Player)) return;
        Player player = (Player) sender;
        ICDocsParser.generateICDocs(player, args.getString(0));
    }
View Full Code Here

    @Command(aliases = {"list"}, desc = "List available IC's",
            flags = "p:", usage = "[-p page]", min = 0, max = 0)
    public void listCmd(CommandContext args, CommandSender sender) throws CommandException {

        if(ICManager.inst() == null)
            throw new CommandException("ICs are not enabled!");
        if (!(sender instanceof Player)) return;
        Player player = (Player) sender;
        char[] ar = null;
        try {
            ar = args.getString(1).toCharArray();
View Full Code Here

    @Command(aliases = {"search"}, desc = "Search available IC's with names",
            flags = "p:", usage = "[-p page] <name>", min = 1, max = 1)
    public void searchCmd(CommandContext args, CommandSender sender) throws CommandException {

        if(ICManager.inst() == null)
            throw new CommandException("ICs are not enabled!");
        if (!(sender instanceof Player)) return;
        Player player = (Player) sender;
        char[] ar = null;
        try {
            ar = args.getString(2).toCharArray();
View Full Code Here

    @Command(aliases = {"midis"}, desc = "List MIDI's available for Melody IC",
            flags = "p:", usage = "[-p page]", min = 0, max = 0)
    public void midiListCmd(CommandContext args, CommandSender sender) throws CommandException {

        if(ICManager.inst() == null)
            throw new CommandException("ICs are not enabled!");
        if (!(sender instanceof Player)) return;
        Player player = (Player) sender;
        List<String> lines = new ArrayList<String>();

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

    @Command(aliases = {"fireworks"}, desc = "List Fireworks available for PFD IC",
            flags = "p:", usage = "[-p page]", min = 0, max = 0)
    public void fireworkListCmd(CommandContext args, CommandSender sender) throws CommandException {

        if(ICManager.inst() == null)
            throw new CommandException("ICs are not enabled!");
        if (!(sender instanceof Player)) return;
        Player player = (Player) sender;
        List<String> lines = new ArrayList<String>();

        FilenameFilter fnf = new FilenameFilter() {
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.