From 3dedb94bdc1d064a856fb99e69cbebc5799d1640 Mon Sep 17 00:00:00 2001 From: GJ Date: Tue, 14 May 2013 23:30:24 -0400 Subject: [PATCH] Add new Experience API functions and clarify some old ones. --- .../com/gmail/nossr50/api/ExperienceAPI.java | 65 +++++++++++++++++-- 1 file changed, 61 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/api/ExperienceAPI.java b/src/main/java/com/gmail/nossr50/api/ExperienceAPI.java index be3281d12..7e24ab66e 100644 --- a/src/main/java/com/gmail/nossr50/api/ExperienceAPI.java +++ b/src/main/java/com/gmail/nossr50/api/ExperienceAPI.java @@ -272,13 +272,13 @@ public final class ExperienceAPI { } /** - * Get the amount of XP left before leveling up. + * Get the total amount of XP needed to reach the next level. *
* This function is designed for API usage. * * @param player The player to get the XP amount for * @param skillType The skill to get the XP amount for - * @return the amount of XP left before leveling up a specifc skill + * @return the total amount of XP needed to reach the next level * * @throws InvalidSkillException if the given skill is not valid * @throws UnsupportedOperationException if the given skill is a child skill @@ -298,13 +298,13 @@ public final class ExperienceAPI { } /** - * Get the amount of XP an offline player has left before leveling up. + * Get the total amount of XP an offline player needs to reach the next level. *
* This function is designed for API usage. * * @param playerName The player to get XP for * @param skillType The skill to get XP for - * @return the amount of XP in a given skill + * @return the total amount of XP needed to reach the next level * * @throws InvalidSkillException if the given skill is not valid * @throws InvalidPlayerException if the given player does not exist in the database @@ -324,6 +324,63 @@ public final class ExperienceAPI { return getOfflineProfile(playerName).getXpToLevel(skill); } + /** + * Get the amount of XP remaining until the next level. + *
+ * This function is designed for API usage. + * + * @param player The player to get the XP amount for + * @param skillType The skill to get the XP amount for + * @return the amount of XP remaining until the next level + * + * @throws InvalidSkillException if the given skill is not valid + * @throws UnsupportedOperationException if the given skill is a child skill + */ + public static int getXPRemaining(Player player, String skillType) { + SkillType skill = SkillType.getSkill(skillType); + + if (skill == null) { + throw new InvalidSkillException(); + } + + if (skill.isChildSkill()) { + throw new UnsupportedOperationException("Child skills do not have XP"); + } + + PlayerProfile profile = UserManager.getPlayer(player).getProfile(); + + return profile.getXpToLevel(skill) - profile.getSkillXpLevel(skill); + } + + /** + * Get the amount of XP an offline player has left before leveling up. + *
+ * This function is designed for API usage. + * + * @param playerName The player to get XP for + * @param skillType The skill to get XP for + * @return the amount of XP needed to reach the next level + * + * @throws InvalidSkillException if the given skill is not valid + * @throws InvalidPlayerException if the given player does not exist in the database + * @throws UnsupportedOperationException if the given skill is a child skill + */ + public static int getOfflineXPRemaining(String playerName, String skillType) { + SkillType skill = SkillType.getSkill(skillType); + + if (skill == null) { + throw new InvalidSkillException(); + } + + if (skill.isChildSkill()) { + throw new UnsupportedOperationException("Child skills do not have XP"); + } + + PlayerProfile profile = getOfflineProfile(playerName); + + return profile.getXpToLevel(skill) - profile.getSkillXpLevel(skill); + } + /** * Add levels to a skill. *