2013-03-01 06:52:01 +01:00
|
|
|
package com.gmail.nossr50.api;
|
|
|
|
|
2019-01-15 07:11:58 +01:00
|
|
|
import com.gmail.nossr50.api.exceptions.*;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.config.Config;
|
2013-08-23 10:16:22 +02:00
|
|
|
import com.gmail.nossr50.config.experience.ExperienceConfig;
|
2014-08-22 22:27:05 +02:00
|
|
|
import com.gmail.nossr50.datatypes.experience.FormulaType;
|
2019-01-28 03:11:51 +01:00
|
|
|
import com.gmail.nossr50.datatypes.experience.XPGainReason;
|
|
|
|
import com.gmail.nossr50.datatypes.experience.XPGainSource;
|
2014-08-22 22:27:05 +02:00
|
|
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
2013-03-17 15:34:46 +01:00
|
|
|
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
2019-01-15 07:11:58 +01:00
|
|
|
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
|
|
|
import com.gmail.nossr50.mcMMO;
|
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;
|
2019-02-02 00:23:45 +01:00
|
|
|
import org.bukkit.block.BlockState;
|
2019-01-15 07:11:58 +01:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2019-02-02 00:23:45 +01:00
|
|
|
import java.util.ArrayList;
|
2019-01-15 07:11:58 +01:00
|
|
|
import java.util.Set;
|
|
|
|
import java.util.UUID;
|
2013-03-01 06:52:01 +01:00
|
|
|
|
|
|
|
public final class ExperienceAPI {
|
|
|
|
private ExperienceAPI() {}
|
|
|
|
|
2013-05-30 19:18:13 +02:00
|
|
|
/**
|
|
|
|
* Returns whether given string is a valid type of skill suitable for the
|
|
|
|
* other API calls in this class.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param skillType A string that may or may not be a skill
|
|
|
|
* @return true if this is a valid mcMMO skill
|
|
|
|
*/
|
|
|
|
public static boolean isValidSkillType(String skillType) {
|
2019-01-13 08:54:53 +01:00
|
|
|
return PrimarySkillType.getSkill(skillType) != null;
|
2013-05-30 19:18:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether the given skill type string is both valid and not a
|
|
|
|
* child skill. (Child skills have no XP of their own, and their level is
|
|
|
|
* derived from the parent(s).)
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param skillType the skill to check
|
|
|
|
* @return true if this is a valid, non-child mcMMO skill
|
|
|
|
*/
|
|
|
|
public static boolean isNonChildSkill(String skillType) {
|
2019-01-13 08:54:53 +01:00
|
|
|
PrimarySkillType skill = PrimarySkillType.getSkill(skillType);
|
2013-05-30 19:18:13 +02:00
|
|
|
|
2014-02-27 16:56:21 +01:00
|
|
|
return skill != null && !skill.isChildSkill();
|
2013-05-30 19:18:13 +02:00
|
|
|
}
|
|
|
|
|
2013-09-30 19:03:44 +02:00
|
|
|
@Deprecated
|
|
|
|
public static void addRawXP(Player player, String skillType, int XP) {
|
2013-09-30 19:38:22 +02:00
|
|
|
addRawXP(player, skillType, (float) XP);
|
2013-09-30 19:03:44 +02:00
|
|
|
}
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
*/
|
2014-04-18 21:56:03 +02:00
|
|
|
@Deprecated
|
2013-09-29 15:48:11 +02:00
|
|
|
public static void addRawXP(Player player, String skillType, float XP) {
|
2014-04-18 21:56:03 +02:00
|
|
|
addRawXP(player, skillType, XP, "UNKNOWN");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
* @param xpGainReason The reason to gain XP
|
|
|
|
*
|
|
|
|
* @throws InvalidSkillException if the given skill is not valid
|
|
|
|
* @throws InvalidXPGainReasonException if the given xpGainReason is not valid
|
|
|
|
*/
|
|
|
|
public static void addRawXP(Player player, String skillType, float XP, String xpGainReason) {
|
2014-08-22 20:49:16 +02:00
|
|
|
addRawXP(player, skillType, XP, xpGainReason, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
* @param xpGainReason The reason to gain XP
|
|
|
|
* @param isUnshared true if the XP cannot be shared with party members
|
|
|
|
*
|
|
|
|
* @throws InvalidSkillException if the given skill is not valid
|
|
|
|
* @throws InvalidXPGainReasonException if the given xpGainReason is not valid
|
|
|
|
*/
|
|
|
|
public static void addRawXP(Player player, String skillType, float XP, String xpGainReason, boolean isUnshared) {
|
|
|
|
if (isUnshared) {
|
2019-01-28 03:11:51 +01:00
|
|
|
getPlayer(player).beginUnsharedXpGain(getSkillType(skillType), XP, getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
|
2014-08-22 20:49:16 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-28 03:11:51 +01:00
|
|
|
getPlayer(player).applyXpGain(getSkillType(skillType), XP, getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
2014-08-01 20:17:15 +02:00
|
|
|
/**
|
|
|
|
* Adds raw XP to an offline player.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @deprecated We're using float for our XP values now
|
|
|
|
* replaced by {@link #addRawXPOffline(String playerName, String skillType, float XP)}
|
|
|
|
*/
|
2013-09-30 19:03:44 +02:00
|
|
|
@Deprecated
|
|
|
|
public static void addRawXPOffline(String playerName, String skillType, int XP) {
|
2013-09-30 19:38:22 +02:00
|
|
|
addRawXPOffline(playerName, skillType, (float) XP);
|
2013-09-30 19:03:44 +02:00
|
|
|
}
|
|
|
|
|
2013-03-17 15:34:46 +01:00
|
|
|
/**
|
|
|
|
* Adds raw XP to an offline player.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
2014-08-01 20:17:15 +02:00
|
|
|
* @deprecated We're using uuids to get an offline player
|
|
|
|
* replaced by {@link #addRawXPOffline(UUID uuid, String skillType, float XP)}
|
|
|
|
*
|
2013-03-17 15:34:46 +01:00
|
|
|
* @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
|
|
|
|
*/
|
2014-08-01 20:17:15 +02:00
|
|
|
@Deprecated
|
2013-09-29 15:48:11 +02:00
|
|
|
public static void addRawXPOffline(String playerName, String skillType, float XP) {
|
|
|
|
addOfflineXP(playerName, getSkillType(skillType), (int) Math.floor(XP));
|
2013-03-17 15:34:46 +01:00
|
|
|
}
|
|
|
|
|
2014-08-01 20:17:15 +02:00
|
|
|
/**
|
|
|
|
* Adds raw XP to an offline player.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param uuid The UUID of player to add XP to
|
|
|
|
* @param skillType The skill to add XP to
|
|
|
|
* @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
|
|
|
|
*/
|
|
|
|
public static void addRawXPOffline(UUID uuid, String skillType, float XP) {
|
|
|
|
addOfflineXP(uuid, getSkillType(skillType), (int) Math.floor(XP));
|
|
|
|
}
|
|
|
|
|
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
|
|
|
*/
|
2014-04-18 21:56:03 +02:00
|
|
|
@Deprecated
|
2013-04-10 03:09:25 +02:00
|
|
|
public static void addMultipliedXP(Player player, String skillType, int XP) {
|
2014-04-18 21:56:03 +02:00
|
|
|
addMultipliedXP(player, skillType, XP, "UNKNOWN");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
* @param xpGainReason The reason to gain XP
|
|
|
|
*
|
|
|
|
* @throws InvalidSkillException if the given skill is not valid
|
|
|
|
* @throws InvalidXPGainReasonException if the given xpGainReason is not valid
|
|
|
|
*/
|
|
|
|
public static void addMultipliedXP(Player player, String skillType, int XP, String xpGainReason) {
|
2019-01-28 03:11:51 +01:00
|
|
|
getPlayer(player).applyXpGain(getSkillType(skillType), (int) (XP * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()), getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
|
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
|
|
|
|
*/
|
2014-08-01 20:17:15 +02:00
|
|
|
@Deprecated
|
2013-04-10 03:09:25 +02:00
|
|
|
public static void addMultipliedXPOffline(String playerName, String skillType, int XP) {
|
2013-08-23 10:16:22 +02:00
|
|
|
addOfflineXP(playerName, getSkillType(skillType), (int) (XP * ExperienceConfig.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
|
|
|
*/
|
2014-04-18 21:56:03 +02:00
|
|
|
@Deprecated
|
2013-04-10 03:09:25 +02:00
|
|
|
public static void addModifiedXP(Player player, String skillType, int XP) {
|
2014-04-18 21:56:03 +02:00
|
|
|
addModifiedXP(player, skillType, XP, "UNKNOWN");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
* @param xpGainReason The reason to gain XP
|
|
|
|
*
|
|
|
|
* @throws InvalidSkillException if the given skill is not valid
|
|
|
|
* @throws InvalidXPGainReasonException if the given xpGainReason is not valid
|
|
|
|
*/
|
|
|
|
public static void addModifiedXP(Player player, String skillType, int XP, String xpGainReason) {
|
2014-08-22 20:49:16 +02:00
|
|
|
addModifiedXP(player, skillType, XP, xpGainReason, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
* @param xpGainReason The reason to gain XP
|
|
|
|
* @param isUnshared true if the XP cannot be shared with party members
|
|
|
|
*
|
|
|
|
* @throws InvalidSkillException if the given skill is not valid
|
|
|
|
* @throws InvalidXPGainReasonException if the given xpGainReason is not valid
|
|
|
|
*/
|
|
|
|
public static void addModifiedXP(Player player, String skillType, int XP, String xpGainReason, boolean isUnshared) {
|
2019-01-13 08:54:53 +01:00
|
|
|
PrimarySkillType skill = getSkillType(skillType);
|
2013-04-10 02:52:58 +02:00
|
|
|
|
2014-08-22 20:49:16 +02:00
|
|
|
if (isUnshared) {
|
2019-01-28 03:11:51 +01:00
|
|
|
getPlayer(player).beginUnsharedXpGain(skill, (int) (XP / skill.getXpModifier() * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()), getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
|
2014-08-22 20:49:16 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-28 03:11:51 +01:00
|
|
|
getPlayer(player).applyXpGain(skill, (int) (XP / skill.getXpModifier() * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()), getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
|
2013-03-17 15:34:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2014-08-01 20:17:15 +02:00
|
|
|
@Deprecated
|
2013-04-10 03:09:25 +02:00
|
|
|
public static void addModifiedXPOffline(String playerName, String skillType, int XP) {
|
2019-01-13 08:54:53 +01:00
|
|
|
PrimarySkillType skill = getSkillType(skillType);
|
2013-04-10 02:52:58 +02:00
|
|
|
|
2013-08-23 10:16:22 +02:00
|
|
|
addOfflineXP(playerName, skill, (int) (XP / skill.getXpModifier() * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()));
|
2013-03-17 15:34:46 +01:00
|
|
|
}
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
/**
|
2013-05-30 19:18:13 +02:00
|
|
|
* Adds XP to the player, calculates for XP Rate, skill modifiers, perks, child skills,
|
|
|
|
* and party sharing.
|
2013-03-01 06:52:01 +01:00
|
|
|
* </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
|
|
|
*/
|
2014-04-18 21:56:03 +02:00
|
|
|
@Deprecated
|
2013-04-10 03:09:25 +02:00
|
|
|
public static void addXP(Player player, String skillType, int XP) {
|
2014-04-18 21:56:03 +02:00
|
|
|
addXP(player, skillType, XP, "UNKNOWN");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds XP to the player, calculates for XP Rate, skill modifiers, perks, child skills,
|
|
|
|
* and party sharing.
|
|
|
|
* </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
|
|
|
|
* @param xpGainReason The reason to gain XP
|
|
|
|
*
|
|
|
|
* @throws InvalidSkillException if the given skill is not valid
|
|
|
|
* @throws InvalidXPGainReasonException if the given xpGainReason is not valid
|
|
|
|
*/
|
|
|
|
public static void addXP(Player player, String skillType, int XP, String xpGainReason) {
|
2014-08-22 20:49:16 +02:00
|
|
|
addXP(player, skillType, XP, xpGainReason, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds XP to the player, calculates for XP Rate, skill modifiers, perks, child skills,
|
|
|
|
* and party sharing.
|
|
|
|
* </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
|
|
|
|
* @param xpGainReason The reason to gain XP
|
|
|
|
* @param isUnshared true if the XP cannot be shared with party members
|
|
|
|
*
|
|
|
|
* @throws InvalidSkillException if the given skill is not valid
|
|
|
|
* @throws InvalidXPGainReasonException if the given xpGainReason is not valid
|
|
|
|
*/
|
|
|
|
public static void addXP(Player player, String skillType, int XP, String xpGainReason, boolean isUnshared) {
|
|
|
|
if (isUnshared) {
|
2019-01-28 03:11:51 +01:00
|
|
|
getPlayer(player).beginUnsharedXpGain(getSkillType(skillType), XP, getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
|
2014-08-22 20:49:16 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-28 03:11:51 +01:00
|
|
|
getPlayer(player).beginXpGain(getSkillType(skillType), XP, getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
|
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-05-15 01:31:40 +02:00
|
|
|
* @throws UnsupportedOperationException if the given skill is a child skill
|
2013-03-01 06:52:01 +01:00
|
|
|
*/
|
2013-04-10 03:09:25 +02:00
|
|
|
public static int getXP(Player player, String skillType) {
|
2014-08-22 22:27:05 +02:00
|
|
|
return getPlayer(player).getSkillXpLevel(getNonChildSkillType(skillType));
|
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-05-15 01:31:40 +02:00
|
|
|
* @throws UnsupportedOperationException if the given skill is a child skill
|
2013-03-17 15:34:46 +01:00
|
|
|
*/
|
2014-08-01 20:17:15 +02:00
|
|
|
@Deprecated
|
2013-04-10 03:09:25 +02:00
|
|
|
public static int getOfflineXP(String playerName, String skillType) {
|
2013-05-30 19:18:13 +02:00
|
|
|
return getOfflineProfile(playerName).getSkillXpLevel(getNonChildSkillType(skillType));
|
2013-03-17 15:34:46 +01:00
|
|
|
}
|
|
|
|
|
2014-08-01 20:17:15 +02:00
|
|
|
/**
|
|
|
|
* Get the amount of XP an offline player has in a specific skill.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param uuid The player to get XP for
|
|
|
|
* @param skillType The skill to get XP for
|
|
|
|
* @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 UnsupportedOperationException if the given skill is a child skill
|
|
|
|
*/
|
|
|
|
public static int getOfflineXP(UUID uuid, String skillType) {
|
|
|
|
return getOfflineProfile(uuid).getSkillXpLevel(getNonChildSkillType(skillType));
|
|
|
|
}
|
|
|
|
|
2013-04-24 19:30:46 +02:00
|
|
|
/**
|
|
|
|
* Get the raw 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
|
|
|
|
*
|
|
|
|
* @throws InvalidSkillException if the given skill is not valid
|
2013-05-15 01:31:40 +02:00
|
|
|
* @throws UnsupportedOperationException if the given skill is a child skill
|
2013-04-24 19:30:46 +02:00
|
|
|
*/
|
|
|
|
public static float getXPRaw(Player player, String skillType) {
|
2014-08-22 22:27:05 +02:00
|
|
|
return getPlayer(player).getSkillXpLevelRaw(getNonChildSkillType(skillType));
|
2013-04-24 19:30:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the raw 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
|
|
|
|
*
|
|
|
|
* @throws InvalidSkillException if the given skill is not valid
|
|
|
|
* @throws InvalidPlayerException if the given player does not exist in the database
|
2013-05-15 01:31:40 +02:00
|
|
|
* @throws UnsupportedOperationException if the given skill is a child skill
|
2013-04-24 19:30:46 +02:00
|
|
|
*/
|
2014-08-01 20:17:15 +02:00
|
|
|
@Deprecated
|
2013-04-24 19:30:46 +02:00
|
|
|
public static float getOfflineXPRaw(String playerName, String skillType) {
|
2013-05-30 19:18:13 +02:00
|
|
|
return getOfflineProfile(playerName).getSkillXpLevelRaw(getNonChildSkillType(skillType));
|
2013-04-24 19:30:46 +02:00
|
|
|
}
|
|
|
|
|
2014-08-01 20:17:15 +02:00
|
|
|
/**
|
|
|
|
* Get the raw amount of XP an offline player has in a specific skill.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param uuid The player to get XP for
|
|
|
|
* @param skillType The skill to get XP for
|
|
|
|
* @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 UnsupportedOperationException if the given skill is a child skill
|
|
|
|
*/
|
|
|
|
public static float getOfflineXPRaw(UUID uuid, String skillType) {
|
|
|
|
return getOfflineProfile(uuid).getSkillXpLevelRaw(getNonChildSkillType(skillType));
|
|
|
|
}
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
/**
|
2013-05-15 05:30:24 +02:00
|
|
|
* Get the total amount of XP needed to reach the next level.
|
2013-03-01 06:52:01 +01:00
|
|
|
* </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
|
2013-05-15 05:30:24 +02:00
|
|
|
* @return the total amount of XP needed to reach the next level
|
2013-04-10 02:52:58 +02:00
|
|
|
*
|
|
|
|
* @throws InvalidSkillException if the given skill is not valid
|
2013-05-15 01:31:40 +02:00
|
|
|
* @throws UnsupportedOperationException if the given skill is a child skill
|
2013-03-01 06:52:01 +01:00
|
|
|
*/
|
2013-04-10 03:09:25 +02:00
|
|
|
public static int getXPToNextLevel(Player player, String skillType) {
|
2014-08-22 22:27:05 +02:00
|
|
|
return getPlayer(player).getXpToLevel(getNonChildSkillType(skillType));
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
2013-03-17 15:34:46 +01:00
|
|
|
/**
|
2013-05-15 05:30:24 +02:00
|
|
|
* Get the total amount of XP an offline player needs to reach the next level.
|
2013-03-17 15:34:46 +01:00
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param playerName The player to get XP for
|
|
|
|
* @param skillType The skill to get XP for
|
2013-05-15 05:30:24 +02:00
|
|
|
* @return the total amount of XP needed to reach the next level
|
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-05-15 01:31:40 +02:00
|
|
|
* @throws UnsupportedOperationException if the given skill is a child skill
|
2013-03-17 15:34:46 +01:00
|
|
|
*/
|
2014-08-01 20:17:15 +02:00
|
|
|
@Deprecated
|
2013-04-10 03:09:25 +02:00
|
|
|
public static int getOfflineXPToNextLevel(String playerName, String skillType) {
|
2013-05-30 19:18:13 +02:00
|
|
|
return getOfflineProfile(playerName).getXpToLevel(getNonChildSkillType(skillType));
|
2013-03-17 15:34:46 +01:00
|
|
|
}
|
|
|
|
|
2014-08-01 20:17:15 +02:00
|
|
|
/**
|
|
|
|
* Get the total amount of XP an offline player needs to reach the next level.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param uuid The player to get XP for
|
|
|
|
* @param skillType The skill to get XP for
|
|
|
|
* @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
|
|
|
|
* @throws UnsupportedOperationException if the given skill is a child skill
|
|
|
|
*/
|
|
|
|
public static int getOfflineXPToNextLevel(UUID uuid, String skillType) {
|
|
|
|
return getOfflineProfile(uuid).getXpToLevel(getNonChildSkillType(skillType));
|
|
|
|
}
|
|
|
|
|
2013-05-15 05:30:24 +02:00
|
|
|
/**
|
|
|
|
* Get the amount of XP remaining until the next level.
|
|
|
|
* </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 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) {
|
2019-01-13 08:54:53 +01:00
|
|
|
PrimarySkillType skill = getNonChildSkillType(skillType);
|
2013-05-15 05:30:24 +02:00
|
|
|
|
2014-08-22 22:27:05 +02:00
|
|
|
PlayerProfile profile = getPlayer(player).getProfile();
|
2013-05-15 05:30:24 +02:00
|
|
|
|
|
|
|
return profile.getXpToLevel(skill) - profile.getSkillXpLevel(skill);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 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
|
|
|
|
*/
|
2014-08-01 20:17:15 +02:00
|
|
|
@Deprecated
|
2013-05-15 05:30:24 +02:00
|
|
|
public static int getOfflineXPRemaining(String playerName, String skillType) {
|
2019-01-13 08:54:53 +01:00
|
|
|
PrimarySkillType skill = getNonChildSkillType(skillType);
|
2013-05-15 05:30:24 +02:00
|
|
|
PlayerProfile profile = getOfflineProfile(playerName);
|
|
|
|
|
|
|
|
return profile.getXpToLevel(skill) - profile.getSkillXpLevel(skill);
|
|
|
|
}
|
|
|
|
|
2014-08-01 20:17:15 +02:00
|
|
|
/**
|
|
|
|
* Get the amount of XP an offline player has left before leveling up.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param uuid 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 float getOfflineXPRemaining(UUID uuid, String skillType) {
|
2019-01-13 08:54:53 +01:00
|
|
|
PrimarySkillType skill = getNonChildSkillType(skillType);
|
2014-08-01 20:17:15 +02:00
|
|
|
PlayerProfile profile = getOfflineProfile(uuid);
|
|
|
|
|
|
|
|
return profile.getXpToLevel(skill) - profile.getSkillXpLevelRaw(skill);
|
|
|
|
}
|
|
|
|
|
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) {
|
2014-08-22 22:27:05 +02:00
|
|
|
getPlayer(player).addLevels(getSkillType(skillType), 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
|
|
|
|
*/
|
2014-08-01 20:17:15 +02:00
|
|
|
@Deprecated
|
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);
|
2019-01-13 08:54:53 +01:00
|
|
|
PrimarySkillType skill = getSkillType(skillType);
|
2013-04-10 02:52:58 +02:00
|
|
|
|
2013-03-17 15:34:46 +01:00
|
|
|
if (skill.isChildSkill()) {
|
2019-01-13 08:54:53 +01:00
|
|
|
Set<PrimarySkillType> parentSkills = FamilyTree.getParents(skill);
|
2013-03-17 15:34:46 +01:00
|
|
|
|
2019-01-13 08:54:53 +01:00
|
|
|
for (PrimarySkillType parentSkill : parentSkills) {
|
2013-03-17 15:34:46 +01:00
|
|
|
profile.addLevels(parentSkill, (levels / parentSkills.size()));
|
|
|
|
}
|
|
|
|
|
2014-06-04 05:52:22 +02:00
|
|
|
profile.scheduleAsyncSave();
|
2013-03-17 15:34:46 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
profile.addLevels(skill, levels);
|
2014-06-04 05:52:22 +02:00
|
|
|
profile.scheduleAsyncSave();
|
2013-03-17 15:34:46 +01:00
|
|
|
}
|
|
|
|
|
2014-08-01 20:17:15 +02:00
|
|
|
/**
|
|
|
|
* Add levels to a skill for an offline player.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param uuid The player to add levels to
|
|
|
|
* @param skillType Type of skill to add levels to
|
|
|
|
* @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
|
|
|
|
*/
|
|
|
|
public static void addLevelOffline(UUID uuid, String skillType, int levels) {
|
|
|
|
PlayerProfile profile = getOfflineProfile(uuid);
|
2019-01-13 08:54:53 +01:00
|
|
|
PrimarySkillType skill = getSkillType(skillType);
|
2014-08-01 20:17:15 +02:00
|
|
|
|
|
|
|
if (skill.isChildSkill()) {
|
2019-01-13 08:54:53 +01:00
|
|
|
Set<PrimarySkillType> parentSkills = FamilyTree.getParents(skill);
|
2014-08-01 20:17:15 +02:00
|
|
|
|
2019-01-13 08:54:53 +01:00
|
|
|
for (PrimarySkillType parentSkill : parentSkills) {
|
2014-08-01 20:17:15 +02:00
|
|
|
profile.addLevels(parentSkill, (levels / parentSkills.size()));
|
|
|
|
}
|
|
|
|
|
|
|
|
profile.scheduleAsyncSave();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
profile.addLevels(skill, levels);
|
|
|
|
profile.scheduleAsyncSave();
|
|
|
|
}
|
|
|
|
|
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) {
|
2014-08-22 22:27:05 +02:00
|
|
|
return getPlayer(player).getSkillLevel(getSkillType(skillType));
|
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
|
|
|
|
*/
|
2014-08-01 20:17:15 +02:00
|
|
|
@Deprecated
|
2013-04-10 03:09:25 +02:00
|
|
|
public static int getLevelOffline(String playerName, String skillType) {
|
2013-05-30 19:18:13 +02:00
|
|
|
return getOfflineProfile(playerName).getSkillLevel(getSkillType(skillType));
|
2013-03-17 15:34:46 +01:00
|
|
|
}
|
|
|
|
|
2014-08-01 20:17:15 +02:00
|
|
|
/**
|
|
|
|
* Get the level an offline player has in a specific skill.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param uuid The player to get the level for
|
|
|
|
* @param skillType The skill to get the level for
|
|
|
|
* @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
|
|
|
|
*/
|
|
|
|
public static int getLevelOffline(UUID uuid, String skillType) {
|
|
|
|
return getOfflineProfile(uuid).getSkillLevel(getSkillType(skillType));
|
|
|
|
}
|
|
|
|
|
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) {
|
2014-08-22 22:27:05 +02:00
|
|
|
return getPlayer(player).getPowerLevel();
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
*/
|
2014-08-01 20:17:15 +02:00
|
|
|
@Deprecated
|
2013-03-17 15:34:46 +01:00
|
|
|
public static int getPowerLevelOffline(String playerName) {
|
|
|
|
int powerLevel = 0;
|
|
|
|
PlayerProfile profile = getOfflineProfile(playerName);
|
|
|
|
|
2019-01-13 08:54:53 +01:00
|
|
|
for (PrimarySkillType type : PrimarySkillType.NON_CHILD_SKILLS) {
|
2013-03-17 15:34:46 +01:00
|
|
|
powerLevel += profile.getSkillLevel(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
return powerLevel;
|
|
|
|
}
|
|
|
|
|
2014-08-01 20:17:15 +02:00
|
|
|
/**
|
|
|
|
* Gets the power level of an offline player.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param uuid The player to get the power level for
|
|
|
|
* @return the power level of the player
|
|
|
|
*
|
|
|
|
* @throws InvalidPlayerException if the given player does not exist in the database
|
|
|
|
*/
|
|
|
|
public static int getPowerLevelOffline(UUID uuid) {
|
|
|
|
int powerLevel = 0;
|
|
|
|
PlayerProfile profile = getOfflineProfile(uuid);
|
|
|
|
|
2019-01-13 08:54:53 +01:00
|
|
|
for (PrimarySkillType type : PrimarySkillType.NON_CHILD_SKILLS) {
|
2014-08-01 20:17:15 +02:00
|
|
|
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-05-30 19:18:13 +02:00
|
|
|
return Config.getInstance().getLevelCap(getSkillType(skillType));
|
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-08-13 09:37:45 +02:00
|
|
|
/**
|
|
|
|
* Get the position on the leaderboard of a player.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param playerName The name of the player to check
|
|
|
|
* @param skillType The skill to check
|
|
|
|
*
|
|
|
|
* @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
|
|
|
|
*
|
|
|
|
* @return the position on the leaderboard
|
|
|
|
*/
|
2014-08-01 20:17:15 +02:00
|
|
|
@Deprecated
|
2013-08-13 09:37:45 +02:00
|
|
|
public static int getPlayerRankSkill(String playerName, String skillType) {
|
2013-09-12 04:42:27 +02:00
|
|
|
return mcMMO.getDatabaseManager().readRank(getOfflineProfile(playerName).getPlayerName()).get(getNonChildSkillType(skillType));
|
2013-08-13 09:37:45 +02:00
|
|
|
}
|
|
|
|
|
2014-08-01 20:17:15 +02:00
|
|
|
/**
|
|
|
|
* Get the position on the leaderboard of a player.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param uuid The name of the player to check
|
|
|
|
* @param skillType The skill to check
|
|
|
|
*
|
|
|
|
* @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
|
|
|
|
*
|
|
|
|
* @return the position on the leaderboard
|
|
|
|
*/
|
|
|
|
public static int getPlayerRankSkill(UUID uuid, String skillType) {
|
|
|
|
return mcMMO.getDatabaseManager().readRank(getOfflineProfile(uuid).getPlayerName()).get(getNonChildSkillType(skillType));
|
|
|
|
}
|
2013-08-13 09:37:45 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the position on the power level leaderboard of a player.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param playerName The name of the player to check
|
|
|
|
*
|
|
|
|
* @throws InvalidPlayerException if the given player does not exist in the database
|
|
|
|
*
|
|
|
|
* @return the position on the power level leaderboard
|
|
|
|
*/
|
2014-08-01 20:17:15 +02:00
|
|
|
@Deprecated
|
2013-08-13 09:37:45 +02:00
|
|
|
public static int getPlayerRankOverall(String playerName) {
|
2013-09-12 04:42:27 +02:00
|
|
|
return mcMMO.getDatabaseManager().readRank(getOfflineProfile(playerName).getPlayerName()).get(null);
|
2013-08-13 09:37:45 +02:00
|
|
|
}
|
|
|
|
|
2014-08-01 20:17:15 +02:00
|
|
|
/**
|
|
|
|
* Get the position on the power level leaderboard of a player.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param uuid The name of the player to check
|
|
|
|
*
|
|
|
|
* @throws InvalidPlayerException if the given player does not exist in the database
|
|
|
|
*
|
|
|
|
* @return the position on the power level leaderboard
|
|
|
|
*/
|
|
|
|
public static int getPlayerRankOverall(UUID uuid) {
|
|
|
|
return mcMMO.getDatabaseManager().readRank(getOfflineProfile(uuid).getPlayerName()).get(null);
|
|
|
|
}
|
|
|
|
|
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) {
|
2014-08-22 22:27:05 +02:00
|
|
|
getPlayer(player).modifySkill(getSkillType(skillType), 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
|
|
|
|
*/
|
2014-08-01 20:17:15 +02:00
|
|
|
@Deprecated
|
2013-04-10 03:09:25 +02:00
|
|
|
public static void setLevelOffline(String playerName, String skillType, int skillLevel) {
|
2013-05-30 19:18:13 +02:00
|
|
|
getOfflineProfile(playerName).modifySkill(getSkillType(skillType), skillLevel);
|
2013-03-17 15:34:46 +01:00
|
|
|
}
|
|
|
|
|
2014-08-01 20:17:15 +02:00
|
|
|
/**
|
|
|
|
* Sets the level of an offline player in a specific skill type.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param uuid 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
|
|
|
|
*
|
|
|
|
* @throws InvalidSkillException if the given skill is not valid
|
|
|
|
* @throws InvalidPlayerException if the given player does not exist in the database
|
|
|
|
*/
|
|
|
|
public static void setLevelOffline(UUID uuid, String skillType, int skillLevel) {
|
|
|
|
getOfflineProfile(uuid).modifySkill(getSkillType(skillType), skillLevel);
|
|
|
|
}
|
|
|
|
|
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-05-15 01:31:40 +02:00
|
|
|
* @throws UnsupportedOperationException if the given skill is a child skill
|
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) {
|
2014-08-22 22:27:05 +02:00
|
|
|
getPlayer(player).setSkillXpLevel(getNonChildSkillType(skillType), 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-05-15 01:31:40 +02:00
|
|
|
* @throws UnsupportedOperationException if the given skill is a child skill
|
2013-03-17 15:34:46 +01:00
|
|
|
*/
|
2014-08-01 20:17:15 +02:00
|
|
|
@Deprecated
|
2013-04-10 03:09:25 +02:00
|
|
|
public static void setXPOffline(String playerName, String skillType, int newValue) {
|
2013-05-30 19:18:13 +02:00
|
|
|
getOfflineProfile(playerName).setSkillXpLevel(getNonChildSkillType(skillType), newValue);
|
2013-03-17 15:34:46 +01:00
|
|
|
}
|
|
|
|
|
2014-08-01 20:17:15 +02:00
|
|
|
/**
|
|
|
|
* Sets the XP of an offline player in a specific skill type.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param uuid 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
|
|
|
|
*
|
|
|
|
* @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(UUID uuid, String skillType, int newValue) {
|
|
|
|
getOfflineProfile(uuid).setSkillXpLevel(getNonChildSkillType(skillType), newValue);
|
|
|
|
}
|
|
|
|
|
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-05-15 01:31:40 +02:00
|
|
|
* @throws UnsupportedOperationException if the given skill is a child skill
|
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) {
|
2014-08-22 22:27:05 +02:00
|
|
|
getPlayer(player).removeXp(getNonChildSkillType(skillType), 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-05-15 01:31:40 +02:00
|
|
|
* @throws UnsupportedOperationException if the given skill is a child skill
|
2013-03-17 15:34:46 +01:00
|
|
|
*/
|
2014-08-01 20:17:15 +02:00
|
|
|
@Deprecated
|
2013-04-10 03:09:25 +02:00
|
|
|
public static void removeXPOffline(String playerName, String skillType, int xp) {
|
2013-05-30 19:18:13 +02:00
|
|
|
getOfflineProfile(playerName).removeXp(getNonChildSkillType(skillType), xp);
|
2013-03-17 15:34:46 +01:00
|
|
|
}
|
|
|
|
|
2014-08-01 20:17:15 +02:00
|
|
|
/**
|
|
|
|
* Removes XP from an offline player in a specific skill type.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param uuid The player to change the XP of
|
|
|
|
* @param skillType The skill to change the XP for
|
|
|
|
* @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 UnsupportedOperationException if the given skill is a child skill
|
|
|
|
*/
|
|
|
|
public static void removeXPOffline(UUID uuid, String skillType, int xp) {
|
|
|
|
getOfflineProfile(uuid).removeXp(getNonChildSkillType(skillType), xp);
|
|
|
|
}
|
|
|
|
|
2014-08-22 00:38:33 +02:00
|
|
|
/**
|
|
|
|
* Check how much XP is needed for a specific level with the selected level curve.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param level The level to get the amount of XP for
|
|
|
|
*
|
|
|
|
* @throws InvalidFormulaTypeException if the given formulaType is not valid
|
|
|
|
*/
|
|
|
|
public static int getXpNeededToLevel(int level) {
|
|
|
|
return mcMMO.getFormulaManager().getCachedXpToLevel(level, ExperienceConfig.getInstance().getFormulaType());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check how much XP is needed for a specific level with the provided level curve.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param level The level to get the amount of XP for
|
|
|
|
* @param formulaType The formula type to get the amount of XP for
|
|
|
|
*
|
|
|
|
* @throws InvalidFormulaTypeException if the given formulaType is not valid
|
|
|
|
*/
|
|
|
|
public static int getXpNeededToLevel(int level, String formulaType) {
|
|
|
|
return mcMMO.getFormulaManager().getCachedXpToLevel(level, getFormulaType(formulaType));
|
|
|
|
}
|
|
|
|
|
2019-02-02 00:23:45 +01:00
|
|
|
/**
|
|
|
|
* Will add the appropriate type of XP from the block to the player based on the material of the blocks given
|
|
|
|
* @param blockStates the blocks to reward XP for
|
|
|
|
* @param mcMMOPlayer the target player
|
|
|
|
*/
|
|
|
|
public static void addXpFromBlocks(ArrayList<BlockState> blockStates, McMMOPlayer mcMMOPlayer)
|
|
|
|
{
|
|
|
|
for(BlockState bs : blockStates)
|
|
|
|
{
|
|
|
|
for(PrimarySkillType skillType : PrimarySkillType.values())
|
|
|
|
{
|
|
|
|
if(ExperienceConfig.getInstance().getXp(skillType, bs.getType()) > 0)
|
|
|
|
{
|
2019-02-02 16:15:12 +01:00
|
|
|
mcMMOPlayer.applyXpGain(skillType, ExperienceConfig.getInstance().getXp(skillType, bs.getType()), XPGainReason.PVE, XPGainSource.SELF);
|
2019-02-02 00:23:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Will add the appropriate type of XP from the block to the player based on the material of the blocks given if it matches the given skillType
|
|
|
|
* @param blockStates the blocks to reward XP for
|
|
|
|
* @param mcMMOPlayer the target player
|
|
|
|
* @param skillType target primary skill
|
|
|
|
*/
|
|
|
|
public static void addXpFromBlocksBySkill(ArrayList<BlockState> blockStates, McMMOPlayer mcMMOPlayer, PrimarySkillType skillType)
|
|
|
|
{
|
|
|
|
for(BlockState bs : blockStates)
|
|
|
|
{
|
|
|
|
if(ExperienceConfig.getInstance().getXp(skillType, bs.getType()) > 0)
|
|
|
|
{
|
2019-02-02 16:15:12 +01:00
|
|
|
mcMMOPlayer.applyXpGain(skillType, ExperienceConfig.getInstance().getXp(skillType, bs.getType()), XPGainReason.PVE, XPGainSource.SELF);
|
2019-02-02 00:23:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Will add the appropriate type of XP from the block to the player based on the material of the blocks given
|
|
|
|
* @param blockState The target blockstate
|
|
|
|
* @param mcMMOPlayer The target player
|
|
|
|
*/
|
|
|
|
public static void addXpFromBlock(BlockState blockState, McMMOPlayer mcMMOPlayer)
|
|
|
|
{
|
|
|
|
for(PrimarySkillType skillType : PrimarySkillType.values())
|
|
|
|
{
|
|
|
|
if(ExperienceConfig.getInstance().getXp(skillType, blockState.getType()) > 0)
|
|
|
|
{
|
2019-02-02 16:15:12 +01:00
|
|
|
mcMMOPlayer.applyXpGain(skillType, ExperienceConfig.getInstance().getXp(skillType, blockState.getType()), XPGainReason.PVE, XPGainSource.SELF);
|
2019-02-02 00:23:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Will add the appropriate type of XP from the block to the player based on the material of the blocks given if it matches the given skillType
|
|
|
|
* @param blockState The target blockstate
|
|
|
|
* @param mcMMOPlayer The target player
|
|
|
|
* @param skillType target primary skill
|
|
|
|
*/
|
|
|
|
public static void addXpFromBlockBySkill(BlockState blockState, McMMOPlayer mcMMOPlayer, PrimarySkillType skillType)
|
|
|
|
{
|
|
|
|
if(ExperienceConfig.getInstance().getXp(skillType, blockState.getType()) > 0)
|
|
|
|
{
|
2019-02-02 16:15:12 +01:00
|
|
|
mcMMOPlayer.applyXpGain(skillType, ExperienceConfig.getInstance().getXp(skillType, blockState.getType()), XPGainReason.PVE, XPGainSource.SELF);
|
2019-02-02 00:23:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-05-30 19:18:13 +02:00
|
|
|
// Utility methods follow.
|
2019-01-13 08:54:53 +01:00
|
|
|
private static void addOfflineXP(UUID playerUniqueId, PrimarySkillType skill, int XP) {
|
2014-08-01 20:17:15 +02:00
|
|
|
PlayerProfile profile = getOfflineProfile(playerUniqueId);
|
2013-05-30 19:18:13 +02:00
|
|
|
|
2014-08-01 20:17:15 +02:00
|
|
|
profile.addXp(skill, XP);
|
|
|
|
profile.save();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Deprecated
|
2019-01-13 08:54:53 +01:00
|
|
|
private static void addOfflineXP(String playerName, PrimarySkillType skill, int XP) {
|
2013-03-17 15:34:46 +01:00
|
|
|
PlayerProfile profile = getOfflineProfile(playerName);
|
|
|
|
|
2013-10-29 16:02:57 +01:00
|
|
|
profile.addXp(skill, XP);
|
2014-06-04 05:52:22 +02:00
|
|
|
profile.scheduleAsyncSave();
|
2013-03-17 15:34:46 +01:00
|
|
|
}
|
|
|
|
|
2014-08-01 20:17:15 +02:00
|
|
|
private static PlayerProfile getOfflineProfile(UUID uuid) {
|
2014-08-01 19:35:36 +02:00
|
|
|
PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(uuid);
|
2014-08-01 20:17:15 +02:00
|
|
|
|
|
|
|
if (!profile.isLoaded()) {
|
|
|
|
throw new InvalidPlayerException();
|
|
|
|
}
|
|
|
|
|
|
|
|
return profile;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Deprecated
|
2013-03-17 15:34:46 +01:00
|
|
|
private static PlayerProfile getOfflineProfile(String playerName) {
|
2014-08-01 20:17:15 +02:00
|
|
|
UUID uuid = mcMMO.p.getServer().getOfflinePlayer(playerName).getUniqueId();
|
2014-08-01 19:35:36 +02:00
|
|
|
PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(uuid);
|
2013-03-17 15:34:46 +01:00
|
|
|
|
|
|
|
if (!profile.isLoaded()) {
|
|
|
|
throw new InvalidPlayerException();
|
|
|
|
}
|
|
|
|
|
|
|
|
return profile;
|
|
|
|
}
|
2013-05-30 19:18:13 +02:00
|
|
|
|
2019-01-13 08:54:53 +01:00
|
|
|
private static PrimarySkillType getSkillType(String skillType) throws InvalidSkillException {
|
|
|
|
PrimarySkillType skill = PrimarySkillType.getSkill(skillType);
|
2013-05-30 19:18:13 +02:00
|
|
|
|
|
|
|
if (skill == null) {
|
|
|
|
throw new InvalidSkillException();
|
|
|
|
}
|
|
|
|
|
|
|
|
return skill;
|
|
|
|
}
|
|
|
|
|
2019-01-13 08:54:53 +01:00
|
|
|
private static PrimarySkillType getNonChildSkillType(String skillType) throws InvalidSkillException, UnsupportedOperationException {
|
|
|
|
PrimarySkillType skill = getSkillType(skillType);
|
2013-05-30 19:18:13 +02:00
|
|
|
|
|
|
|
if (skill.isChildSkill()) {
|
|
|
|
throw new UnsupportedOperationException("Child skills do not have XP");
|
|
|
|
}
|
|
|
|
|
|
|
|
return skill;
|
|
|
|
}
|
2014-04-18 21:56:03 +02:00
|
|
|
|
|
|
|
private static XPGainReason getXPGainReason(String reason) throws InvalidXPGainReasonException {
|
|
|
|
XPGainReason xpGainReason = XPGainReason.getXPGainReason(reason);
|
|
|
|
|
|
|
|
if (xpGainReason == null) {
|
|
|
|
throw new InvalidXPGainReasonException();
|
|
|
|
}
|
|
|
|
|
|
|
|
return xpGainReason;
|
|
|
|
}
|
2014-08-22 00:38:33 +02:00
|
|
|
|
|
|
|
private static FormulaType getFormulaType(String formula) throws InvalidFormulaTypeException {
|
|
|
|
FormulaType formulaType = FormulaType.getFormulaType(formula);
|
|
|
|
|
|
|
|
if (formulaType == null) {
|
|
|
|
throw new InvalidFormulaTypeException();
|
|
|
|
}
|
|
|
|
|
|
|
|
return formulaType;
|
|
|
|
}
|
2014-08-22 22:27:05 +02:00
|
|
|
|
|
|
|
private static McMMOPlayer getPlayer(Player player) throws McMMOPlayerNotFoundException {
|
|
|
|
if (!UserManager.hasPlayerDataKey(player)) {
|
|
|
|
throw new McMMOPlayerNotFoundException(player);
|
|
|
|
}
|
|
|
|
|
|
|
|
return UserManager.getPlayer(player);
|
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|