1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225 |
- package com.gmail.nossr50.api;
- import com.gmail.nossr50.api.exceptions.*;
- import com.gmail.nossr50.config.experience.ExperienceConfig;
- import com.gmail.nossr50.datatypes.experience.FormulaType;
- import com.gmail.nossr50.datatypes.experience.XPGainReason;
- import com.gmail.nossr50.datatypes.experience.XPGainSource;
- import com.gmail.nossr50.datatypes.player.McMMOPlayer;
- import com.gmail.nossr50.datatypes.player.PlayerProfile;
- import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
- import com.gmail.nossr50.mcMMO;
- import com.gmail.nossr50.skills.child.FamilyTree;
- import com.gmail.nossr50.util.player.UserManager;
- import com.gmail.nossr50.util.skills.CombatUtils;
- import org.bukkit.Bukkit;
- import org.bukkit.OfflinePlayer;
- import org.bukkit.block.BlockState;
- import org.bukkit.entity.LivingEntity;
- import org.bukkit.entity.Player;
- import java.util.ArrayList;
- import java.util.Set;
- import java.util.UUID;
- public final class ExperienceAPI {
- private ExperienceAPI() {}
- /**
- * 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) {
- return mcMMO.p.getSkillTools().matchSkill(skillType) != null;
- }
- /**
- * Start the task that gives combat XP.
- * Processes combat XP like mcMMO normally would, so mcMMO will check whether or not the entity should reward XP when giving out the XP
- *
- * @param mcMMOPlayer The attacking player
- * @param target The defending entity
- * @param primarySkillType The skill being used
- * @param multiplier final XP result will be multiplied by this
- * @deprecated Draft API
- */
- @Deprecated
- public static void addCombatXP(McMMOPlayer mcMMOPlayer, LivingEntity target, PrimarySkillType primarySkillType, double multiplier) {
- CombatUtils.processCombatXP(mcMMOPlayer, target, primarySkillType, multiplier);
- }
- /**
- * Start the task that gives combat XP.
- * Processes combat XP like mcMMO normally would, so mcMMO will check whether or not the entity should reward XP when giving out the XP
- *
- * @param mcMMOPlayer The attacking player
- * @param target The defending entity
- * @param primarySkillType The skill being used
- * @deprecated Draft API
- */
- @Deprecated
- public static void addCombatXP(McMMOPlayer mcMMOPlayer, LivingEntity target, PrimarySkillType primarySkillType) {
- CombatUtils.processCombatXP(mcMMOPlayer, target, primarySkillType);
- }
- /**
- * 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) {
- PrimarySkillType skill = mcMMO.p.getSkillTools().matchSkill(skillType);
- return skill != null && !mcMMO.p.getSkillTools().isChildSkill(skill);
- }
- @Deprecated
- public static void addRawXP(Player player, String skillType, int XP) {
- addRawXP(player, skillType, (float) XP);
- }
- /**
- * 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
- *
- * @throws InvalidSkillException if the given skill is not valid
- */
- @Deprecated
- public static void addRawXP(Player player, String skillType, float XP) {
- 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) {
- 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) {
- getPlayer(player).beginUnsharedXpGain(getSkillType(skillType), XP, getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
- return;
- }
- getPlayer(player).applyXpGain(getSkillType(skillType), XP, getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
- }
- /**
- * 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)}
- */
- @Deprecated
- public static void addRawXPOffline(String playerName, String skillType, int XP) {
- addRawXPOffline(playerName, skillType, (float) XP);
- }
- /**
- * Adds raw XP to an offline player.
- * </br>
- * This function is designed for API usage.
- *
- * @deprecated We're using uuids to get an offline player
- * replaced by {@link #addRawXPOffline(UUID uuid, String skillType, float XP)}
- *
- * @param playerName The 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
- */
- @Deprecated
- public static void addRawXPOffline(String playerName, String skillType, float XP) {
- addOfflineXP(playerName, getSkillType(skillType), (int) Math.floor(XP));
- }
- /**
- * 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));
- }
- /**
- * 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
- *
- * @throws InvalidSkillException if the given skill is not valid
- */
- @Deprecated
- public static void addMultipliedXP(Player player, String skillType, int XP) {
- 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) {
- getPlayer(player).applyXpGain(getSkillType(skillType), (int) (XP * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()), getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
- }
- /**
- * 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
- *
- * @throws InvalidSkillException if the given skill is not valid
- * @throws InvalidPlayerException if the given player does not exist in the database
- */
- @Deprecated
- public static void addMultipliedXPOffline(String playerName, String skillType, int XP) {
- addOfflineXP(playerName, getSkillType(skillType), (int) (XP * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()));
- }
- /**
- * 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
- *
- * @throws InvalidSkillException if the given skill is not valid
- */
- @Deprecated
- public static void addModifiedXP(Player player, String skillType, int XP) {
- 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) {
- 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) {
- PrimarySkillType skill = getSkillType(skillType);
- if (isUnshared) {
- getPlayer(player).beginUnsharedXpGain(skill,
- (int) (XP / ExperienceConfig.getInstance().getFormulaSkillModifier(skill) * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()), getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
- return;
- }
- getPlayer(player).applyXpGain(skill, (int) (XP / ExperienceConfig.getInstance().getFormulaSkillModifier(skill) * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()), getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
- }
- /**
- * 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
- *
- * @throws InvalidSkillException if the given skill is not valid
- * @throws InvalidPlayerException if the given player does not exist in the database
- */
- @Deprecated
- public static void addModifiedXPOffline(String playerName, String skillType, int XP) {
- PrimarySkillType skill = getSkillType(skillType);
- addOfflineXP(playerName, skill, (int) (XP / ExperienceConfig.getInstance().getFormulaSkillModifier(skill) * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()));
- }
- /**
- * 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
- *
- * @throws InvalidSkillException if the given skill is not valid
- */
- @Deprecated
- public static void addXP(Player player, String skillType, int XP) {
- 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) {
- 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) {
- getPlayer(player).beginUnsharedXpGain(getSkillType(skillType), XP, getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
- return;
- }
- getPlayer(player).beginXpGain(getSkillType(skillType), XP, getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
- }
- /**
- * 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
- *
- * @throws InvalidSkillException if the given skill is not valid
- * @throws UnsupportedOperationException if the given skill is a child skill
- */
- public static int getXP(Player player, String skillType) {
- return getPlayer(player).getSkillXpLevel(getNonChildSkillType(skillType));
- }
- /**
- * 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
- *
- * @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
- */
- @Deprecated
- public static int getOfflineXP(String playerName, String skillType) {
- return getOfflineProfile(playerName).getSkillXpLevel(getNonChildSkillType(skillType));
- }
- /**
- * 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));
- }
- /**
- * 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
- * @throws UnsupportedOperationException if the given skill is a child skill
- */
- public static float getXPRaw(Player player, String skillType) {
- return getPlayer(player).getSkillXpLevelRaw(getNonChildSkillType(skillType));
- }
- /**
- * 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
- * @throws UnsupportedOperationException if the given skill is a child skill
- */
- @Deprecated
- public static float getOfflineXPRaw(String playerName, String skillType) {
- return getOfflineProfile(playerName).getSkillXpLevelRaw(getNonChildSkillType(skillType));
- }
- /**
- * 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));
- }
- /**
- * Get the total amount of XP needed to reach 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 total amount of XP needed to reach the next level
- *
- * @throws InvalidSkillException if the given skill is not valid
- * @throws UnsupportedOperationException if the given skill is a child skill
- */
- public static int getXPToNextLevel(Player player, String skillType) {
- return getPlayer(player).getXpToLevel(getNonChildSkillType(skillType));
- }
- /**
- * Get the total amount of XP an offline player needs to reach the next level.
- * </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 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
- */
- @Deprecated
- public static int getOfflineXPToNextLevel(String playerName, String skillType) {
- return getOfflineProfile(playerName).getXpToLevel(getNonChildSkillType(skillType));
- }
- /**
- * 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));
- }
- /**
- * 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) {
- PrimarySkillType skill = getNonChildSkillType(skillType);
- PlayerProfile profile = getPlayer(player).getProfile();
- 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
- */
- @Deprecated
- public static int getOfflineXPRemaining(String playerName, String skillType) {
- PrimarySkillType skill = getNonChildSkillType(skillType);
- PlayerProfile profile = getOfflineProfile(playerName);
- 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 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) {
- PrimarySkillType skill = getNonChildSkillType(skillType);
- PlayerProfile profile = getOfflineProfile(uuid);
- return profile.getXpToLevel(skill) - profile.getSkillXpLevelRaw(skill);
- }
- /**
- * 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
- *
- * @throws InvalidSkillException if the given skill is not valid
- */
- public static void addLevel(Player player, String skillType, int levels) {
- getPlayer(player).addLevels(getSkillType(skillType), levels);
- }
- /**
- * 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
- *
- * @throws InvalidSkillException if the given skill is not valid
- * @throws InvalidPlayerException if the given player does not exist in the database
- */
- @Deprecated
- public static void addLevelOffline(String playerName, String skillType, int levels) {
- PlayerProfile profile = getOfflineProfile(playerName);
- PrimarySkillType skill = getSkillType(skillType);
- if (mcMMO.p.getSkillTools().isChildSkill(skill)) {
- Set<PrimarySkillType> parentSkills = FamilyTree.getParents(skill);
- for (PrimarySkillType parentSkill : parentSkills) {
- profile.addLevels(parentSkill, (levels / parentSkills.size()));
- }
- profile.scheduleAsyncSave();
- return;
- }
- profile.addLevels(skill, levels);
- profile.scheduleAsyncSave();
- }
- /**
- * 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);
- PrimarySkillType skill = getSkillType(skillType);
- if (mcMMO.p.getSkillTools().isChildSkill(skill)) {
- Set<PrimarySkillType> parentSkills = FamilyTree.getParents(skill);
- for (PrimarySkillType parentSkill : parentSkills) {
- profile.addLevels(parentSkill, (levels / parentSkills.size()));
- }
- profile.scheduleAsyncSave();
- return;
- }
- profile.addLevels(skill, levels);
- profile.scheduleAsyncSave();
- }
- /**
- * 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
- *
- * @throws InvalidSkillException if the given skill is not valid
- * @deprecated Use getLevel(Player player, PrimarySkillType skillType) instead
- */
- @Deprecated
- public static int getLevel(Player player, String skillType) {
- return getPlayer(player).getSkillLevel(getSkillType(skillType));
- }
- /**
- * 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
- *
- * @throws InvalidSkillException if the given skill is not valid
- */
- public static int getLevel(Player player, PrimarySkillType skillType) {
- return getPlayer(player).getSkillLevel(skillType);
- }
- /**
- * 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
- *
- * @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(String playerName, String skillType) {
- return getOfflineProfile(playerName).getSkillLevel(getSkillType(skillType));
- }
- /**
- * 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));
- }
- /**
- * 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 getPlayer(player).getPowerLevel();
- }
- /**
- * 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
- *
- * @throws InvalidPlayerException if the given player does not exist in the database
- */
- @Deprecated
- public static int getPowerLevelOffline(String playerName) {
- int powerLevel = 0;
- PlayerProfile profile = getOfflineProfile(playerName);
- for (PrimarySkillType type : mcMMO.p.getSkillTools().NON_CHILD_SKILLS) {
- powerLevel += profile.getSkillLevel(type);
- }
- return powerLevel;
- }
- /**
- * 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);
- for (PrimarySkillType type : mcMMO.p.getSkillTools().NON_CHILD_SKILLS) {
- powerLevel += profile.getSkillLevel(type);
- }
- return powerLevel;
- }
- /**
- * 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
- *
- * @throws InvalidSkillException if the given skill is not valid
- */
- public static int getLevelCap(String skillType) {
- return mcMMO.p.getSkillTools().getLevelCap(getSkillType(skillType));
- }
- /**
- * Get the power level cap.
- * </br>
- * This function is designed for API usage.
- *
- * @return the overall power level cap
- */
- public static int getPowerLevelCap() {
- return mcMMO.p.getGeneralConfig().getPowerLevelCap();
- }
- /**
- * 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
- */
- @Deprecated
- public static int getPlayerRankSkill(String playerName, String skillType) {
- return mcMMO.getDatabaseManager().readRank(mcMMO.p.getServer().getOfflinePlayer(playerName).getName()).get(getNonChildSkillType(skillType));
- }
- /**
- * 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(mcMMO.p.getServer().getOfflinePlayer(uuid).getName()).get(getNonChildSkillType(skillType));
- }
- /**
- * 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
- */
- @Deprecated
- public static int getPlayerRankOverall(String playerName) {
- return mcMMO.getDatabaseManager().readRank(mcMMO.p.getServer().getOfflinePlayer(playerName).getName()).get(null);
- }
- /**
- * 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(mcMMO.p.getServer().getOfflinePlayer(uuid).getName()).get(null);
- }
- /**
- * 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
- *
- * @throws InvalidSkillException if the given skill is not valid
- */
- public static void setLevel(Player player, String skillType, int skillLevel) {
- getPlayer(player).modifySkill(getSkillType(skillType), skillLevel);
- }
- /**
- * 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
- *
- * @throws InvalidSkillException if the given skill is not valid
- * @throws InvalidPlayerException if the given player does not exist in the database
- */
- @Deprecated
- public static void setLevelOffline(String playerName, String skillType, int skillLevel) {
- getOfflineProfile(playerName).modifySkill(getSkillType(skillType), skillLevel);
- }
- /**
- * 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);
- }
- /**
- * 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
- *
- * @throws InvalidSkillException if the given skill is not valid
- * @throws UnsupportedOperationException if the given skill is a child skill
- */
- public static void setXP(Player player, String skillType, int newValue) {
- getPlayer(player).setSkillXpLevel(getNonChildSkillType(skillType), newValue);
- }
- /**
- * 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
- *
- * @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
- */
- @Deprecated
- public static void setXPOffline(String playerName, String skillType, int newValue) {
- getOfflineProfile(playerName).setSkillXpLevel(getNonChildSkillType(skillType), newValue);
- }
- /**
- * 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);
- }
- /**
- * 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
- *
- * @throws InvalidSkillException if the given skill is not valid
- * @throws UnsupportedOperationException if the given skill is a child skill
- */
- public static void removeXP(Player player, String skillType, int xp) {
- getPlayer(player).removeXp(getNonChildSkillType(skillType), xp);
- }
- /**
- * 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
- *
- * @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
- */
- @Deprecated
- public static void removeXPOffline(String playerName, String skillType, int xp) {
- getOfflineProfile(playerName).removeXp(getNonChildSkillType(skillType), xp);
- }
- /**
- * 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);
- }
- /**
- * 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().getXPtoNextLevel(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().getXPtoNextLevel(level, getFormulaType(formulaType));
- }
- /**
- * 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)
- {
- mcMMOPlayer.applyXpGain(skillType, ExperienceConfig.getInstance().getXp(skillType, bs.getType()), XPGainReason.PVE, XPGainSource.SELF);
- }
- }
- }
- }
- /**
- * 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)
- {
- mcMMOPlayer.applyXpGain(skillType, ExperienceConfig.getInstance().getXp(skillType, bs.getType()), XPGainReason.PVE, XPGainSource.SELF);
- }
- }
- }
- /**
- * 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)
- {
- mcMMOPlayer.applyXpGain(skillType, ExperienceConfig.getInstance().getXp(skillType, blockState.getType()), XPGainReason.PVE, XPGainSource.SELF);
- }
- }
- }
- /**
- * 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)
- {
- mcMMOPlayer.applyXpGain(skillType, ExperienceConfig.getInstance().getXp(skillType, blockState.getType()), XPGainReason.PVE, XPGainSource.SELF);
- }
- }
- // Utility methods follow.
- private static void addOfflineXP(UUID playerUniqueId, PrimarySkillType skill, int XP) {
- PlayerProfile profile = getOfflineProfile(playerUniqueId);
- profile.addXp(skill, XP);
- profile.save(true);
- }
- @Deprecated
- private static void addOfflineXP(String playerName, PrimarySkillType skill, int XP) {
- PlayerProfile profile = getOfflineProfile(playerName);
- profile.addXp(skill, XP);
- profile.scheduleAsyncSave();
- }
- private static PlayerProfile getOfflineProfile(UUID uuid) throws InvalidPlayerException {
- OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(uuid);
- String playerName = offlinePlayer.getName();
- PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(uuid, playerName);
- if (!profile.isLoaded()) {
- throw new InvalidPlayerException();
- }
- return profile;
- }
- @Deprecated
- private static PlayerProfile getOfflineProfile(String playerName) throws InvalidPlayerException {
- OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(playerName);
- UUID uuid = offlinePlayer.getUniqueId();
- PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(uuid, playerName);
- if (!profile.isLoaded()) {
- throw new InvalidPlayerException();
- }
- return profile;
- }
- private static PrimarySkillType getSkillType(String skillType) throws InvalidSkillException {
- PrimarySkillType skill = mcMMO.p.getSkillTools().matchSkill(skillType);
- if (skill == null) {
- throw new InvalidSkillException();
- }
- return skill;
- }
- private static PrimarySkillType getNonChildSkillType(String skillType) throws InvalidSkillException, UnsupportedOperationException {
- PrimarySkillType skill = getSkillType(skillType);
- if (mcMMO.p.getSkillTools().isChildSkill(skill)) {
- throw new UnsupportedOperationException("Child skills do not have XP");
- }
- return skill;
- }
- private static XPGainReason getXPGainReason(String reason) throws InvalidXPGainReasonException {
- XPGainReason xpGainReason = XPGainReason.getXPGainReason(reason);
- if (xpGainReason == null) {
- throw new InvalidXPGainReasonException();
- }
- return xpGainReason;
- }
- private static FormulaType getFormulaType(String formula) throws InvalidFormulaTypeException {
- FormulaType formulaType = FormulaType.getFormulaType(formula);
- if (formulaType == null) {
- throw new InvalidFormulaTypeException();
- }
- return formulaType;
- }
- /**
- * @deprecated Use UserManager::getPlayer(Player player) instead
- * @param player target player
- * @return McMMOPlayer for that player if the profile is loaded, otherwise null
- * @throws McMMOPlayerNotFoundException
- */
- @Deprecated
- private static McMMOPlayer getPlayer(Player player) throws McMMOPlayerNotFoundException {
- if (!UserManager.hasPlayerDataKey(player)) {
- throw new McMMOPlayerNotFoundException(player);
- }
- return UserManager.getPlayer(player);
- }
- }
|