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,55 +104,136 @@ public final class AbilityAPI {
return BleedTimerTask.isBleeding(entity); 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) { public static AbilityType createAbility(String name, String skillName, final Material... materials) {
return createAbility(name, skillName, 240, 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) { public static AbilityType createAbility(String name, String skillName) {
return createAbility(name, skillName, 240); 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) { public static AbilityType createAbility(String name, String skillName, int cooldown, final Material... materials) {
AbilityType ability = AbilityType.createAbility(name, skillName, materials); AbilityType ability = AbilityType.createAbility(name, skillName, materials);
Config.getInstance().createAbility(ability, cooldown); Config.getInstance().createAbility(ability, cooldown);
return ability; 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) { public static AbilityType createAbility(String name, String skillName, int cooldown) {
AbilityType ability = AbilityType.createAbility(name, skillName); AbilityType ability = AbilityType.createAbility(name, skillName);
Config.getInstance().createAbility(ability, cooldown); Config.getInstance().createAbility(ability, cooldown);
return ability; 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) { public static SecondaryAbility createSecondaryAbility(String name, String skillName) {
return createSecondaryAbility(name, skillName, 0, 100); 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) { public static SecondaryAbility createSecondaryAbility(String name, String skillName, int maxBonusLevel, double maxChance) {
SecondaryAbility ability = new SecondaryAbility(name); SecondaryAbility ability = new SecondaryAbility(name);
AdvancedConfig.getInstance().createNewSkill(ability, skillName, maxBonusLevel, maxChance); AdvancedConfig.getInstance().createNewSkill(ability, skillName, maxBonusLevel, maxChance);
return ability; 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) { public static boolean hasSecondaryAbilityPermissions(Player player, SecondaryAbility ability) {
return Permissions.secondaryAbilityEnabled(player, 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) { public static void activateSkillAbility(SkillType skill, Player player, BlockState blockState) {
SkillAbilityManager abilityManager = SkillAPI.getSkillAbilityManager(skill, player); SkillAbilityManager abilityManager = SkillAPI.getSkillAbilityManager(skill, player);
if(abilityManager != null) { if(abilityManager != null) {
abilityManager.doAbilityPreparationCheck(blockState); 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) { public static void activateSkillAbility(SkillType skill, Player player) {
SkillAbilityManager abilityManager = SkillAPI.getSkillAbilityManager(skill, player); SkillAbilityManager abilityManager = SkillAPI.getSkillAbilityManager(skill, player);
if(abilityManager != null) { if(abilityManager != null) {
abilityManager.doAbilityPreparationCheck(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; package com.gmail.nossr50.api;
import java.util.Locale;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
public final class LocaleAPI { 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) { public static void addBundles(ResourceBundle bundle, ResourceBundle defaultBundle) {
LocaleLoader.addResourceBundle(bundle, 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) { public static void addBundle(ResourceBundle bundle, boolean isDefault) {
if(isDefault) { if(isDefault) {
addBundles(null, bundle); addBundles(null, bundle);
@ -18,5 +29,13 @@ public final class LocaleAPI {
addBundles(bundle, null); addBundles(bundle, null);
} }
} }
/**
* 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.datatypes.skills.ToolType;
import com.gmail.nossr50.skills.SkillAbilityManager; import com.gmail.nossr50.skills.SkillAbilityManager;
import com.gmail.nossr50.skills.SkillManager; 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.StringUtils;
import com.gmail.nossr50.util.commands.CommandRegistrationManager; import com.gmail.nossr50.util.commands.CommandRegistrationManager;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
@ -105,40 +107,124 @@ public final class SkillAPI {
return skills; 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) { 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); SkillType skill = SkillType.createSkill(name, managerClass, commandClass, isChild, runescapeColor, skillUseType, secondaryAbilities);
CommandRegistrationManager.registerSkillCommandAndPassSkillToConstructor(skill); CommandRegistrationManager.registerSkillCommandAndPassSkillToConstructor(skill);
return 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) { 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); SkillType skill = SkillType.createSkill(name, managerClass, commandClass, isChild, runescapeColor, skillUseType, ability, ToolType.createToolType(StringUtils.getCapitalized(name), materials), secondaryAbilities);
CommandRegistrationManager.registerSkillCommandAndPassSkillToConstructor(skill); CommandRegistrationManager.registerSkillCommandAndPassSkillToConstructor(skill);
return 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) { 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); SkillType skill = SkillType.createSkill(name, managerClass, commandClass, isChild, runescapeColor, skillUseType, ability, ToolType.createToolType(StringUtils.getCapitalized(name)), secondaryAbilities);
CommandRegistrationManager.registerSkillCommandAndPassSkillToConstructor(skill); CommandRegistrationManager.registerSkillCommandAndPassSkillToConstructor(skill);
return 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) { 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)); 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) { 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)); 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) { 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)); 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) { public static SkillManager getSkillManager(SkillType skill, Player player) {
return UserManager.getPlayer(player).getSkillManager(skill); 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) { public static SkillAbilityManager getSkillAbilityManager(SkillType skill, Player player) {
SkillManager skillManager = getSkillManager(skill, player); SkillManager skillManager = getSkillManager(skill, player);
if(skillManager instanceof SkillAbilityManager) { if(skillManager instanceof SkillAbilityManager) {
@ -147,6 +233,20 @@ public final class SkillAPI {
return null; 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() { public static void loadNewSkills() {
SkillType.setUpSkillTypes(); SkillType.setUpSkillTypes();
} }

View File

@ -38,20 +38,32 @@ public final class LocaleLoader {
} }
for(ResourceBundle customBundle : bundles) { for(ResourceBundle customBundle : bundles) {
if(customBundle.containsKey(key)) { try {
return getString(key, customBundle, messageArguments); if(customBundle.containsKey(key)) {
return getString(key, customBundle, messageArguments);
}
} }
catch(Exception e) {}
} }
if(bundle.containsKey(key)) { if(bundle.containsKey(key)) {
return getString(key, bundle, messageArguments); try {
return getString(key, bundle, messageArguments);
}
catch(Exception e) {}
} }
for(ResourceBundle defaultCustomBundle : defaultBundles) { for(ResourceBundle defaultCustomBundle : defaultBundles) {
if(defaultCustomBundle.containsKey(key)) { try {
return getString(key, defaultCustomBundle, messageArguments); if(defaultCustomBundle.containsKey(key)) {
} return getString(key, defaultCustomBundle, messageArguments);
}
}
catch(Exception e) {}
} }
if(enBundle.containsKey(key)) { if(enBundle.containsKey(key)) {
return getString(key, enBundle, messageArguments); try {
return getString(key, enBundle, messageArguments);
}
catch(Exception e) {}
} }
if (!key.contains("Guides")) { if (!key.contains("Guides")) {
mcMMO.p.getLogger().warning("Could not find locale string: " + key); 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; import com.gmail.nossr50.util.StringUtils;
public class ChildConfig extends AutoUpdateConfigLoader { public class ChildConfig extends AutoUpdateConfigLoader {
private static ChildConfig INSTANCE = null;
public ChildConfig() { public ChildConfig() {
super("child.yml"); super("child.yml");
loadKeys(); loadKeys();
INSTANCE = this;
} }
@Override @Override
@ -42,13 +45,16 @@ public class ChildConfig extends AutoUpdateConfigLoader {
if (useDefaults) { if (useDefaults) {
parentSkills.clear(); parentSkills.clear();
for (String name : config.getDefaults().getStringList(StringUtils.getCapitalized(skill.getName()))) { try {
/* We do less checks in here because it's from inside our jar. for (String name : config.getDefaults().getStringList(StringUtils.getCapitalized(skill.getName()))) {
* If they're dedicated enough to have modified it, they can have the errors it may produce. /* We do less checks in here because it's from inside our jar.
* 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. * 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)); */
parentSkills.add(SkillType.getSkill(name));
}
} }
catch(Exception e) {}
} }
// Register them // Register them
@ -60,4 +66,19 @@ public class ChildConfig extends AutoUpdateConfigLoader {
FamilyTree.closeRegistration(); 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;
}
} }