diff --git a/src/main/java/com/gmail/nossr50/api/AbilityAPI.java b/src/main/java/com/gmail/nossr50/api/AbilityAPI.java index b83e03652..b1b1e958d 100644 --- a/src/main/java/com/gmail/nossr50/api/AbilityAPI.java +++ b/src/main/java/com/gmail/nossr50/api/AbilityAPI.java @@ -104,55 +104,136 @@ public final class AbilityAPI { return BleedTimerTask.isBleeding(entity); } + /** + * Creates a new ability to be used with a skill that is effective on certain blocks with a default cooldown of 240 + * + * @param name the name of the ability + * @param skillName the name of the skill (used for localization only) + * @param materials the materials that the skill is effective on (ability will only activate when one of those blocks is entered) + * @return the ability created + */ public static AbilityType createAbility(String name, String skillName, final Material... materials) { return createAbility(name, skillName, 240, materials); } - + + /** + * Creates a new ability to be used with a skill with a default cooldown of 240 + * + * @param name the name of the ability + * @param skillName the name of the skill (used for localization only) + * @return the ability created + */ public static AbilityType createAbility(String name, String skillName) { return createAbility(name, skillName, 240); } - + + /** + * Creates a new ability to be used with a skill that is effective on certain blocks with a specified default cooldown + * + * @param name the name of the ability + * @param skillName the name of the skill (used for localization only) + * @param materials the materials that the skill is effective on + * @param cooldown the default cooldown of the ability + * @return the ability created + */ public static AbilityType createAbility(String name, String skillName, int cooldown, final Material... materials) { AbilityType ability = AbilityType.createAbility(name, skillName, materials); Config.getInstance().createAbility(ability, cooldown); return ability; } - + + /** + * Creates a new ability to be used with a skill with a specified default cooldown + * + * @param name the name of the ability + * @param skillName the name of the skill (used for localization only) + * @param cooldown the default cooldown of the ability + * @return the ability created + */ public static AbilityType createAbility(String name, String skillName, int cooldown) { AbilityType ability = AbilityType.createAbility(name, skillName); Config.getInstance().createAbility(ability, cooldown); return ability; } - + + /** + * Creates a secondary ability to be used with a skill with a max bonus level of 0 and max chance of 100 + * + * @param name the name of the ability + * @param skillName the name of the skill (used for config only) + * @return the secondary ability created + */ public static SecondaryAbility createSecondaryAbility(String name, String skillName) { return createSecondaryAbility(name, skillName, 0, 100); } + /** + * Creates a secondary ability to be used with a skill with specified default config + * + * @param name the name of the ability + * @param skillName the name of the skill (used for config only) + * @param maxBonuslevel the level where the skill is at it's maximum chance + * @param maxChance the maximum chance of the skill + * @return the secondary ability created + */ public static SecondaryAbility createSecondaryAbility(String name, String skillName, int maxBonusLevel, double maxChance) { SecondaryAbility ability = new SecondaryAbility(name); AdvancedConfig.getInstance().createNewSkill(ability, skillName, maxBonusLevel, maxChance); return ability; } + /** + * Checks if the specified player has permission to use the specified ability + * @param player the player to check the permission for + * @param ability the ability that the player wants to use + * @return true if the player has permission and false if they don't + */ public static boolean hasSecondaryAbilityPermissions(Player player, SecondaryAbility ability) { return Permissions.secondaryAbilityEnabled(player, ability); } - public static boolean wasSecondaryAbilityActivationSuccessful(SecondaryAbility skillAbility, Player player, SkillType skill) { - return SkillUtils.activationSuccessful(skillAbility, player, skill); + /** + * Checks if a secondary ability's chances of activating would succeed + * @param skillAbility the secondary ability to check for + * @param player the player who wants to use the secondary ability + * @return true if the player can successfully use the ability this time + */ + public static boolean wasSecondaryAbilityActivationSuccessful(SecondaryAbility skillAbility, Player player) { + return SkillUtils.activationSuccessful(skillAbility, player); } + /** + * Activates an ability for a player + * @param skill the skill that the player is trying to use the ability for + * @param player the player trying to use the ability + * @param blockState a blockstate that must be passed to check if the ability is allowed to use it + */ public static void activateSkillAbility(SkillType skill, Player player, BlockState blockState) { SkillAbilityManager abilityManager = SkillAPI.getSkillAbilityManager(skill, player); if(abilityManager != null) { abilityManager.doAbilityPreparationCheck(blockState); } } - + + /** + * Activates an ability for a player + * @param skill the skill that the player is trying to use the ability for + * @param player the player trying to use the ability + */ public static void activateSkillAbility(SkillType skill, Player player) { SkillAbilityManager abilityManager = SkillAPI.getSkillAbilityManager(skill, player); if(abilityManager != null) { abilityManager.doAbilityPreparationCheck(null); } } + + /** + * Checks if an ability will activate when passed this blockstate + * @param ability the ability to check for + * @param blockState the blockstate to see if the ability will activate for it + * @return whether the ability will activate when passed this blockstate + */ + public static boolean abilityBlockCheck(AbilityType ability, BlockState blockState) { + return ability.blockCheck(blockState); + } } diff --git a/src/main/java/com/gmail/nossr50/api/LocaleAPI.java b/src/main/java/com/gmail/nossr50/api/LocaleAPI.java index c6c6268e2..457709a37 100644 --- a/src/main/java/com/gmail/nossr50/api/LocaleAPI.java +++ b/src/main/java/com/gmail/nossr50/api/LocaleAPI.java @@ -1,15 +1,26 @@ package com.gmail.nossr50.api; +import java.util.Locale; import java.util.ResourceBundle; import com.gmail.nossr50.locale.LocaleLoader; public final class LocaleAPI { + /** + * Adds a default resource localization bundle and a localized one + * @param bundle the bundle with priority + * @param defaultBundle the default bundle to fall back on + */ public static void addBundles(ResourceBundle bundle, ResourceBundle defaultBundle) { LocaleLoader.addResourceBundle(bundle, defaultBundle); } + /** + * Adds a localization bundle to the locale loader + * @param bundle the localization bundle to add + * @param isDefault whether the bundle is a default bundle (has lower priority) + */ public static void addBundle(ResourceBundle bundle, boolean isDefault) { if(isDefault) { addBundles(null, bundle); @@ -18,5 +29,13 @@ public final class LocaleAPI { addBundles(bundle, null); } } + + /** + * Gets the current locale to create a resource bundle for + * @return the current locale + */ + public static Locale getCurrentLocale() { + return LocaleLoader.getCurrentLocale(); + } } diff --git a/src/main/java/com/gmail/nossr50/api/SkillAPI.java b/src/main/java/com/gmail/nossr50/api/SkillAPI.java index f7e773ce7..4ef6cffa6 100644 --- a/src/main/java/com/gmail/nossr50/api/SkillAPI.java +++ b/src/main/java/com/gmail/nossr50/api/SkillAPI.java @@ -15,6 +15,8 @@ import com.gmail.nossr50.datatypes.skills.SkillType.SkillUseType; import com.gmail.nossr50.datatypes.skills.ToolType; import com.gmail.nossr50.skills.SkillAbilityManager; import com.gmail.nossr50.skills.SkillManager; +import com.gmail.nossr50.skills.child.ChildConfig; +import com.gmail.nossr50.skills.child.FamilyTree; import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.commands.CommandRegistrationManager; import com.gmail.nossr50.util.player.UserManager; @@ -105,40 +107,124 @@ public final class SkillAPI { return skills; } + /** + * Creates a mcmmo skill + * @param name the name of the skill in all caps + * @param managerClass the manager class for the skill + * @param commandClass the command handler for the skill + * @param isChild whether the skill is a child + * @param runescapeColor the runescape color for the skill + * @param skillUseType what the skill use type of the skill is (COMBAT, GATHERING, MISC) + * @param secondaryAbilities the list of secondary abilities the skill can use + * @return the mcmmo skill created + */ public static SkillType createSkill(String name, Class managerClass, Class commandClass, boolean isChild, Color runescapeColor, SkillUseType skillUseType, List secondaryAbilities) { SkillType skill = SkillType.createSkill(name, managerClass, commandClass, isChild, runescapeColor, skillUseType, secondaryAbilities); CommandRegistrationManager.registerSkillCommandAndPassSkillToConstructor(skill); return skill; } - + + /** + * Creates a mcmmo skill with an ability + * @param name the name of the skill in all caps + * @param managerClass the manager class for the skill + * @param commandClass the command handler for the skill + * @param isChild whether the skill is a child + * @param runescapeColor the runescape color for the skill + * @param skillUseType what the skill use type of the skill is (COMBAT, GATHERING, MISC) + * @param ability the AbilityType attached to this skill + * @param materials what tools can activate the ability + * @param secondaryAbilities the list of secondary abilities the skill can use + * @return the mcmmo skill created + */ public static SkillType createSkill(String name, Class managerClass, Class commandClass, boolean isChild, Color runescapeColor, SkillUseType skillUseType, AbilityType ability, Material[] materials, List secondaryAbilities) { SkillType skill = SkillType.createSkill(name, managerClass, commandClass, isChild, runescapeColor, skillUseType, ability, ToolType.createToolType(StringUtils.getCapitalized(name), materials), secondaryAbilities); CommandRegistrationManager.registerSkillCommandAndPassSkillToConstructor(skill); return skill; } - + + /** + * Creates a mcmmo skill with an ability + * @param name the name of the skill in all caps + * @param managerClass the manager class for the skill + * @param commandClass the command handler for the skill + * @param isChild whether the skill is a child + * @param runescapeColor the runescape color for the skill + * @param skillUseType what the skill use type of the skill is (COMBAT, GATHERING, MISC) + * @param ability the AbilityType attached to this skill + * @param secondaryAbilities the list of secondary abilities the skill can use + * @return the mcmmo skill created + */ public static SkillType createSkill(String name, Class managerClass, Class commandClass, boolean isChild, Color runescapeColor, SkillUseType skillUseType, AbilityType ability, List secondaryAbilities) { SkillType skill = SkillType.createSkill(name, managerClass, commandClass, isChild, runescapeColor, skillUseType, ability, ToolType.createToolType(StringUtils.getCapitalized(name)), secondaryAbilities); CommandRegistrationManager.registerSkillCommandAndPassSkillToConstructor(skill); return skill; } - + + /** + * Creates a mcmmo skill + * @param name the name of the skill in all caps + * @param managerClass the manager class for the skill + * @param commandClass the command handler for the skill + * @param isChild whether the skill is a child + * @param runescapeColor the runescape color for the skill + * @param skillUseType what the skill use type of the skill is (COMBAT, GATHERING, MISC) + * @param secondaryAbilities the list of secondary abilities the skill can use + * @return the mcmmo skill created + */ public static SkillType createSkill(String name, Class managerClass, Class commandClass, boolean isChild, Color runescapeColor, SkillUseType skillUseType, SecondaryAbility... secondaryAbilities) { return createSkill(name, managerClass, commandClass, isChild, runescapeColor, skillUseType, ImmutableList.copyOf(secondaryAbilities)); } - + + /** + * Creates a mcmmo skill with an ability + * @param name the name of the skill in all caps + * @param managerClass the manager class for the skill + * @param commandClass the command handler for the skill + * @param isChild whether the skill is a child + * @param runescapeColor the runescape color for the skill + * @param skillUseType what the skill use type of the skill is (COMBAT, GATHERING, MISC) + * @param ability the AbilityType attached to this skill + * @param materials what tools can activate the ability + * @param secondaryAbilities the list of secondary abilities the skill can use + * @return the mcmmo skill created + */ public static SkillType createSkill(String name, Class managerClass, Class commandClass, boolean isChild, Color runescapeColor, SkillUseType skillUseType, AbilityType ability, Material[] materials, SecondaryAbility... secondaryAbilities) { return createSkill(name, managerClass, commandClass, isChild, runescapeColor, skillUseType, ability, materials, ImmutableList.copyOf(secondaryAbilities)); } - + + /** + * Creates a mcmmo skill with an ability + * @param name the name of the skill in all caps + * @param managerClass the manager class for the skill + * @param commandClass the command handler for the skill + * @param isChild whether the skill is a child + * @param runescapeColor the runescape color for the skill + * @param skillUseType what the skill use type of the skill is (COMBAT, GATHERING, MISC) + * @param ability the AbilityType attached to this skill + * @param secondaryAbilities the list of secondary abilities the skill can use + * @return the mcmmo skill created + */ public static SkillType createSkill(String name, Class managerClass, Class commandClass, boolean isChild, Color runescapeColor, SkillUseType skillUseType, AbilityType ability, SecondaryAbility... secondaryAbilities) { return createSkill(name, managerClass, commandClass, isChild, runescapeColor, skillUseType, ability, ImmutableList.copyOf(secondaryAbilities)); } + /** + * Gets the skill manager for the skill from the specified player + * @param skill the skill the skill manager is for + * @param player who's skill manager it is + * @return a skill manager for the skill owned by the player + */ public static SkillManager getSkillManager(SkillType skill, Player player) { return UserManager.getPlayer(player).getSkillManager(skill); } + /** + * Gets the skill manager cast to SkillAbilityManager + * @param skill the skill the skill manager is for + * @param player who's skill manager it is + * @return a skill ability manager for the skill owned by the player + */ public static SkillAbilityManager getSkillAbilityManager(SkillType skill, Player player) { SkillManager skillManager = getSkillManager(skill, player); if(skillManager instanceof SkillAbilityManager) { @@ -147,6 +233,20 @@ public final class SkillAPI { return null; } + /** + * Registers parents for the child + * @param childSkill the child to add parents for + * @param parentSkills the parents to add + */ + public static void registerParents(SkillType childSkill, SkillType... parentSkills) { + if(ChildConfig.getInstance() != null) { + ChildConfig.getInstance().addParents(childSkill, parentSkills); + } + } + + /** + * Loads the new skills added + */ public static void loadNewSkills() { SkillType.setUpSkillTypes(); } diff --git a/src/main/java/com/gmail/nossr50/locale/LocaleLoader.java b/src/main/java/com/gmail/nossr50/locale/LocaleLoader.java index f65875b81..6c0c65665 100644 --- a/src/main/java/com/gmail/nossr50/locale/LocaleLoader.java +++ b/src/main/java/com/gmail/nossr50/locale/LocaleLoader.java @@ -38,20 +38,32 @@ public final class LocaleLoader { } for(ResourceBundle customBundle : bundles) { - if(customBundle.containsKey(key)) { - return getString(key, customBundle, messageArguments); + try { + if(customBundle.containsKey(key)) { + return getString(key, customBundle, messageArguments); + } } + catch(Exception e) {} } if(bundle.containsKey(key)) { - return getString(key, bundle, messageArguments); + try { + return getString(key, bundle, messageArguments); + } + catch(Exception e) {} } for(ResourceBundle defaultCustomBundle : defaultBundles) { - if(defaultCustomBundle.containsKey(key)) { - return getString(key, defaultCustomBundle, messageArguments); - } + try { + if(defaultCustomBundle.containsKey(key)) { + return getString(key, defaultCustomBundle, messageArguments); + } + } + catch(Exception e) {} } if(enBundle.containsKey(key)) { - return getString(key, enBundle, messageArguments); + try { + return getString(key, enBundle, messageArguments); + } + catch(Exception e) {} } if (!key.contains("Guides")) { mcMMO.p.getLogger().warning("Could not find locale string: " + key); diff --git a/src/main/java/com/gmail/nossr50/skills/child/ChildConfig.java b/src/main/java/com/gmail/nossr50/skills/child/ChildConfig.java index 77fdaa25c..bd397b4b8 100644 --- a/src/main/java/com/gmail/nossr50/skills/child/ChildConfig.java +++ b/src/main/java/com/gmail/nossr50/skills/child/ChildConfig.java @@ -10,9 +10,12 @@ import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.util.StringUtils; public class ChildConfig extends AutoUpdateConfigLoader { + private static ChildConfig INSTANCE = null; + public ChildConfig() { super("child.yml"); loadKeys(); + INSTANCE = this; } @Override @@ -42,13 +45,16 @@ public class ChildConfig extends AutoUpdateConfigLoader { if (useDefaults) { parentSkills.clear(); - for (String name : config.getDefaults().getStringList(StringUtils.getCapitalized(skill.getName()))) { - /* 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.getSkill(name)); + try { + for (String name : config.getDefaults().getStringList(StringUtils.getCapitalized(skill.getName()))) { + /* 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.getSkill(name)); + } } + catch(Exception e) {} } // Register them @@ -60,4 +66,19 @@ public class ChildConfig extends AutoUpdateConfigLoader { FamilyTree.closeRegistration(); } + + public void addParents(SkillType childSkill, SkillType... parents) { + if(!config.contains(StringUtils.getCapitalized(childSkill.getName()))) { + String[] parentStrings = new String[parents.length]; + for(int i = 0; i < parents.length; i++) { + parentStrings[i] = StringUtils.getCapitalized(parents[i].getName()); + } + config.set(StringUtils.getCapitalized(childSkill.getName()), parentStrings); + loadKeys(); + } + } + + public static ChildConfig getInstance() { + return INSTANCE; + } }