Package com.sk89q.minecraft.util.commands

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


            String item = args.getJoinedStrings(0);
            if (remove(sender, item)) {
                sender.sendMessage(ChatColor.YELLOW + titleCase(getTypeName()) +
                        " for command '" + item + "' removed.");
            } else {
                throw new CommandException("No " + getTypeName() + " for input " + item);
            }
        }
View Full Code Here


            String item = args.getJoinedStrings(0);
            if (remove(sender, item)) {
                sender.sendMessage(ChatColor.YELLOW + titleCase(getTypeName()) +
                        " for command '" + item + "' removed.");
            } else {
                throw new CommandException("No " + getTypeName() + " for input " + item);
            }
        }
View Full Code Here

                for (Player player : targets) {
                    getJingleNoteManager().play(player.getName(), sequencer);
                    player.sendMessage(ChatColor.YELLOW + "Playing intro.midi...");
                }
            } catch (MidiUnavailableException e) {
                throw new CommandException("Failed to access MIDI: "
                        + e.getMessage());
            } catch (InvalidMidiDataException e) {
                throw new CommandException("Failed to read intro MIDI file: "
                        + e.getMessage());
            } catch (FileNotFoundException e) {
                throw new CommandException("No intro.mid is available.");
            } catch (IOException e) {
                throw new CommandException("Failed to read intro MIDI file: "
                        + e.getMessage());
            }
        }
View Full Code Here

            CommandBook.inst().checkPermission(sender, "commandbook.midi");

            String filename = args.getString(0);

            if (!filename.matches("^[A-Za-z0-9 \\-_\\.~\\[\\]\\(\\$),]+$")) {
                throw new CommandException("Invalid filename specified!");
            }

            File[] trialPaths = {
                    new File(CommandBook.inst().getDataFolder(), "midi/" + filename),
                    new File(CommandBook.inst().getDataFolder(), "midi/" + filename + ".mid"),
                    new File(CommandBook.inst().getDataFolder(), "midi/" + filename + ".midi"),
                    new File("midi", filename),
                    new File("midi", filename + ".mid"),
                    new File("midi", filename + ".midi"),
            };

            File file = null;

            for (File f : trialPaths) {
                if (f.exists()) {
                    file = f;
                    break;
                }
            }

            if (file == null) {
                throw new CommandException("The specified MIDI file was not found.");
            }

            try {
                MidiJingleSequencer sequencer = new MidiJingleSequencer(file, false);
                for (Player player : targets) {
                    getJingleNoteManager().play(player.getName(), sequencer);
                    player.sendMessage(ChatColor.YELLOW + "Playing " + file.getName()
                            + "... Use '/midi' to stop.");
                }
            } catch (MidiUnavailableException e) {
                throw new CommandException("Failed to access MIDI: "
                        + e.getMessage());
            } catch (InvalidMidiDataException e) {
                throw new CommandException("Failed to read intro MIDI file: "
                        + e.getMessage());
            } catch (FileNotFoundException e) {
                throw new CommandException("The specified MIDI file was not found.");
            } catch (IOException e) {
                throw new CommandException("Failed to read intro MIDI file: "
                        + e.getMessage());
            }
        }
View Full Code Here

                    // Tell console, since console won't get the broadcast message.
                    sender.sendMessage(ChatColor.YELLOW + "Stormy weather disabled.");
                }

            } else {
                throw new CommandException("Unknown weather state! Acceptable states: sunny or stormy");
            }
        }
View Full Code Here

                            + world.getName() + "'.");
                } else {
                    sender.sendMessage(ChatColor.YELLOW + "Thunder disabled.");
                }
            } else {
                throw new CommandException("Unknown thunder state! Acceptable states: on or off");
            }
        }
