Added javadocs and child skill support

This commit is contained in:
ile123ile 2014-09-01 20:02:16 -07:00
parent 952309ecda
commit 0dd779fa17
5 changed files with 258 additions and 25 deletions

View File

@ -104,44 +104,110 @@ 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) {
@ -149,10 +215,25 @@ public final class AbilityAPI {
}
}
/**
* 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);
}
}

View File

@ -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);
@ -19,4 +30,12 @@ public final class LocaleAPI {
}
}
/**
* Gets the current locale to create a resource bundle for
* @return the current locale
*/
public static Locale getCurrentLocale() {
return LocaleLoader.getCurrentLocale();
}
}

View File

@ -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<? extends SkillManager> managerClass, Class<? extends SkillCommand> commandClass, boolean isChild, Color runescapeColor, SkillUseType skillUseType, List<SecondaryAbility> 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<? extends SkillManager> managerClass, Class<? extends SkillCommand> commandClass, boolean isChild, Color runescapeColor, SkillUseType skillUseType, AbilityType ability, Material[] materials, List<SecondaryAbility> 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<? extends SkillManager> managerClass, Class<? extends SkillCommand> commandClass, boolean isChild, Color runescapeColor, SkillUseType skillUseType, AbilityType ability, List<SecondaryAbility> 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<? extends SkillManager> managerClass, Class<? extends SkillCommand> 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<? extends SkillManager> managerClass, Class<? extends SkillCommand> 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<? extends SkillManager> managerClass, Class<? extends SkillCommand> 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();
}

View File

@ -38,21 +38,33 @@ public final class LocaleLoader {
}
for(ResourceBundle customBundle : bundles) {
try {
if(customBundle.containsKey(key)) {
return getString(key, customBundle, messageArguments);
}
}
catch(Exception e) {}
}
if(bundle.containsKey(key)) {
try {
return getString(key, bundle, messageArguments);
}
catch(Exception e) {}
}
for(ResourceBundle defaultCustomBundle : defaultBundles) {
try {
if(defaultCustomBundle.containsKey(key)) {
return getString(key, defaultCustomBundle, messageArguments);
}
}
catch(Exception e) {}
}
if(enBundle.containsKey(key)) {
try {
return getString(key, enBundle, messageArguments);
}
catch(Exception e) {}
}
if (!key.contains("Guides")) {
mcMMO.p.getLogger().warning("Could not find locale string: " + key);
}

View File

@ -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,6 +45,7 @@ public class ChildConfig extends AutoUpdateConfigLoader {
if (useDefaults) {
parentSkills.clear();
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.
@ -50,6 +54,8 @@ public class ChildConfig extends AutoUpdateConfigLoader {
parentSkills.add(SkillType.getSkill(name));
}
}
catch(Exception e) {}
}
// Register them
for (SkillType parentSkill : parentSkills) {
@ -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;
}
}