mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 13:16:45 +01:00
ExperienceAPI methods will now throw InvalidSkillException if the skill
name passed in is invalid
This commit is contained in:
parent
78d2fa7520
commit
7525de1a72
@ -16,6 +16,7 @@ Version 1.4.06-dev
|
|||||||
= Fixed bug where /party chat was not working
|
= Fixed bug where /party chat was not working
|
||||||
! Changed Chimaera Wing's recipe result to use the ingredient Material
|
! Changed Chimaera Wing's recipe result to use the ingredient Material
|
||||||
! Players will no longer pickup items to their hotbar while using Unarmed
|
! Players will no longer pickup items to their hotbar while using Unarmed
|
||||||
|
! ExperienceAPI methods will now throw InvalidSkillException if the skill name passed in is invalid.
|
||||||
|
|
||||||
Version 1.4.05
|
Version 1.4.05
|
||||||
+ Added option to allow refreshing of chunks after block-breaking abilities. (Disabled by default)
|
+ Added option to allow refreshing of chunks after block-breaking abilities. (Disabled by default)
|
||||||
|
@ -21,9 +21,17 @@ public final class ExperienceAPI {
|
|||||||
* @param player The player to add XP to
|
* @param player The player to add XP to
|
||||||
* @param skillType The skill to add XP to
|
* @param skillType The skill to add XP to
|
||||||
* @param XP The amount of XP to add
|
* @param XP The amount of XP to add
|
||||||
|
*
|
||||||
|
* @throws InvalidSkillException if the given skill is not valid
|
||||||
*/
|
*/
|
||||||
public static void addRawXP(Player player, String skillType, int XP) {
|
public static void addRawXP(Player player, String skillType, int XP) throws InvalidSkillException {
|
||||||
UserManager.getPlayer(player).applyXpGain(SkillType.getSkill(skillType), XP);
|
SkillType skill = SkillType.getSkill(skillType);
|
||||||
|
|
||||||
|
if (skill == null) {
|
||||||
|
throw new InvalidSkillException();
|
||||||
|
}
|
||||||
|
|
||||||
|
UserManager.getPlayer(player).applyXpGain(skill, XP);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -35,10 +43,17 @@ public final class ExperienceAPI {
|
|||||||
* @param skillType The skill to add XP to
|
* @param skillType The skill to add XP to
|
||||||
* @param XP The amount of XP to add
|
* @param XP The amount of XP to add
|
||||||
*
|
*
|
||||||
|
* @throws InvalidSkillException if the given skill is not valid
|
||||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||||
*/
|
*/
|
||||||
public static void addRawXPOffline(String playerName, String skillType, int XP) {
|
public static void addRawXPOffline(String playerName, String skillType, int XP) throws InvalidSkillException {
|
||||||
addOfflineXP(playerName, skillType, XP);
|
SkillType skill = SkillType.getSkill(skillType);
|
||||||
|
|
||||||
|
if (skill == null) {
|
||||||
|
throw new InvalidSkillException();
|
||||||
|
}
|
||||||
|
|
||||||
|
addOfflineXP(playerName, skill, XP);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -49,9 +64,17 @@ public final class ExperienceAPI {
|
|||||||
* @param player The player to add XP to
|
* @param player The player to add XP to
|
||||||
* @param skillType The skill to add XP to
|
* @param skillType The skill to add XP to
|
||||||
* @param XP The amount of XP to add
|
* @param XP The amount of XP to add
|
||||||
|
*
|
||||||
|
* @throws InvalidSkillException if the given skill is not valid
|
||||||
*/
|
*/
|
||||||
public static void addMultipliedXP(Player player, String skillType, int XP) {
|
public static void addMultipliedXP(Player player, String skillType, int XP) throws InvalidSkillException {
|
||||||
UserManager.getPlayer(player).applyXpGain(SkillType.getSkill(skillType), (int) (XP * Config.getInstance().getExperienceGainsGlobalMultiplier()));
|
SkillType skill = SkillType.getSkill(skillType);
|
||||||
|
|
||||||
|
if (skill == null) {
|
||||||
|
throw new InvalidSkillException();
|
||||||
|
}
|
||||||
|
|
||||||
|
UserManager.getPlayer(player).applyXpGain(skill, (int) (XP * Config.getInstance().getExperienceGainsGlobalMultiplier()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -63,10 +86,17 @@ public final class ExperienceAPI {
|
|||||||
* @param skillType The skill to add XP to
|
* @param skillType The skill to add XP to
|
||||||
* @param XP The amount of XP to add
|
* @param XP The amount of XP to add
|
||||||
*
|
*
|
||||||
|
* @throws InvalidSkillException if the given skill is not valid
|
||||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||||
*/
|
*/
|
||||||
public static void addMultipliedXPOffline(String playerName, String skillType, int XP) {
|
public static void addMultipliedXPOffline(String playerName, String skillType, int XP) throws InvalidSkillException {
|
||||||
addOfflineXP(playerName, skillType, (int) (XP * Config.getInstance().getExperienceGainsGlobalMultiplier()));
|
SkillType skill = SkillType.getSkill(skillType);
|
||||||
|
|
||||||
|
if (skill == null) {
|
||||||
|
throw new InvalidSkillException();
|
||||||
|
}
|
||||||
|
|
||||||
|
addOfflineXP(playerName, skill, (int) (XP * Config.getInstance().getExperienceGainsGlobalMultiplier()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -77,10 +107,16 @@ public final class ExperienceAPI {
|
|||||||
* @param player The player to add XP to
|
* @param player The player to add XP to
|
||||||
* @param skillType The skill to add XP to
|
* @param skillType The skill to add XP to
|
||||||
* @param XP The amount of XP to add
|
* @param XP The amount of XP to add
|
||||||
|
*
|
||||||
|
* @throws InvalidSkillException if the given skill is not valid
|
||||||
*/
|
*/
|
||||||
public static void addModifiedXP(Player player, String skillType, int XP) {
|
public static void addModifiedXP(Player player, String skillType, int XP) throws InvalidSkillException {
|
||||||
SkillType skill = SkillType.getSkill(skillType);
|
SkillType skill = SkillType.getSkill(skillType);
|
||||||
|
|
||||||
|
if (skill == null) {
|
||||||
|
throw new InvalidSkillException();
|
||||||
|
}
|
||||||
|
|
||||||
UserManager.getPlayer(player).applyXpGain(skill, (int) (XP / skill.getXpModifier() * Config.getInstance().getExperienceGainsGlobalMultiplier()));
|
UserManager.getPlayer(player).applyXpGain(skill, (int) (XP / skill.getXpModifier() * Config.getInstance().getExperienceGainsGlobalMultiplier()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,10 +129,17 @@ public final class ExperienceAPI {
|
|||||||
* @param skillType The skill to add XP to
|
* @param skillType The skill to add XP to
|
||||||
* @param XP The amount of XP to add
|
* @param XP The amount of XP to add
|
||||||
*
|
*
|
||||||
|
* @throws InvalidSkillException if the given skill is not valid
|
||||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||||
*/
|
*/
|
||||||
public static void addModifiedXPOffline(String playerName, String skillType, int XP) {
|
public static void addModifiedXPOffline(String playerName, String skillType, int XP) throws InvalidSkillException {
|
||||||
addOfflineXP(playerName, skillType, (int) (XP / SkillType.getSkill(skillType).getXpModifier() * Config.getInstance().getExperienceGainsGlobalMultiplier()));
|
SkillType skill = SkillType.getSkill(skillType);
|
||||||
|
|
||||||
|
if (skill == null) {
|
||||||
|
throw new InvalidSkillException();
|
||||||
|
}
|
||||||
|
|
||||||
|
addOfflineXP(playerName, skill, (int) (XP / skill.getXpModifier() * Config.getInstance().getExperienceGainsGlobalMultiplier()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -107,9 +150,17 @@ public final class ExperienceAPI {
|
|||||||
* @param player The player to add XP to
|
* @param player The player to add XP to
|
||||||
* @param skillType The skill to add XP to
|
* @param skillType The skill to add XP to
|
||||||
* @param XP The amount of XP to add
|
* @param XP The amount of XP to add
|
||||||
|
*
|
||||||
|
* @throws InvalidSkillException if the given skill is not valid
|
||||||
*/
|
*/
|
||||||
public static void addXP(Player player, String skillType, int XP) {
|
public static void addXP(Player player, String skillType, int XP) throws InvalidSkillException {
|
||||||
UserManager.getPlayer(player).beginXpGain(SkillType.getSkill(skillType), XP);
|
SkillType skill = SkillType.getSkill(skillType);
|
||||||
|
|
||||||
|
if (skill == null) {
|
||||||
|
throw new InvalidSkillException();
|
||||||
|
}
|
||||||
|
|
||||||
|
UserManager.getPlayer(player).beginXpGain(skill, XP);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -120,9 +171,17 @@ public final class ExperienceAPI {
|
|||||||
* @param player The player to get XP for
|
* @param player The player to get XP for
|
||||||
* @param skillType The skill to get XP for
|
* @param skillType The skill to get XP for
|
||||||
* @return the amount of XP in a given skill
|
* @return the amount of XP in a given skill
|
||||||
|
*
|
||||||
|
* @throws InvalidSkillException if the given skill is not valid
|
||||||
*/
|
*/
|
||||||
public static int getXP(Player player, String skillType) {
|
public static int getXP(Player player, String skillType) throws InvalidSkillException {
|
||||||
return UserManager.getPlayer(player).getProfile().getSkillXpLevel(SkillType.getSkill(skillType));
|
SkillType skill = SkillType.getSkill(skillType);
|
||||||
|
|
||||||
|
if (skill == null) {
|
||||||
|
throw new InvalidSkillException();
|
||||||
|
}
|
||||||
|
|
||||||
|
return UserManager.getPlayer(player).getProfile().getSkillXpLevel(skill);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -133,10 +192,18 @@ public final class ExperienceAPI {
|
|||||||
* @param playerName The player to get XP for
|
* @param playerName The player to get XP for
|
||||||
* @param skillType The skill to get XP for
|
* @param skillType The skill to get XP for
|
||||||
* @return the amount of XP in a given skill
|
* @return the amount of XP in a given skill
|
||||||
|
*
|
||||||
|
* @throws InvalidSkillException if the given skill is not valid
|
||||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||||
*/
|
*/
|
||||||
public static int getOfflineXP(String playerName, String skillType) {
|
public static int getOfflineXP(String playerName, String skillType) throws InvalidSkillException {
|
||||||
return getOfflineProfile(playerName).getSkillXpLevel(SkillType.getSkill(skillType));
|
SkillType skill = SkillType.getSkill(skillType);
|
||||||
|
|
||||||
|
if (skill == null) {
|
||||||
|
throw new InvalidSkillException();
|
||||||
|
}
|
||||||
|
|
||||||
|
return getOfflineProfile(playerName).getSkillXpLevel(skill);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -147,9 +214,17 @@ public final class ExperienceAPI {
|
|||||||
* @param player The player to get the XP amount for
|
* @param player The player to get the XP amount for
|
||||||
* @param skillType The skill 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 amount of XP left before leveling up a specifc skill
|
||||||
|
*
|
||||||
|
* @throws InvalidSkillException if the given skill is not valid
|
||||||
*/
|
*/
|
||||||
public static int getXPToNextLevel(Player player, String skillType) {
|
public static int getXPToNextLevel(Player player, String skillType) throws InvalidSkillException {
|
||||||
return UserManager.getPlayer(player).getProfile().getXpToLevel(SkillType.getSkill(skillType));
|
SkillType skill = SkillType.getSkill(skillType);
|
||||||
|
|
||||||
|
if (skill == null) {
|
||||||
|
throw new InvalidSkillException();
|
||||||
|
}
|
||||||
|
|
||||||
|
return UserManager.getPlayer(player).getProfile().getXpToLevel(skill);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -160,10 +235,18 @@ public final class ExperienceAPI {
|
|||||||
* @param playerName The player to get XP for
|
* @param playerName The player to get XP for
|
||||||
* @param skillType The skill to get XP for
|
* @param skillType The skill to get XP for
|
||||||
* @return the amount of XP in a given skill
|
* @return the amount of XP in a given skill
|
||||||
|
*
|
||||||
|
* @throws InvalidSkillException if the given skill is not valid
|
||||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||||
*/
|
*/
|
||||||
public static int getOfflineXPToNextLevel(String playerName, String skillType) {
|
public static int getOfflineXPToNextLevel(String playerName, String skillType) throws InvalidSkillException {
|
||||||
return getOfflineProfile(playerName).getXpToLevel(SkillType.getSkill(skillType));
|
SkillType skill = SkillType.getSkill(skillType);
|
||||||
|
|
||||||
|
if (skill == null) {
|
||||||
|
throw new InvalidSkillException();
|
||||||
|
}
|
||||||
|
|
||||||
|
return getOfflineProfile(playerName).getXpToLevel(skill);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -174,9 +257,17 @@ public final class ExperienceAPI {
|
|||||||
* @param player The player to add levels to
|
* @param player The player to add levels to
|
||||||
* @param skillType Type of skill to add levels to
|
* @param skillType Type of skill to add levels to
|
||||||
* @param levels Number of levels to add
|
* @param levels Number of levels to add
|
||||||
|
*
|
||||||
|
* @throws InvalidSkillException if the given skill is not valid
|
||||||
*/
|
*/
|
||||||
public static void addLevel(Player player, String skillType, int levels) {
|
public static void addLevel(Player player, String skillType, int levels) throws InvalidSkillException {
|
||||||
UserManager.getPlayer(player).getProfile().addLevels(SkillType.getSkill(skillType), levels);
|
SkillType skill = SkillType.getSkill(skillType);
|
||||||
|
|
||||||
|
if (skill == null) {
|
||||||
|
throw new InvalidSkillException();
|
||||||
|
}
|
||||||
|
|
||||||
|
UserManager.getPlayer(player).getProfile().addLevels(skill, levels);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -188,13 +279,17 @@ public final class ExperienceAPI {
|
|||||||
* @param skillType Type of skill to add levels to
|
* @param skillType Type of skill to add levels to
|
||||||
* @param levels Number of levels to add
|
* @param levels Number of levels to add
|
||||||
*
|
*
|
||||||
|
* @throws InvalidSkillException if the given skill is not valid
|
||||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||||
*/
|
*/
|
||||||
public static void addLevelOffline(String playerName, String skillType, int levels) {
|
public static void addLevelOffline(String playerName, String skillType, int levels) throws InvalidSkillException {
|
||||||
PlayerProfile profile = getOfflineProfile(playerName);
|
PlayerProfile profile = getOfflineProfile(playerName);
|
||||||
|
|
||||||
SkillType skill = SkillType.getSkill(skillType);
|
SkillType skill = SkillType.getSkill(skillType);
|
||||||
|
|
||||||
|
if (skill == null) {
|
||||||
|
throw new InvalidSkillException();
|
||||||
|
}
|
||||||
|
|
||||||
if (skill.isChildSkill()) {
|
if (skill.isChildSkill()) {
|
||||||
Set<SkillType> parentSkills = FamilyTree.getParents(skill);
|
Set<SkillType> parentSkills = FamilyTree.getParents(skill);
|
||||||
|
|
||||||
@ -218,9 +313,17 @@ public final class ExperienceAPI {
|
|||||||
* @param player The player to get the level for
|
* @param player The player to get the level for
|
||||||
* @param skillType The skill to get the level for
|
* @param skillType The skill to get the level for
|
||||||
* @return the level of a given skill
|
* @return the level of a given skill
|
||||||
|
*
|
||||||
|
* @throws InvalidSkillException if the given skill is not valid
|
||||||
*/
|
*/
|
||||||
public static int getLevel(Player player, String skillType) {
|
public static int getLevel(Player player, String skillType) throws InvalidSkillException {
|
||||||
return UserManager.getPlayer(player).getProfile().getSkillLevel(SkillType.getSkill(skillType));
|
SkillType skill = SkillType.getSkill(skillType);
|
||||||
|
|
||||||
|
if (skill == null) {
|
||||||
|
throw new InvalidSkillException();
|
||||||
|
}
|
||||||
|
|
||||||
|
return UserManager.getPlayer(player).getProfile().getSkillLevel(skill);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -231,10 +334,18 @@ public final class ExperienceAPI {
|
|||||||
* @param playerName The player to get the level for
|
* @param playerName The player to get the level for
|
||||||
* @param skillType The skill to get the level for
|
* @param skillType The skill to get the level for
|
||||||
* @return the level of a given skill
|
* @return the level of a given skill
|
||||||
|
*
|
||||||
|
* @throws InvalidSkillException if the given skill is not valid
|
||||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||||
*/
|
*/
|
||||||
public static int getLevelOffline(String playerName, String skillType) {
|
public static int getLevelOffline(String playerName, String skillType) throws InvalidSkillException {
|
||||||
return getOfflineProfile(playerName).getSkillLevel(SkillType.getSkill(skillType));
|
SkillType skill = SkillType.getSkill(skillType);
|
||||||
|
|
||||||
|
if (skill == null) {
|
||||||
|
throw new InvalidSkillException();
|
||||||
|
}
|
||||||
|
|
||||||
|
return getOfflineProfile(playerName).getSkillLevel(skill);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -256,6 +367,7 @@ public final class ExperienceAPI {
|
|||||||
*
|
*
|
||||||
* @param playerName The player to get the power level for
|
* @param playerName The player to get the power level for
|
||||||
* @return the power level of the player
|
* @return the power level of the player
|
||||||
|
*
|
||||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||||
*/
|
*/
|
||||||
public static int getPowerLevelOffline(String playerName) {
|
public static int getPowerLevelOffline(String playerName) {
|
||||||
@ -280,9 +392,17 @@ public final class ExperienceAPI {
|
|||||||
*
|
*
|
||||||
* @param skillType The skill to get the level cap for
|
* @param skillType The skill to get the level cap for
|
||||||
* @return the level cap of a given skill
|
* @return the level cap of a given skill
|
||||||
|
*
|
||||||
|
* @throws InvalidSkillException if the given skill is not valid
|
||||||
*/
|
*/
|
||||||
public static int getLevelCap(String skillType) {
|
public static int getLevelCap(String skillType) throws InvalidSkillException {
|
||||||
return Config.getInstance().getLevelCap(SkillType.getSkill(skillType));
|
SkillType skill = SkillType.getSkill(skillType);
|
||||||
|
|
||||||
|
if (skill == null) {
|
||||||
|
throw new InvalidSkillException();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Config.getInstance().getLevelCap(skill);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -290,7 +410,7 @@ public final class ExperienceAPI {
|
|||||||
* </br>
|
* </br>
|
||||||
* This function is designed for API usage.
|
* This function is designed for API usage.
|
||||||
*
|
*
|
||||||
* @return the power level cap of a given skill
|
* @return the overall power level cap
|
||||||
*/
|
*/
|
||||||
public static int getPowerLevelCap() {
|
public static int getPowerLevelCap() {
|
||||||
return Config.getInstance().getPowerLevelCap();
|
return Config.getInstance().getPowerLevelCap();
|
||||||
@ -304,9 +424,17 @@ public final class ExperienceAPI {
|
|||||||
* @param player The player to set the level of
|
* @param player The player to set the level of
|
||||||
* @param skillType The skill to set the level for
|
* @param skillType The skill to set the level for
|
||||||
* @param skillLevel The value to set the level to
|
* @param skillLevel The value to set the level to
|
||||||
|
*
|
||||||
|
* @throws InvalidSkillException if the given skill is not valid
|
||||||
*/
|
*/
|
||||||
public static void setLevel(Player player, String skillType, int skillLevel) {
|
public static void setLevel(Player player, String skillType, int skillLevel) throws InvalidSkillException {
|
||||||
UserManager.getPlayer(player).getProfile().modifySkill(SkillType.getSkill(skillType), skillLevel);
|
SkillType skill = SkillType.getSkill(skillType);
|
||||||
|
|
||||||
|
if (skill == null) {
|
||||||
|
throw new InvalidSkillException();
|
||||||
|
}
|
||||||
|
|
||||||
|
UserManager.getPlayer(player).getProfile().modifySkill(skill, skillLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -318,10 +446,17 @@ public final class ExperienceAPI {
|
|||||||
* @param skillType The skill to set the level for
|
* @param skillType The skill to set the level for
|
||||||
* @param skillLevel The value to set the level to
|
* @param skillLevel The value to set the level to
|
||||||
*
|
*
|
||||||
|
* @throws InvalidSkillException if the given skill is not valid
|
||||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||||
*/
|
*/
|
||||||
public static void setLevelOffline(String playerName, String skillType, int skillLevel) {
|
public static void setLevelOffline(String playerName, String skillType, int skillLevel) throws InvalidSkillException {
|
||||||
getOfflineProfile(playerName).modifySkill(SkillType.getSkill(skillType), skillLevel);
|
SkillType skill = SkillType.getSkill(skillType);
|
||||||
|
|
||||||
|
if (skill == null) {
|
||||||
|
throw new InvalidSkillException();
|
||||||
|
}
|
||||||
|
|
||||||
|
getOfflineProfile(playerName).modifySkill(skill, skillLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -332,9 +467,17 @@ public final class ExperienceAPI {
|
|||||||
* @param player The player to set the XP of
|
* @param player The player to set the XP of
|
||||||
* @param skillType The skill to set the XP for
|
* @param skillType The skill to set the XP for
|
||||||
* @param newValue The value to set the XP to
|
* @param newValue The value to set the XP to
|
||||||
|
*
|
||||||
|
* @throws InvalidSkillException if the given skill is not valid
|
||||||
*/
|
*/
|
||||||
public static void setXP(Player player, String skillType, int newValue) {
|
public static void setXP(Player player, String skillType, int newValue) throws InvalidSkillException {
|
||||||
UserManager.getPlayer(player).getProfile().setSkillXpLevel(SkillType.getSkill(skillType), newValue);
|
SkillType skill = SkillType.getSkill(skillType);
|
||||||
|
|
||||||
|
if (skill == null) {
|
||||||
|
throw new InvalidSkillException();
|
||||||
|
}
|
||||||
|
|
||||||
|
UserManager.getPlayer(player).getProfile().setSkillXpLevel(skill, newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -346,10 +489,17 @@ public final class ExperienceAPI {
|
|||||||
* @param skillType The skill to set the XP for
|
* @param skillType The skill to set the XP for
|
||||||
* @param newValue The value to set the XP to
|
* @param newValue The value to set the XP to
|
||||||
*
|
*
|
||||||
|
* @throws InvalidSkillException if the given skill is not valid
|
||||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||||
*/
|
*/
|
||||||
public static void setXPOffline(String playerName, String skillType, int newValue) {
|
public static void setXPOffline(String playerName, String skillType, int newValue) throws InvalidSkillException {
|
||||||
getOfflineProfile(playerName).setSkillXpLevel(SkillType.getSkill(skillType), newValue);
|
SkillType skill = SkillType.getSkill(skillType);
|
||||||
|
|
||||||
|
if (skill == null) {
|
||||||
|
throw new InvalidSkillException();
|
||||||
|
}
|
||||||
|
|
||||||
|
getOfflineProfile(playerName).setSkillXpLevel(skill, newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -360,9 +510,17 @@ public final class ExperienceAPI {
|
|||||||
* @param player The player to change the XP of
|
* @param player The player to change the XP of
|
||||||
* @param skillType The skill to change the XP for
|
* @param skillType The skill to change the XP for
|
||||||
* @param xp The amount of XP to remove
|
* @param xp The amount of XP to remove
|
||||||
|
*
|
||||||
|
* @throws InvalidSkillException if the given skill is not valid
|
||||||
*/
|
*/
|
||||||
public static void removeXP(Player player, String skillType, int xp) {
|
public static void removeXP(Player player, String skillType, int xp) throws InvalidSkillException {
|
||||||
UserManager.getPlayer(player).getProfile().removeXp(SkillType.getSkill(skillType), xp);
|
SkillType skill = SkillType.getSkill(skillType);
|
||||||
|
|
||||||
|
if (skill == null) {
|
||||||
|
throw new InvalidSkillException();
|
||||||
|
}
|
||||||
|
|
||||||
|
UserManager.getPlayer(player).getProfile().removeXp(skill, xp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -374,10 +532,17 @@ public final class ExperienceAPI {
|
|||||||
* @param skillType The skill to change the XP for
|
* @param skillType The skill to change the XP for
|
||||||
* @param xp The amount of XP to remove
|
* @param xp The amount of XP to remove
|
||||||
*
|
*
|
||||||
|
* @throws InvalidSkillException if the given skill is not valid
|
||||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||||
*/
|
*/
|
||||||
public static void removeXPOffline(String playerName, String skillType, int xp) {
|
public static void removeXPOffline(String playerName, String skillType, int xp) throws InvalidSkillException {
|
||||||
getOfflineProfile(playerName).removeXp(SkillType.getSkill(skillType), xp);
|
SkillType skill = SkillType.getSkill(skillType);
|
||||||
|
|
||||||
|
if (skill == null) {
|
||||||
|
throw new InvalidSkillException();
|
||||||
|
}
|
||||||
|
|
||||||
|
getOfflineProfile(playerName).removeXp(skill, xp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -387,11 +552,9 @@ public final class ExperienceAPI {
|
|||||||
* @param skillType The skill to check
|
* @param skillType The skill to check
|
||||||
* @param XP The amount of XP to award.
|
* @param XP The amount of XP to award.
|
||||||
*/
|
*/
|
||||||
private static void addOfflineXP(String playerName, String skillType, int XP) {
|
private static void addOfflineXP(String playerName, SkillType skill, int XP) {
|
||||||
PlayerProfile profile = getOfflineProfile(playerName);
|
PlayerProfile profile = getOfflineProfile(playerName);
|
||||||
|
|
||||||
SkillType skill = SkillType.getSkill(skillType);
|
|
||||||
|
|
||||||
if (skill.isChildSkill()) {
|
if (skill.isChildSkill()) {
|
||||||
Set<SkillType> parentSkills = FamilyTree.getParents(skill);
|
Set<SkillType> parentSkills = FamilyTree.getParents(skill);
|
||||||
|
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.gmail.nossr50.api;
|
||||||
|
|
||||||
|
public class InvalidSkillException extends Exception {
|
||||||
|
private static final long serialVersionUID = 942705284195791157L;
|
||||||
|
|
||||||
|
public InvalidSkillException() {
|
||||||
|
super("That is not a valid skill.");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user