diff --git a/src/main/java/com/gmail/nossr50/api/ExperienceAPI.java b/src/main/java/com/gmail/nossr50/api/ExperienceAPI.java index e9e508cd1..be3281d12 100644 --- a/src/main/java/com/gmail/nossr50/api/ExperienceAPI.java +++ b/src/main/java/com/gmail/nossr50/api/ExperienceAPI.java @@ -175,6 +175,7 @@ public final class ExperienceAPI { * @return the amount of XP in a given skill * * @throws InvalidSkillException if the given skill is not valid + * @throws UnsupportedOperationException if the given skill is a child skill */ public static int getXP(Player player, String skillType) { SkillType skill = SkillType.getSkill(skillType); @@ -183,6 +184,10 @@ public final class ExperienceAPI { throw new InvalidSkillException(); } + if (skill.isChildSkill()) { + throw new UnsupportedOperationException("Child skills do not have XP"); + } + return UserManager.getPlayer(player).getProfile().getSkillXpLevel(skill); } @@ -197,6 +202,7 @@ public final class ExperienceAPI { * * @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 getOfflineXP(String playerName, String skillType) { SkillType skill = SkillType.getSkill(skillType); @@ -205,6 +211,10 @@ public final class ExperienceAPI { throw new InvalidSkillException(); } + if (skill.isChildSkill()) { + throw new UnsupportedOperationException("Child skills do not have XP"); + } + return getOfflineProfile(playerName).getSkillXpLevel(skill); } @@ -218,6 +228,7 @@ public final class ExperienceAPI { * @return the amount of XP in a given skill * * @throws InvalidSkillException if the given skill is not valid + * @throws UnsupportedOperationException if the given skill is a child skill */ public static float getXPRaw(Player player, String skillType) { SkillType skill = SkillType.getSkill(skillType); @@ -226,6 +237,10 @@ public final class ExperienceAPI { throw new InvalidSkillException(); } + if (skill.isChildSkill()) { + throw new UnsupportedOperationException("Child skills do not have XP"); + } + return UserManager.getPlayer(player).getProfile().getSkillXpLevelRaw(skill); } @@ -240,6 +255,7 @@ public final class ExperienceAPI { * * @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 float getOfflineXPRaw(String playerName, String skillType) { SkillType skill = SkillType.getSkill(skillType); @@ -248,6 +264,10 @@ public final class ExperienceAPI { throw new InvalidSkillException(); } + if (skill.isChildSkill()) { + throw new UnsupportedOperationException("Child skills do not have XP"); + } + return getOfflineProfile(playerName).getSkillXpLevelRaw(skill); } @@ -261,6 +281,7 @@ public final class ExperienceAPI { * @return the amount of XP left before leveling up a specifc skill * * @throws InvalidSkillException if the given skill is not valid + * @throws UnsupportedOperationException if the given skill is a child skill */ public static int getXPToNextLevel(Player player, String skillType) { SkillType skill = SkillType.getSkill(skillType); @@ -269,6 +290,10 @@ public final class ExperienceAPI { throw new InvalidSkillException(); } + if (skill.isChildSkill()) { + throw new UnsupportedOperationException("Child skills do not have XP"); + } + return UserManager.getPlayer(player).getProfile().getXpToLevel(skill); } @@ -283,6 +308,7 @@ public final class ExperienceAPI { * * @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 getOfflineXPToNextLevel(String playerName, String skillType) { SkillType skill = SkillType.getSkill(skillType); @@ -291,6 +317,10 @@ public final class ExperienceAPI { throw new InvalidSkillException(); } + if (skill.isChildSkill()) { + throw new UnsupportedOperationException("Child skills do not have XP"); + } + return getOfflineProfile(playerName).getXpToLevel(skill); } @@ -514,6 +544,7 @@ public final class ExperienceAPI { * @param newValue The value to set the XP to * * @throws InvalidSkillException if the given skill is not valid + * @throws UnsupportedOperationException if the given skill is a child skill */ public static void setXP(Player player, String skillType, int newValue) { SkillType skill = SkillType.getSkill(skillType); @@ -522,6 +553,10 @@ public final class ExperienceAPI { throw new InvalidSkillException(); } + if (skill.isChildSkill()) { + throw new UnsupportedOperationException("Child skills do not have XP"); + } + UserManager.getPlayer(player).getProfile().setSkillXpLevel(skill, newValue); } @@ -536,6 +571,7 @@ public final class ExperienceAPI { * * @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 void setXPOffline(String playerName, String skillType, int newValue) { SkillType skill = SkillType.getSkill(skillType); @@ -544,6 +580,10 @@ public final class ExperienceAPI { throw new InvalidSkillException(); } + if (skill.isChildSkill()) { + throw new UnsupportedOperationException("Child skills do not have XP"); + } + getOfflineProfile(playerName).setSkillXpLevel(skill, newValue); } @@ -557,6 +597,7 @@ public final class ExperienceAPI { * @param xp The amount of XP to remove * * @throws InvalidSkillException if the given skill is not valid + * @throws UnsupportedOperationException if the given skill is a child skill */ public static void removeXP(Player player, String skillType, int xp) { SkillType skill = SkillType.getSkill(skillType); @@ -565,6 +606,10 @@ public final class ExperienceAPI { throw new InvalidSkillException(); } + if (skill.isChildSkill()) { + throw new UnsupportedOperationException("Child skills do not have XP"); + } + UserManager.getPlayer(player).getProfile().removeXp(skill, xp); } @@ -579,6 +624,7 @@ public final class ExperienceAPI { * * @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 void removeXPOffline(String playerName, String skillType, int xp) { SkillType skill = SkillType.getSkill(skillType); @@ -587,6 +633,10 @@ public final class ExperienceAPI { throw new InvalidSkillException(); } + if (skill.isChildSkill()) { + throw new UnsupportedOperationException("Child skills do not have XP"); + } + getOfflineProfile(playerName).removeXp(skill, xp); }