public Construct exec(Target t, Environment environment, Construct... args) throws ConfigRuntimeException { Static.checkPlugin("mcMMO", t); BukkitMCPlayer player = (BukkitMCPlayer) Static.GetPlayer(args[0], t); SkillType skill; int amount = 1; try { skill = SkillType.valueOf(args[1].val().toUpperCase()); } catch (Exception e) { throw new ConfigRuntimeException( "Unknown McMMO skilltype for mcmmo_add_level, " + args[1].val(), Exceptions.ExceptionType.NotFoundException, t); } if (args.length == 3) { try { amount = Integer.parseInt(args[2].val()); } catch (Exception e) { throw new ConfigRuntimeException( "Bad amount for mcmmo_add_level, " + args[2].val(), Exceptions.ExceptionType.RangeException, t); } } ExperienceAPI.addLevel(player._Player(), skill.name(), amount); return new CVoid(t); }
@Override protected void loadKeys() { config.setDefaults(YamlConfiguration.loadConfiguration(plugin.getResource("child.yml"))); FamilyTree.clearRegistrations(); // when reloading, need to clear statics for (SkillType skill : SkillType.CHILD_SKILLS) { plugin.debug("Finding parents of " + skill.name()); EnumSet<SkillType> parentSkills = EnumSet.noneOf(SkillType.class); boolean useDefaults = false; // If we had an error we back out and use defaults for (String name : config.getStringList(StringUtils.getCapitalized(skill.name()))) { try { SkillType parentSkill = SkillType.valueOf(name.toUpperCase()); FamilyTree.enforceNotChildSkill(parentSkill); parentSkills.add(parentSkill); } catch (IllegalArgumentException ex) { plugin.getLogger().warning(name + " is not a valid skill type, or is a child skill!"); useDefaults = true; break; } } if (useDefaults) { parentSkills.clear(); for (String name : config.getDefaults().getStringList(StringUtils.getCapitalized(skill.name()))) { /* We do less checks in here because it's from inside our jar. * If they're dedicated enough to have modified it, they can have the errors it may produce. * Alternatively, this can be used to allow child skills to be parent skills, provided there are no circular dependencies this is an advanced sort of configuration. */ parentSkills.add(SkillType.valueOf(name.toUpperCase())); } } // Register them for (SkillType parentSkill : parentSkills) { plugin.debug("Registering " + parentSkill.name() + " as parent of " + skill.name()); FamilyTree.registerParent(skill, parentSkill); } } FamilyTree.closeRegistration(); }
/** * Creates a new mcMMO replacer. This also validates if all variables are available and can be * used in the runtime. */ public McmmoVariables() { final ImmutableSet.Builder<String> builder = ImmutableSet.builder(); // goes through all available skill types for (SkillType type : SkillType.values()) { final String skillName = type.name().toLowerCase(Locale.ENGLISH); builder.add('%' + skillName + '%'); } skillTypes = builder.build(); }
public static SkillType getSkill(String skillName) { if (!Config.getInstance().getLocale().equalsIgnoreCase("en_US")) { for (SkillType type : values()) { if (skillName.equalsIgnoreCase( LocaleLoader.getString(StringUtils.getCapitalized(type.name()) + ".SkillName"))) { return type; } } } for (SkillType type : values()) { if (type.name().equalsIgnoreCase(skillName)) { return type; } } if (!skillName.equalsIgnoreCase("all")) { mcMMO.p.getLogger().warning("Invalid mcMMO skill (" + skillName + ")"); // TODO: Localize } return null; }