2013-03-01 06:52:01 +01:00
|
|
|
package com.gmail.nossr50.api;
|
|
|
|
|
2013-03-17 15:34:46 +01:00
|
|
|
import java.util.Set;
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2013-04-11 02:21:55 +02:00
|
|
|
import com.gmail.nossr50.api.exceptions.InvalidPlayerException;
|
|
|
|
import com.gmail.nossr50.api.exceptions.InvalidSkillException;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.config.Config;
|
2013-03-17 15:34:46 +01:00
|
|
|
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.datatypes.skills.SkillType;
|
2013-03-17 15:34:46 +01:00
|
|
|
import com.gmail.nossr50.skills.child.FamilyTree;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.util.player.UserManager;
|
|
|
|
|
|
|
|
public final class ExperienceAPI {
|
|
|
|
private ExperienceAPI() {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds raw XP to the player.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param player The player to add XP to
|
|
|
|
* @param skillType The skill to add XP to
|
|
|
|
* @param XP The amount of XP to add
|
2013-04-10 02:52:58 +02:00
|
|
|
*
|
|
|
|
* @throws InvalidSkillException if the given skill is not valid
|
2013-03-01 06:52:01 +01:00
|
|
|
*/
|
2013-04-10 03:09:25 +02:00
|
|
|
public static void addRawXP(Player player, String skillType, int XP) {
|
2013-04-10 02:52:58 +02:00
|
|
|
SkillType skill = SkillType.getSkill(skillType);
|
|
|
|
|
|
|
|
if (skill == null) {
|
|
|
|
throw new InvalidSkillException();
|
|
|
|
}
|
|
|
|
|
|
|
|
UserManager.getPlayer(player).applyXpGain(skill, XP);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
2013-03-17 15:34:46 +01:00
|
|
|
/**
|
|
|
|
* Adds raw XP to an offline player.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param playerName The player to add XP to
|
|
|
|
* @param skillType The skill to add XP to
|
|
|
|
* @param XP The amount of XP to add
|
|
|
|
*
|
2013-04-10 02:52:58 +02:00
|
|
|
* @throws InvalidSkillException if the given skill is not valid
|
2013-03-17 15:34:46 +01:00
|
|
|
* @throws InvalidPlayerException if the given player does not exist in the database
|
|
|
|
*/
|
2013-04-10 03:09:25 +02:00
|
|
|
public static void addRawXPOffline(String playerName, String skillType, int XP) {
|
2013-04-10 02:52:58 +02:00
|
|
|
SkillType skill = SkillType.getSkill(skillType);
|
|
|
|
|
|
|
|
if (skill == null) {
|
|
|
|
throw new InvalidSkillException();
|
|
|
|
}
|
|
|
|
|
|
|
|
addOfflineXP(playerName, skill, XP);
|
2013-03-17 15:34:46 +01:00
|
|
|
}
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
/**
|
|
|
|
* Adds XP to the player, calculates for XP Rate only.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param player The player to add XP to
|
|
|
|
* @param skillType The skill to add XP to
|
|
|
|
* @param XP The amount of XP to add
|
2013-04-10 02:52:58 +02:00
|
|
|
*
|
|
|
|
* @throws InvalidSkillException if the given skill is not valid
|
2013-03-01 06:52:01 +01:00
|
|
|
*/
|
2013-04-10 03:09:25 +02:00
|
|
|
public static void addMultipliedXP(Player player, String skillType, int XP) {
|
2013-04-10 02:52:58 +02:00
|
|
|
SkillType skill = SkillType.getSkill(skillType);
|
|
|
|
|
|
|
|
if (skill == null) {
|
|
|
|
throw new InvalidSkillException();
|
|
|
|
}
|
|
|
|
|
|
|
|
UserManager.getPlayer(player).applyXpGain(skill, (int) (XP * Config.getInstance().getExperienceGainsGlobalMultiplier()));
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
2013-03-17 15:34:46 +01:00
|
|
|
/**
|
|
|
|
* Adds XP to an offline player, calculates for XP Rate only.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param playerName The player to add XP to
|
|
|
|
* @param skillType The skill to add XP to
|
|
|
|
* @param XP The amount of XP to add
|
|
|
|
*
|
2013-04-10 02:52:58 +02:00
|
|
|
* @throws InvalidSkillException if the given skill is not valid
|
2013-03-17 15:34:46 +01:00
|
|
|
* @throws InvalidPlayerException if the given player does not exist in the database
|
|
|
|
*/
|
2013-04-10 03:09:25 +02:00
|
|
|
public static void addMultipliedXPOffline(String playerName, String skillType, int XP) {
|
2013-04-10 02:52:58 +02:00
|
|
|
SkillType skill = SkillType.getSkill(skillType);
|
|
|
|
|
|
|
|
if (skill == null) {
|
|
|
|
throw new InvalidSkillException();
|
|
|
|
}
|
|
|
|
|
|
|
|
addOfflineXP(playerName, skill, (int) (XP * Config.getInstance().getExperienceGainsGlobalMultiplier()));
|
2013-03-17 15:34:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds XP to the player, calculates for XP Rate and skill modifier.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param player The player to add XP to
|
|
|
|
* @param skillType The skill to add XP to
|
|
|
|
* @param XP The amount of XP to add
|
2013-04-10 02:52:58 +02:00
|
|
|
*
|
|
|
|
* @throws InvalidSkillException if the given skill is not valid
|
2013-03-17 15:34:46 +01:00
|
|
|
*/
|
2013-04-10 03:09:25 +02:00
|
|
|
public static void addModifiedXP(Player player, String skillType, int XP) {
|
2013-03-17 15:34:46 +01:00
|
|
|
SkillType skill = SkillType.getSkill(skillType);
|
|
|
|
|
2013-04-10 02:52:58 +02:00
|
|
|
if (skill == null) {
|
|
|
|
throw new InvalidSkillException();
|
|
|
|
}
|
|
|
|
|
2013-03-17 15:34:46 +01:00
|
|
|
UserManager.getPlayer(player).applyXpGain(skill, (int) (XP / skill.getXpModifier() * Config.getInstance().getExperienceGainsGlobalMultiplier()));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds XP to an offline player, calculates for XP Rate and skill modifier.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param playerName The player to add XP to
|
|
|
|
* @param skillType The skill to add XP to
|
|
|
|
* @param XP The amount of XP to add
|
|
|
|
*
|
2013-04-10 02:52:58 +02:00
|
|
|
* @throws InvalidSkillException if the given skill is not valid
|
2013-03-17 15:34:46 +01:00
|
|
|
* @throws InvalidPlayerException if the given player does not exist in the database
|
|
|
|
*/
|
2013-04-10 03:09:25 +02:00
|
|
|
public static void addModifiedXPOffline(String playerName, String skillType, int XP) {
|
2013-04-10 02:52:58 +02:00
|
|
|
SkillType skill = SkillType.getSkill(skillType);
|
|
|
|
|
|
|
|
if (skill == null) {
|
|
|
|
throw new InvalidSkillException();
|
|
|
|
}
|
|
|
|
|
|
|
|
addOfflineXP(playerName, skill, (int) (XP / skill.getXpModifier() * Config.getInstance().getExperienceGainsGlobalMultiplier()));
|
2013-03-17 15:34:46 +01:00
|
|
|
}
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
/**
|
|
|
|
* Adds XP to the player, calculates for XP Rate, skill modifiers and perks. May be shared with the party.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param player The player to add XP to
|
|
|
|
* @param skillType The skill to add XP to
|
|
|
|
* @param XP The amount of XP to add
|
2013-04-10 02:52:58 +02:00
|
|
|
*
|
|
|
|
* @throws InvalidSkillException if the given skill is not valid
|
2013-03-01 06:52:01 +01:00
|
|
|
*/
|
2013-04-10 03:09:25 +02:00
|
|
|
public static void addXP(Player player, String skillType, int XP) {
|
2013-04-10 02:52:58 +02:00
|
|
|
SkillType skill = SkillType.getSkill(skillType);
|
|
|
|
|
|
|
|
if (skill == null) {
|
|
|
|
throw new InvalidSkillException();
|
|
|
|
}
|
|
|
|
|
|
|
|
UserManager.getPlayer(player).beginXpGain(skill, XP);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the amount of XP a player has in a specific skill.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param player The player to get XP for
|
|
|
|
* @param skillType The skill to get XP for
|
|
|
|
* @return the amount of XP in a given skill
|
2013-04-10 02:52:58 +02:00
|
|
|
*
|
|
|
|
* @throws InvalidSkillException if the given skill is not valid
|
2013-03-01 06:52:01 +01:00
|
|
|
*/
|
2013-04-10 03:09:25 +02:00
|
|
|
public static int getXP(Player player, String skillType) {
|
2013-04-10 02:52:58 +02:00
|
|
|
SkillType skill = SkillType.getSkill(skillType);
|
|
|
|
|
|
|
|
if (skill == null) {
|
|
|
|
throw new InvalidSkillException();
|
|
|
|
}
|
|
|
|
|
|
|
|
return UserManager.getPlayer(player).getProfile().getSkillXpLevel(skill);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
2013-03-17 15:34:46 +01:00
|
|
|
/**
|
|
|
|
* Get the amount of XP an offline player has in a specific skill.
|
|
|
|
* </br>
|
|
|
|
* 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
|
2013-04-10 02:52:58 +02:00
|
|
|
*
|
|
|
|
* @throws InvalidSkillException if the given skill is not valid
|
2013-03-17 15:34:46 +01:00
|
|
|
* @throws InvalidPlayerException if the given player does not exist in the database
|
|
|
|
*/
|
2013-04-10 03:09:25 +02:00
|
|
|
public static int getOfflineXP(String playerName, String skillType) {
|
2013-04-10 02:52:58 +02:00
|
|
|
SkillType skill = SkillType.getSkill(skillType);
|
|
|
|
|
|
|
|
if (skill == null) {
|
|
|
|
throw new InvalidSkillException();
|
|
|
|
}
|
|
|
|
|
|
|
|
return getOfflineProfile(playerName).getSkillXpLevel(skill);
|
2013-03-17 15:34:46 +01:00
|
|
|
}
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
/**
|
|
|
|
* Get the amount of XP left before leveling up.
|
|
|
|
* </br>
|
|
|
|
* 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
|
2013-04-10 02:52:58 +02:00
|
|
|
*
|
|
|
|
* @throws InvalidSkillException if the given skill is not valid
|
2013-03-01 06:52:01 +01:00
|
|
|
*/
|
2013-04-10 03:09:25 +02:00
|
|
|
public static int getXPToNextLevel(Player player, String skillType) {
|
2013-04-10 02:52:58 +02:00
|
|
|
SkillType skill = SkillType.getSkill(skillType);
|
|
|
|
|
|
|
|
if (skill == null) {
|
|
|
|
throw new InvalidSkillException();
|
|
|
|
}
|
|
|
|
|
|
|
|
return UserManager.getPlayer(player).getProfile().getXpToLevel(skill);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
2013-03-17 15:34:46 +01:00
|
|
|
/**
|
|
|
|
* Get the amount of XP an offline player has left before leveling up.
|
|
|
|
* </br>
|
|
|
|
* 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
|
2013-04-10 02:52:58 +02:00
|
|
|
*
|
|
|
|
* @throws InvalidSkillException if the given skill is not valid
|
2013-03-17 15:34:46 +01:00
|
|
|
* @throws InvalidPlayerException if the given player does not exist in the database
|
|
|
|
*/
|
2013-04-10 03:09:25 +02:00
|
|
|
public static int getOfflineXPToNextLevel(String playerName, String skillType) {
|
2013-04-10 02:52:58 +02:00
|
|
|
SkillType skill = SkillType.getSkill(skillType);
|
|
|
|
|
|
|
|
if (skill == null) {
|
|
|
|
throw new InvalidSkillException();
|
|
|
|
}
|
|
|
|
|
|
|
|
return getOfflineProfile(playerName).getXpToLevel(skill);
|
2013-03-17 15:34:46 +01:00
|
|
|
}
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
/**
|
|
|
|
* Add levels to a skill.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param player The player to add levels to
|
|
|
|
* @param skillType Type of skill to add levels to
|
|
|
|
* @param levels Number of levels to add
|
2013-04-10 02:52:58 +02:00
|
|
|
*
|
|
|
|
* @throws InvalidSkillException if the given skill is not valid
|
2013-03-01 06:52:01 +01:00
|
|
|
*/
|
2013-04-10 03:09:25 +02:00
|
|
|
public static void addLevel(Player player, String skillType, int levels) {
|
2013-04-10 02:52:58 +02:00
|
|
|
SkillType skill = SkillType.getSkill(skillType);
|
|
|
|
|
|
|
|
if (skill == null) {
|
|
|
|
throw new InvalidSkillException();
|
|
|
|
}
|
|
|
|
|
|
|
|
UserManager.getPlayer(player).getProfile().addLevels(skill, levels);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
2013-03-17 15:34:46 +01:00
|
|
|
/**
|
|
|
|
* Add levels to a skill for an offline player.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param playerName The player to add levels to
|
|
|
|
* @param skillType Type of skill to add levels to
|
|
|
|
* @param levels Number of levels to add
|
|
|
|
*
|
2013-04-10 02:52:58 +02:00
|
|
|
* @throws InvalidSkillException if the given skill is not valid
|
2013-03-17 15:34:46 +01:00
|
|
|
* @throws InvalidPlayerException if the given player does not exist in the database
|
|
|
|
*/
|
2013-04-10 03:09:25 +02:00
|
|
|
public static void addLevelOffline(String playerName, String skillType, int levels) {
|
2013-03-17 15:34:46 +01:00
|
|
|
PlayerProfile profile = getOfflineProfile(playerName);
|
|
|
|
SkillType skill = SkillType.getSkill(skillType);
|
|
|
|
|
2013-04-10 02:52:58 +02:00
|
|
|
if (skill == null) {
|
|
|
|
throw new InvalidSkillException();
|
|
|
|
}
|
|
|
|
|
2013-03-17 15:34:46 +01:00
|
|
|
if (skill.isChildSkill()) {
|
|
|
|
Set<SkillType> parentSkills = FamilyTree.getParents(skill);
|
|
|
|
|
|
|
|
for (SkillType parentSkill : parentSkills) {
|
|
|
|
profile.addLevels(parentSkill, (levels / parentSkills.size()));
|
|
|
|
}
|
|
|
|
|
|
|
|
profile.save();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
profile.addLevels(skill, levels);
|
|
|
|
profile.save();
|
|
|
|
}
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
/**
|
|
|
|
* Get the level a player has in a specific skill.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param player The player to get the level for
|
|
|
|
* @param skillType The skill to get the level for
|
|
|
|
* @return the level of a given skill
|
2013-04-10 02:52:58 +02:00
|
|
|
*
|
|
|
|
* @throws InvalidSkillException if the given skill is not valid
|
2013-03-01 06:52:01 +01:00
|
|
|
*/
|
2013-04-10 03:09:25 +02:00
|
|
|
public static int getLevel(Player player, String skillType) {
|
2013-04-10 02:52:58 +02:00
|
|
|
SkillType skill = SkillType.getSkill(skillType);
|
|
|
|
|
|
|
|
if (skill == null) {
|
|
|
|
throw new InvalidSkillException();
|
|
|
|
}
|
|
|
|
|
|
|
|
return UserManager.getPlayer(player).getProfile().getSkillLevel(skill);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
2013-03-17 15:34:46 +01:00
|
|
|
/**
|
|
|
|
* Get the level an offline player has in a specific skill.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param playerName The player to get the level for
|
|
|
|
* @param skillType The skill to get the level for
|
|
|
|
* @return the level of a given skill
|
2013-04-10 02:52:58 +02:00
|
|
|
*
|
|
|
|
* @throws InvalidSkillException if the given skill is not valid
|
2013-03-17 15:34:46 +01:00
|
|
|
* @throws InvalidPlayerException if the given player does not exist in the database
|
|
|
|
*/
|
2013-04-10 03:09:25 +02:00
|
|
|
public static int getLevelOffline(String playerName, String skillType) {
|
2013-04-10 02:52:58 +02:00
|
|
|
SkillType skill = SkillType.getSkill(skillType);
|
|
|
|
|
|
|
|
if (skill == null) {
|
|
|
|
throw new InvalidSkillException();
|
|
|
|
}
|
|
|
|
|
|
|
|
return getOfflineProfile(playerName).getSkillLevel(skill);
|
2013-03-17 15:34:46 +01:00
|
|
|
}
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
/**
|
|
|
|
* Gets the power level of a player.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param player The player to get the power level for
|
|
|
|
* @return the power level of the player
|
|
|
|
*/
|
|
|
|
public static int getPowerLevel(Player player) {
|
|
|
|
return UserManager.getPlayer(player).getPowerLevel();
|
|
|
|
}
|
|
|
|
|
2013-03-17 15:34:46 +01:00
|
|
|
/**
|
|
|
|
* Gets the power level of an offline player.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param playerName The player to get the power level for
|
|
|
|
* @return the power level of the player
|
2013-04-10 02:52:58 +02:00
|
|
|
*
|
2013-03-17 15:34:46 +01:00
|
|
|
* @throws InvalidPlayerException if the given player does not exist in the database
|
|
|
|
*/
|
|
|
|
public static int getPowerLevelOffline(String playerName) {
|
|
|
|
int powerLevel = 0;
|
|
|
|
PlayerProfile profile = getOfflineProfile(playerName);
|
|
|
|
|
|
|
|
for (SkillType type : SkillType.values()) {
|
|
|
|
if (type.isChildSkill()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
powerLevel += profile.getSkillLevel(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
return powerLevel;
|
|
|
|
}
|
|
|
|
|
2013-03-04 15:16:33 +01:00
|
|
|
/**
|
|
|
|
* Get the level cap of a specific skill.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param skillType The skill to get the level cap for
|
|
|
|
* @return the level cap of a given skill
|
2013-04-10 02:52:58 +02:00
|
|
|
*
|
|
|
|
* @throws InvalidSkillException if the given skill is not valid
|
2013-03-04 15:16:33 +01:00
|
|
|
*/
|
2013-04-10 03:09:25 +02:00
|
|
|
public static int getLevelCap(String skillType) {
|
2013-04-10 02:52:58 +02:00
|
|
|
SkillType skill = SkillType.getSkill(skillType);
|
|
|
|
|
|
|
|
if (skill == null) {
|
|
|
|
throw new InvalidSkillException();
|
|
|
|
}
|
|
|
|
|
|
|
|
return Config.getInstance().getLevelCap(skill);
|
2013-03-04 15:16:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the power level cap.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
2013-04-10 02:52:58 +02:00
|
|
|
* @return the overall power level cap
|
2013-03-04 15:16:33 +01:00
|
|
|
*/
|
|
|
|
public static int getPowerLevelCap() {
|
|
|
|
return Config.getInstance().getPowerLevelCap();
|
|
|
|
}
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
/**
|
|
|
|
* Sets the level of a player in a specific skill type.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param player The player to set the level of
|
|
|
|
* @param skillType The skill to set the level for
|
|
|
|
* @param skillLevel The value to set the level to
|
2013-04-10 02:52:58 +02:00
|
|
|
*
|
|
|
|
* @throws InvalidSkillException if the given skill is not valid
|
2013-03-01 06:52:01 +01:00
|
|
|
*/
|
2013-04-10 03:09:25 +02:00
|
|
|
public static void setLevel(Player player, String skillType, int skillLevel) {
|
2013-04-10 02:52:58 +02:00
|
|
|
SkillType skill = SkillType.getSkill(skillType);
|
|
|
|
|
|
|
|
if (skill == null) {
|
|
|
|
throw new InvalidSkillException();
|
|
|
|
}
|
|
|
|
|
|
|
|
UserManager.getPlayer(player).getProfile().modifySkill(skill, skillLevel);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
2013-03-17 15:34:46 +01:00
|
|
|
/**
|
|
|
|
* Sets the level of an offline player in a specific skill type.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param playerName The player to set the level of
|
|
|
|
* @param skillType The skill to set the level for
|
|
|
|
* @param skillLevel The value to set the level to
|
|
|
|
*
|
2013-04-10 02:52:58 +02:00
|
|
|
* @throws InvalidSkillException if the given skill is not valid
|
2013-03-17 15:34:46 +01:00
|
|
|
* @throws InvalidPlayerException if the given player does not exist in the database
|
|
|
|
*/
|
2013-04-10 03:09:25 +02:00
|
|
|
public static void setLevelOffline(String playerName, String skillType, int skillLevel) {
|
2013-04-10 02:52:58 +02:00
|
|
|
SkillType skill = SkillType.getSkill(skillType);
|
|
|
|
|
|
|
|
if (skill == null) {
|
|
|
|
throw new InvalidSkillException();
|
|
|
|
}
|
|
|
|
|
|
|
|
getOfflineProfile(playerName).modifySkill(skill, skillLevel);
|
2013-03-17 15:34:46 +01:00
|
|
|
}
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
/**
|
|
|
|
* Sets the XP of a player in a specific skill type.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param player The player to set the XP of
|
|
|
|
* @param skillType The skill to set the XP for
|
|
|
|
* @param newValue The value to set the XP to
|
2013-04-10 02:52:58 +02:00
|
|
|
*
|
|
|
|
* @throws InvalidSkillException if the given skill is not valid
|
2013-03-01 06:52:01 +01:00
|
|
|
*/
|
2013-04-10 03:09:25 +02:00
|
|
|
public static void setXP(Player player, String skillType, int newValue) {
|
2013-04-10 02:52:58 +02:00
|
|
|
SkillType skill = SkillType.getSkill(skillType);
|
|
|
|
|
|
|
|
if (skill == null) {
|
|
|
|
throw new InvalidSkillException();
|
|
|
|
}
|
|
|
|
|
|
|
|
UserManager.getPlayer(player).getProfile().setSkillXpLevel(skill, newValue);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
2013-03-17 15:34:46 +01:00
|
|
|
/**
|
|
|
|
* Sets the XP of an offline player in a specific skill type.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param playerName The player to set the XP of
|
|
|
|
* @param skillType The skill to set the XP for
|
|
|
|
* @param newValue The value to set the XP to
|
|
|
|
*
|
2013-04-10 02:52:58 +02:00
|
|
|
* @throws InvalidSkillException if the given skill is not valid
|
2013-03-17 15:34:46 +01:00
|
|
|
* @throws InvalidPlayerException if the given player does not exist in the database
|
|
|
|
*/
|
2013-04-10 03:09:25 +02:00
|
|
|
public static void setXPOffline(String playerName, String skillType, int newValue) {
|
2013-04-10 02:52:58 +02:00
|
|
|
SkillType skill = SkillType.getSkill(skillType);
|
|
|
|
|
|
|
|
if (skill == null) {
|
|
|
|
throw new InvalidSkillException();
|
|
|
|
}
|
|
|
|
|
|
|
|
getOfflineProfile(playerName).setSkillXpLevel(skill, newValue);
|
2013-03-17 15:34:46 +01:00
|
|
|
}
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
/**
|
|
|
|
* Removes XP from a player in a specific skill type.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param player The player to change the XP of
|
|
|
|
* @param skillType The skill to change the XP for
|
|
|
|
* @param xp The amount of XP to remove
|
2013-04-10 02:52:58 +02:00
|
|
|
*
|
|
|
|
* @throws InvalidSkillException if the given skill is not valid
|
2013-03-01 06:52:01 +01:00
|
|
|
*/
|
2013-04-10 03:09:25 +02:00
|
|
|
public static void removeXP(Player player, String skillType, int xp) {
|
2013-04-10 02:52:58 +02:00
|
|
|
SkillType skill = SkillType.getSkill(skillType);
|
|
|
|
|
|
|
|
if (skill == null) {
|
|
|
|
throw new InvalidSkillException();
|
|
|
|
}
|
|
|
|
|
|
|
|
UserManager.getPlayer(player).getProfile().removeXp(skill, xp);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
2013-03-17 15:34:46 +01:00
|
|
|
/**
|
|
|
|
* Removes XP from an offline player in a specific skill type.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param playerName The player to change the XP of
|
|
|
|
* @param skillType The skill to change the XP for
|
|
|
|
* @param xp The amount of XP to remove
|
|
|
|
*
|
2013-04-10 02:52:58 +02:00
|
|
|
* @throws InvalidSkillException if the given skill is not valid
|
2013-03-17 15:34:46 +01:00
|
|
|
* @throws InvalidPlayerException if the given player does not exist in the database
|
|
|
|
*/
|
2013-04-10 03:09:25 +02:00
|
|
|
public static void removeXPOffline(String playerName, String skillType, int xp) {
|
2013-04-10 02:52:58 +02:00
|
|
|
SkillType skill = SkillType.getSkill(skillType);
|
|
|
|
|
|
|
|
if (skill == null) {
|
|
|
|
throw new InvalidSkillException();
|
|
|
|
}
|
|
|
|
|
|
|
|
getOfflineProfile(playerName).removeXp(skill, xp);
|
2013-03-17 15:34:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add XP to an offline player.
|
|
|
|
*
|
|
|
|
* @param playerName The player to check
|
|
|
|
* @param skillType The skill to check
|
|
|
|
* @param XP The amount of XP to award.
|
|
|
|
*/
|
2013-04-10 02:52:58 +02:00
|
|
|
private static void addOfflineXP(String playerName, SkillType skill, int XP) {
|
2013-03-17 15:34:46 +01:00
|
|
|
PlayerProfile profile = getOfflineProfile(playerName);
|
|
|
|
|
|
|
|
if (skill.isChildSkill()) {
|
|
|
|
Set<SkillType> parentSkills = FamilyTree.getParents(skill);
|
|
|
|
|
|
|
|
for (SkillType parentSkill : parentSkills) {
|
|
|
|
profile.setSkillXpLevel(parentSkill, profile.getSkillLevel(parentSkill) + (XP / parentSkills.size()));
|
|
|
|
}
|
|
|
|
|
|
|
|
profile.save();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
profile.setSkillXpLevel(skill, profile.getSkillXpLevel(skill) + XP);
|
|
|
|
profile.save();
|
|
|
|
}
|
|
|
|
|
|
|
|
private static PlayerProfile getOfflineProfile(String playerName) {
|
|
|
|
PlayerProfile profile = new PlayerProfile(playerName, false);
|
|
|
|
|
|
|
|
if (!profile.isLoaded()) {
|
|
|
|
throw new InvalidPlayerException();
|
|
|
|
}
|
|
|
|
|
|
|
|
return profile;
|
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|