View Full Code Here

    public LivingEntity spawn(Location loc, EntityType type, String specialTypes,
            CommandContext args, CommandSender sender) throws CommandException {
        Entity spawned = loc.getWorld().spawn(loc, type.getEntityClass());
        if (!(spawned instanceof LivingEntity)) {
            spawned.remove();
            throw new CommandException("Not a creature!");
        }
        LivingEntity creature = (LivingEntity) spawned;

        if (args.hasFlag('d')) {
            creature.setHealth(1);
        }
        if (args.hasFlag('i')) {
            creature.setFireTicks(20 * 25);
        }
        if (args.hasFlag('r')) {
            creature.setVelocity(new Vector(0, 2, 0));
        }
        if (args.hasFlag('b')) {
            if (creature instanceof Ageable) {
                ((Ageable) creature).setBaby();
            } else if (creature instanceof Zombie) {
                ((Zombie) creature).setBaby(true);
            }
        }
        if (args.hasFlag('p')) {
            creature.setCanPickupItems(true);
        }
        /*
        if (args.hasFlag('i')) {
            EntityLiving.bJ() // @TODO see about having this exposed to api?
        }
         */
        if (args.hasFlag('t') && creature instanceof Tameable) {
            if (sender instanceof AnimalTamer) {
                ((Tameable) creature).setOwner((AnimalTamer) sender);
            } else {
                ((Tameable) creature).setTamed(true);
            }
        }

        if (creature instanceof Skeleton) {
            creature.getEquipment().setItemInHand(new ItemStack(Material.BOW));
        } else if (creature instanceof PigZombie) {
            creature.getEquipment().setItemInHand(new ItemStack(Material.GOLD_SWORD));
        }

        String[] types = specialTypes.split(",");

        if (!specialTypes.isEmpty() && types.length > 0) {
            outerloop:
                for (String specialType : types) {
                    switch (creature.getType()) {
                    case WOLF:
                        if (specialType.matches("(?i)angry")) {
                            ((Wolf) creature).setAngry(true);
                        } else if (specialType.matches("(?i)sit(ting)?")) {
                            ((Wolf) creature).setSitting(true);
                        }
                        continue;
                    case OCELOT:
                        Ocelot.Type catType;
                        try {
                            catType = Ocelot.Type.valueOf(specialType.toUpperCase());
                        } catch (IllegalArgumentException e) {
                            throw new CommandException("Unknown cat type '" + specialType + "'. Allowed values are: "
                                    + valueList(Ocelot.Type.class));
                        }
                        if (catType != null) {
                            ((Ocelot) creature).setCatType(catType);
                        }
                        break outerloop; // only one color
                    case CREEPER:
                        if (specialType.matches("(?i)(power(ed)?|electric|lightning|shock(ed)?)")) {
                            ((Creeper) creature).setPowered(true);
                        }
                        break outerloop;
                    case SHEEP:
                        if (specialType.matches("(?i)shear(ed)?")) {
                            ((Sheep) creature).setSheared(true);
                        } else {
                            ((Sheep) creature).setColor(ItemUtil.matchDyeColor(specialType));
                        }
                        continue;
                    case PIG:
                        if (specialType.matches("(?i)saddle(d)?")) {
                            ((Pig) creature).setSaddle(true);
                        }
                        break outerloop;
                    case SLIME:
                        ((Slime) creature).setSize(Integer.parseInt(specialType));
                        break outerloop;
                    case SKELETON:
                        if (specialType.matches("(?i)wither")) {
                            ((Skeleton) creature).setSkeletonType(Skeleton.SkeletonType.WITHER);
                        }
                        break outerloop;
                    case PIG_ZOMBIE:
                        if (specialType.matches("(?i)angry")) {
                            ((PigZombie) creature).setAngry(true);
                            return creature;
                        } else {
                            ((PigZombie) creature).setAnger(Integer.parseInt(specialType));
                        }
                        break outerloop; // having both would be redundant
                    case ZOMBIE:
                        if (specialType.matches("(?i)villager")) {
                            ((Zombie) creature).setVillager(true);
                        }
                        break;
                    case ENDERMAN:
                        ItemStack item = ItemUtil.getItem(specialType);
                        if (item == null) return creature;
                        ((Enderman) creature).setCarriedMaterial(item.getData());
                        break outerloop; // only one set of hands
                    case IRON_GOLEM:
                        if (specialType.matches("(?i)(friendly|player(-created)?)")) {
                            ((IronGolem) creature).setPlayerCreated(true);
                        }
                        break outerloop;
                    case VILLAGER:
                        Villager.Profession profession;
                        try {
                            profession = Villager.Profession.valueOf(specialType.toUpperCase());
                        } catch (IllegalArgumentException e) {
                            throw new CommandException("Unknown profession '" + specialType + "'. Allowed values are: "
                                    + valueList(Villager.Profession.class));
                        }
                        if (profession != null) {
                            ((Villager) creature).setProfession(profession);
                        }
                        break outerloop; // only one profession
                    case HORSE:
                        Horse.Color color = null;
                        Horse.Style style = null;
                        Horse.Variant variant = null;
                        try {
                            color = Horse.Color.valueOf(specialType.toUpperCase());
                        } catch (IllegalArgumentException e) {}
                        if (color != null) {
                            ((Horse) creature).setColor(color);
                            continue;
                        }
                        try {
                            style = Horse.Style.valueOf(specialType.toUpperCase());
                        } catch (IllegalArgumentException e) {}
                        if (style != null) {
                            ((Horse) creature).setStyle(style);
                            continue;
                        }
                        try {
                            variant = Horse.Variant.valueOf(specialType.toUpperCase());
                        } catch (IllegalArgumentException e) {}
                        if (variant != null) {
                            ((Horse) creature).setVariant(variant);
                            continue;
                        }
                        throw new CommandException("Unknown color, style, or variant '" + specialType + "'.");
                    default:
                        break outerloop; // can't do anything with this animal, regardless of all the types given
                    }
                }
        }
View Full Code Here

     * @throws CommandException if the location by said id does not exist
     */
    public static Location getManagedLocation(RootLocationManager<NamedLocation> manager,
                                       World world, String id) throws CommandException {
        NamedLocation loc = manager.get(world, id);
        if (loc == null) throw new CommandException("A location by that name could not be found.");
        return loc.getLocation();
    }
View Full Code Here

            } else {
                // Then check WorldEdit
                ItemType type = ItemType.lookup(name);

                if (type == null) {
                    throw new CommandException("No item type known by '" + name + "'");
                }

                id = type.getID();
            }
        }

        // If the user specified an item data or damage value, let's try
        // to parse it!
        if (dataName != null) {
            dmg = matchItemData(id, dataName);
        }

        ItemStack stack = new ItemStack(id, 1, (short)dmg);

        if (enchantmentName != null) {
            String[] enchantments = enchantmentName.split(",");
            for (String enchStr : enchantments) {
                int level = 1;
                if (enchStr.contains(":")) {
                    String[] parts = enchStr.split(":");
                    enchStr = parts[0];
                    try {
                        level = Integer.parseInt(parts[1]);
                    } catch (NumberFormatException ignore) {}
                }

                Enchantment ench = null;
                final String testName = enchStr.toLowerCase().replaceAll("[_\\-]", "");
                for (Enchantment possible : Enchantment.values()) {
                    if (possible.getName().toLowerCase().replaceAll("[_\\-]", "").equals(testName)) {
                        ench = possible;
                        break;
                    }
                }

                if (ench == null) {
                    throw new CommandException("Unknown enchantment '" + enchStr + "'");
                }

                stack.addUnsafeEnchantment(ench, level);
            }
View Full Code Here

                    return 1;
                } else if (filter.equalsIgnoreCase("birch")) {
                    return 2;
                }

                throw new CommandException("Unknown wood type name of '" + filter + "'.");
            case BlockID.STEP:
            case BlockID.DOUBLE_STEP:
                BlockType dataType = BlockType.lookup(filter);

                if (dataType != null) {
                    if (dataType == BlockType.STONE) {
                        return 0;
                    } else if (dataType == BlockType.SANDSTONE) {
                        return 1;
                    } else if (dataType == BlockType.WOOD) {
                        return 2;
                    } else if (dataType == BlockType.COBBLESTONE) {
                        return 3;
                    } else {
                        throw new CommandException("Invalid slab material of '" + filter + "'.");
                    }
                } else {
                    throw new CommandException("Unknown slab material of '" + filter + "'.");
                }
            case BlockID.CLOTH:
            case BlockID.STAINED_CLAY:
            case BlockID.STAINED_GLASS:
            case BlockID.STAINED_GLASS_PANE:
                ClothColor col = ClothColor.lookup(filter);
                if (col != null) {
                    return col.getID();
                }

                throw new CommandException("Unknown wool color name of '" + filter + "'.");
            case ItemID.INK_SACK: // Dye
                ClothColor dyeCol = ClothColor.lookup(filter);
                if (dyeCol != null) {
                    return 15 - dyeCol.getID();
                }

                throw new CommandException("Unknown dye color name of '" + filter + "'.");
            default:
                throw new CommandException("Invalid data value of '" + filter + "'.");
        }
    }
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.