@Override protected boolean onParse(String value) { String[] split = value.split("\\|"); value = split[0].trim(); EntityType type = Tools.parseEnum(value, EntityType.values()); if (type == null || !type.isAlive()) { ErrorReporter.error( "The " + getType() + " flag has invalid creature: " + value, "Look in '" + Files.FILE_INFO_NAMES + "' at 'ENTITY TYPES' section for ALIVE entities."); return false; } Customization c = new Customization(type); if (split.length > 1) { for (int n = 1; n < split.length; n++) { String original = split[n].trim(); value = original.toLowerCase(); if (value.equals("noremove")) { c.setNoRemove(true); } else if (value.equals("noeffect")) { c.setNoEffect(true); } else if (value.equals("target")) { c.setTarget(true); } else if (value.equals("nohidename")) { c.setNoHideName(true); } else if (value.equals("mountnext")) { c.setMountNext(true); } else if (value.equals("angry")) { switch (type) { case WOLF: case PIG_ZOMBIE: break; default: ErrorReporter.warning("Flag " + getType() + " has 'angry' on unsupported creature!"); continue; } c.setAngry(true); } else if (value.equals("shearedsheep")) { if (type != EntityType.SHEEP) { ErrorReporter.warning( "Flag " + getType() + " has 'shearedsheep' on non-sheep creature!"); continue; } c.setShearedSheep(true); } else if (value.equals("zombievillager")) { if (type != EntityType.ZOMBIE) { ErrorReporter.warning( "Flag " + getType() + " has 'zombievillager' on non-zombie creature!"); continue; } c.setZombieVillager(true); } else if (value.equals("poweredcreeper")) { if (type != EntityType.CREEPER) { ErrorReporter.warning( "Flag " + getType() + " has 'poweredcreeper' on non-creeper creature!"); continue; } c.setPoweredCreeper(true); } else if (value.equals("playerirongolem")) { if (type != EntityType.IRON_GOLEM) { ErrorReporter.warning( "Flag " + getType() + " has 'playerirongolem' on non-irongolem creature!"); continue; } c.setPlayerIronGolem(true); } else if (value.equals("hit")) { c.setHit(true); } else if (value.equals("baby")) { switch (type) { case CHICKEN: case COW: case MUSHROOM_COW: case OCELOT: case PIG: case SHEEP: case VILLAGER: case WOLF: case ZOMBIE: // has set/getBaby() but does not implement Ageable break; default: ErrorReporter.warning( "Flag " + getType() + " has 'baby' set on unsupported creature!"); continue; } c.setBaby(true); } else if (value.equals("agelock")) { switch (type) { case CHICKEN: case COW: case MUSHROOM_COW: case OCELOT: case PIG: case SHEEP: case VILLAGER: case WOLF: break; default: ErrorReporter.warning( "Flag " + getType() + " has 'agelock' set on unsupported creature!"); continue; } c.setAgeLock(true); } else if (value.equals("nobreed")) { switch (type) { case CHICKEN: case COW: case MUSHROOM_COW: case OCELOT: case PIG: case SHEEP: case VILLAGER: case WOLF: break; default: ErrorReporter.warning( "Flag " + getType() + " has 'nobreed' set on unsupported creature!"); continue; } c.setNoBreed(true); } else if (value.startsWith("pickup")) { value = value.substring("pickup".length()).trim(); if (value.isEmpty()) { c.setPickup(true); } else { c.setPickup(value.equals("true")); } } else if (value.startsWith("pet")) { switch (type) { case WOLF: case OCELOT: break; default: ErrorReporter.warning("Flag " + getType() + " has 'pet' on untameable creature!"); continue; } c.setPet(true); if (value.length() > "pet".length()) { value = value.substring("pet".length()).trim(); if (value.equals("nosit")) { c.setNoSit(true); } else { ErrorReporter.warning( "Flag " + getType() + " has 'pet' argument with unknown value: " + value); } } } else if (value.startsWith("saddle")) { if (type != EntityType.PIG) { ErrorReporter.warning("Flag " + getType() + " has 'saddle' on non-pig creature!"); continue; } c.setSaddle(true); if (value.length() > "saddle".length()) { value = value.substring("saddle".length()).trim(); if (value.equals("mount")) { c.setMount(true); } else { ErrorReporter.warning( "Flag " + getType() + " has 'saddle' argument with unknown value: " + value); } } } else if (value.startsWith("chance")) { value = value.substring("chance".length()).trim(); if (value.charAt(value.length() - 1) == '%') { value = value.substring(0, value.length() - 1); } try { c.setChance(Float.valueOf(value)); } catch (NumberFormatException e) { ErrorReporter.warning( "Flag " + getType() + " has 'chance' argument with invalid number: " + value); continue; } } else if (value.startsWith("num")) { value = value.substring("num".length()).trim(); try { c.setNum(Integer.valueOf(value)); } catch (NumberFormatException e) { ErrorReporter.warning( "Flag " + getType() + " has 'num' argument with invalid value number: " + value); } } else if (value.startsWith("spread")) { value = value.substring("spread".length()).trim(); try { c.setSpread(Integer.valueOf(value)); } catch (NumberFormatException e) { ErrorReporter.warning( "Flag " + getType() + " has 'spread' argument with invalid value number: " + value); } } else if (value.startsWith("onfire")) { value = value.substring("onfire".length()).trim(); try { c.setOnFire(Float.valueOf(value) * 20.0f); } catch (NumberFormatException e) { ErrorReporter.warning( "Flag " + getType() + " has 'onfire' argument with invalid value number: " + value); } } else if (value.startsWith("color")) { switch (type) { case SHEEP: case WOLF: break; default: ErrorReporter.warning("Flag " + getType() + " has 'color' on unsupported creature!"); continue; } value = value.substring("color".length()).trim(); c.setColor(Tools.parseEnum(value, DyeColor.values())); if (c.getColor() == null) { ErrorReporter.warning( "Flag " + getType() + " has 'color' argument with invalid dye color: " + value); } } else if (value.startsWith("villager")) { if (type != EntityType.VILLAGER) { ErrorReporter.warning( "Flag " + getType() + " has 'villager' argument on non-villager creature!"); continue; } value = value.substring("villager".length()).trim(); c.setVillager(Tools.parseEnum(value, Villager.Profession.values())); if (c.getVillager() == null) { ErrorReporter.warning( "Flag " + getType() + " has 'villager' argument with invalid type: " + value); } } else if (value.startsWith("skeleton")) { if (type != EntityType.SKELETON) { ErrorReporter.warning( "Flag " + getType() + " has 'skeleton' argument on non-skeleton creature!"); continue; } value = value.substring("skeleton".length()).trim(); c.setSkeleton(Tools.parseEnum(value, SkeletonType.values())); if (c.getSkeleton() == null) { ErrorReporter.warning( "Flag " + getType() + " has 'skeleton' argument with invalid type: " + value); } } else if (value.startsWith("cat")) { if (type != EntityType.OCELOT) { ErrorReporter.warning( "Flag " + getType() + " has 'cat' argument on non-ocelot creature!"); continue; } value = value.substring("cat".length()).trim(); c.setCat(Tools.parseEnum(value, Ocelot.Type.values())); if (c.getCat() == null) { ErrorReporter.warning( "Flag " + getType() + " has 'cat' argument with invalid type: " + value); } } else if (value.startsWith("name")) { value = original.substring("name".length()).trim(); c.setName(value); } else if (value.startsWith("hp")) { value = value.substring("hp".length()).trim(); String[] args = value.split(" "); value = args[0].trim(); try { c.setHp(Integer.valueOf(value)); } catch (NumberFormatException e) { ErrorReporter.warning( "Flag " + getType() + " has 'hp' argument with invalid number: " + value); continue; } if (args.length > 1) { value = args[1].trim(); try { c.setMaxHp(Integer.valueOf(value)); } catch (NumberFormatException e) { ErrorReporter.warning( "Flag " + getType() + " has 'hp' argument with invalid number for maxhp: " + value); continue; } } } else if (value.startsWith("potion")) { value = value.substring("potion".length()).trim(); String[] args = value.split(" "); value = args[0].trim(); PotionEffectType effect = PotionEffectType.getByName( value); // Tools.parseEnum(value, PotionEffectType.values()); if (effect == null) { ErrorReporter.warning( "Flag " + getType() + " has 'potion' argument with invalid type: " + value); continue; } float duration = 1; int amplifier = 0; if (args.length > 1) { value = args[1].trim(); try { duration = Float.valueOf(value); } catch (NumberFormatException e) { ErrorReporter.warning( "Flag " + getType() + " has 'potion' argument with invalid number for duration: " + value); continue; } } if (args.length > 2) { value = args[2].trim(); try { amplifier = Integer.valueOf(value); } catch (NumberFormatException e) { ErrorReporter.warning( "Flag " + getType() + " has 'potion' argument with invalid number for amplifier: " + value); continue; } } c.addPotionEffect(effect, duration, amplifier); } else if (value.startsWith("hand") || value.startsWith("hold") || value.startsWith("head") || value.startsWith("helmet") || value.startsWith("chest") || value.startsWith("leg") || value.startsWith("feet") || value.startsWith("boot")) { int index = -1; switch (value.charAt(0)) { case 'h': switch (value.charAt(1)) { case 'e': index = 0; break; case 'o': case 'a': index = 4; break; } break; case 'c': index = 1; break; case 'l': index = 2; break; case 'b': case 'f': index = 3; break; } if (index < 0) { ErrorReporter.warning("Flag " + getType() + " has unknown argument: " + value); continue; } int i = value.indexOf(' '); String[] args = value.substring(i + 1).trim().split(" "); value = args[0].trim(); ItemStack item = Tools.parseItem(value, 0); if (item == null) { continue; } c.getEquip()[index] = item; if (args.length > 1) { value = args[1].trim(); if (value.charAt(value.length() - 1) == '%') { value = value.substring(0, value.length() - 1); } try { c.getDrop()[index] = Math.min(Math.max(Float.valueOf(value), 0), 100); } catch (NumberFormatException e) { ErrorReporter.warning( "Flag " + getType() + " has 'chance' argument with invalid number: " + value); continue; } } } else { ErrorReporter.warning("Flag " + getType() + " has unknown argument: " + value); } } } if (type == EntityType.WOLF) { if (c.isPet()) { if (c.isAngry()) { c.setAngry(false); ErrorReporter.warning( "Flag " + getType() + " has 'angry' with 'pet' on wolf! Argument 'angry' ignored."); } } else { if (c.getColor() != null) { c.setColor(null); ErrorReporter.warning( "Flag " + getType() + " has 'color' argument without wolf being a pet, ignored."); } } } addSpawn(c); return true; }
@Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (args.length > 0) { String name = (sender instanceof Player ? sender.getName() : null); boolean next = args[0].equalsIgnoreCase("next"); if (next || args[0].equalsIgnoreCase("prev")) { Pages pages = pagination.get(name); if (pages != null) { if (next ? pages.hasNext() : pages.hasPrev()) { String page = (next ? pages.next() : pages.prev()); Messages.CMD_RECIPES_HEADER.print( sender, null, "{item}", Tools.Item.print(pages.item), "{num}", (pages.page + 1), "{total}", pages.pages.length); Messages.send(sender, page); if (pages.hasNext()) { Messages.CMD_RECIPES_MORE.print( sender, null, "{cmdnext}", "/" + label + " next", "{cmdprev}", "/" + label + " prev"); } else { Messages.CMD_RECIPES_END.print(sender); } } else { if (next) { Messages.CMD_RECIPES_NONEXT.print(sender, null, "{command}", "/" + label + " prev"); } else { Messages.CMD_RECIPES_NOPREV.print(sender, null, "{command}", "/" + label + " next"); } } } else { Messages.CMD_RECIPES_NEEDQUERY.print(sender); } } else { ItemStack item; if (args[0].equalsIgnoreCase("this")) { if (sender instanceof Player) { Player player = (Player) sender; item = player.getItemInHand(); if (item == null) { Messages.CMD_RECIPES_NOHAND.print(sender); return true; } } else { sender.sendMessage("The 'this' argument can't be used from console."); return true; } } else { item = Tools.parseItem(args[0], Vanilla.DATA_WILDCARD, ParseBit.NO_META | ParseBit.NO_PRINT); if (item == null) { Messages.CMD_RECIPES_INVALIDITEM.print(sender, null, "{arg}", args[0]); return true; } } boolean ingredient = (args.length > 1 && args[1].charAt(0) == 'i'); List<String> list = new ArrayList<String>(); for (Entry<BaseRecipe, RecipeInfo> e : RecipeManager.getRecipes().getRecipeList().entrySet()) { BaseRecipe recipe = e.getKey(); if (hasItem(recipe, item, ingredient)) { list.add(recipe.printChat()); } } if (!list.isEmpty()) { Pages pages = new Pages(name, item, list); pagination.put(name, pages); Messages.CMD_RECIPES_HEADER.print( sender, null, "{item}", Tools.Item.print(pages.item), "{num}", 1, "{total}", pages.pages.length); Messages.send(sender, pages.next()); if (pages.hasNext()) { Messages.CMD_RECIPES_MORE.print( sender, null, "{cmdnext}", "/" + label + " next", "{cmdprev}", "/" + label + " prev"); } else { Messages.CMD_RECIPES_END.print(sender); } } else { Messages.CMD_RECIPES_NORESULTS.print(sender, null, "{item}", Tools.Item.print(item)); } } } else { int mc = 0; int rm = 0; int other = 0; for (RecipeInfo info : RecipeManager.getRecipes().getRecipeList().values()) { switch (info.getOwner()) { case MINECRAFT: { mc++; break; } case RECIPEMANAGER: { rm++; break; } default: { other++; } } } Messages.CMD_RECIPES_USAGE.print(sender, null, "{command}", label); Messages.CMD_RECIPES_STATS_MC.print(sender, null, "{num}", mc); Messages.CMD_RECIPES_STATS_RM.print(sender, null, "{num}", rm); Messages.CMD_RECIPES_STATS_OTHER.print(sender, null, "{num}", other); } return true; }