ExperienceAPI.java 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225
  1. package com.gmail.nossr50.api;
  2. import com.gmail.nossr50.api.exceptions.*;
  3. import com.gmail.nossr50.config.experience.ExperienceConfig;
  4. import com.gmail.nossr50.datatypes.experience.FormulaType;
  5. import com.gmail.nossr50.datatypes.experience.XPGainReason;
  6. import com.gmail.nossr50.datatypes.experience.XPGainSource;
  7. import com.gmail.nossr50.datatypes.player.McMMOPlayer;
  8. import com.gmail.nossr50.datatypes.player.PlayerProfile;
  9. import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
  10. import com.gmail.nossr50.mcMMO;
  11. import com.gmail.nossr50.skills.child.FamilyTree;
  12. import com.gmail.nossr50.util.player.UserManager;
  13. import com.gmail.nossr50.util.skills.CombatUtils;
  14. import org.bukkit.Bukkit;
  15. import org.bukkit.OfflinePlayer;
  16. import org.bukkit.block.BlockState;
  17. import org.bukkit.entity.LivingEntity;
  18. import org.bukkit.entity.Player;
  19. import java.util.ArrayList;
  20. import java.util.Set;
  21. import java.util.UUID;
  22. public final class ExperienceAPI {
  23. private ExperienceAPI() {}
  24. /**
  25. * Returns whether given string is a valid type of skill suitable for the
  26. * other API calls in this class.
  27. * </br>
  28. * This function is designed for API usage.
  29. *
  30. * @param skillType A string that may or may not be a skill
  31. * @return true if this is a valid mcMMO skill
  32. */
  33. public static boolean isValidSkillType(String skillType) {
  34. return mcMMO.p.getSkillTools().matchSkill(skillType) != null;
  35. }
  36. /**
  37. * Start the task that gives combat XP.
  38. * Processes combat XP like mcMMO normally would, so mcMMO will check whether or not the entity should reward XP when giving out the XP
  39. *
  40. * @param mcMMOPlayer The attacking player
  41. * @param target The defending entity
  42. * @param primarySkillType The skill being used
  43. * @param multiplier final XP result will be multiplied by this
  44. * @deprecated Draft API
  45. */
  46. @Deprecated
  47. public static void addCombatXP(McMMOPlayer mcMMOPlayer, LivingEntity target, PrimarySkillType primarySkillType, double multiplier) {
  48. CombatUtils.processCombatXP(mcMMOPlayer, target, primarySkillType, multiplier);
  49. }
  50. /**
  51. * Start the task that gives combat XP.
  52. * Processes combat XP like mcMMO normally would, so mcMMO will check whether or not the entity should reward XP when giving out the XP
  53. *
  54. * @param mcMMOPlayer The attacking player
  55. * @param target The defending entity
  56. * @param primarySkillType The skill being used
  57. * @deprecated Draft API
  58. */
  59. @Deprecated
  60. public static void addCombatXP(McMMOPlayer mcMMOPlayer, LivingEntity target, PrimarySkillType primarySkillType) {
  61. CombatUtils.processCombatXP(mcMMOPlayer, target, primarySkillType);
  62. }
  63. /**
  64. * Returns whether the given skill type string is both valid and not a
  65. * child skill. (Child skills have no XP of their own, and their level is
  66. * derived from the parent(s).)
  67. * </br>
  68. * This function is designed for API usage.
  69. *
  70. * @param skillType the skill to check
  71. * @return true if this is a valid, non-child mcMMO skill
  72. */
  73. public static boolean isNonChildSkill(String skillType) {
  74. PrimarySkillType skill = mcMMO.p.getSkillTools().matchSkill(skillType);
  75. return skill != null && !mcMMO.p.getSkillTools().isChildSkill(skill);
  76. }
  77. @Deprecated
  78. public static void addRawXP(Player player, String skillType, int XP) {
  79. addRawXP(player, skillType, (float) XP);
  80. }
  81. /**
  82. * Adds raw XP to the player.
  83. * </br>
  84. * This function is designed for API usage.
  85. *
  86. * @param player The player to add XP to
  87. * @param skillType The skill to add XP to
  88. * @param XP The amount of XP to add
  89. *
  90. * @throws InvalidSkillException if the given skill is not valid
  91. */
  92. @Deprecated
  93. public static void addRawXP(Player player, String skillType, float XP) {
  94. addRawXP(player, skillType, XP, "UNKNOWN");
  95. }
  96. /**
  97. * Adds raw XP to the player.
  98. * </br>
  99. * This function is designed for API usage.
  100. *
  101. * @param player The player to add XP to
  102. * @param skillType The skill to add XP to
  103. * @param XP The amount of XP to add
  104. * @param xpGainReason The reason to gain XP
  105. *
  106. * @throws InvalidSkillException if the given skill is not valid
  107. * @throws InvalidXPGainReasonException if the given xpGainReason is not valid
  108. */
  109. public static void addRawXP(Player player, String skillType, float XP, String xpGainReason) {
  110. addRawXP(player, skillType, XP, xpGainReason, false);
  111. }
  112. /**
  113. * Adds raw XP to the player.
  114. * </br>
  115. * This function is designed for API usage.
  116. *
  117. * @param player The player to add XP to
  118. * @param skillType The skill to add XP to
  119. * @param XP The amount of XP to add
  120. * @param xpGainReason The reason to gain XP
  121. * @param isUnshared true if the XP cannot be shared with party members
  122. *
  123. * @throws InvalidSkillException if the given skill is not valid
  124. * @throws InvalidXPGainReasonException if the given xpGainReason is not valid
  125. */
  126. public static void addRawXP(Player player, String skillType, float XP, String xpGainReason, boolean isUnshared) {
  127. if (isUnshared) {
  128. getPlayer(player).beginUnsharedXpGain(getSkillType(skillType), XP, getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
  129. return;
  130. }
  131. getPlayer(player).applyXpGain(getSkillType(skillType), XP, getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
  132. }
  133. /**
  134. * Adds raw XP to an offline player.
  135. * </br>
  136. * This function is designed for API usage.
  137. *
  138. * @deprecated We're using float for our XP values now
  139. * replaced by {@link #addRawXPOffline(String playerName, String skillType, float XP)}
  140. */
  141. @Deprecated
  142. public static void addRawXPOffline(String playerName, String skillType, int XP) {
  143. addRawXPOffline(playerName, skillType, (float) XP);
  144. }
  145. /**
  146. * Adds raw XP to an offline player.
  147. * </br>
  148. * This function is designed for API usage.
  149. *
  150. * @deprecated We're using uuids to get an offline player
  151. * replaced by {@link #addRawXPOffline(UUID uuid, String skillType, float XP)}
  152. *
  153. * @param playerName The player to add XP to
  154. * @param skillType The skill to add XP to
  155. * @param XP The amount of XP to add
  156. *
  157. * @throws InvalidSkillException if the given skill is not valid
  158. * @throws InvalidPlayerException if the given player does not exist in the database
  159. */
  160. @Deprecated
  161. public static void addRawXPOffline(String playerName, String skillType, float XP) {
  162. addOfflineXP(playerName, getSkillType(skillType), (int) Math.floor(XP));
  163. }
  164. /**
  165. * Adds raw XP to an offline player.
  166. * </br>
  167. * This function is designed for API usage.
  168. *
  169. * @param uuid The UUID of player to add XP to
  170. * @param skillType The skill to add XP to
  171. * @param XP The amount of XP to add
  172. *
  173. * @throws InvalidSkillException if the given skill is not valid
  174. * @throws InvalidPlayerException if the given player does not exist in the database
  175. */
  176. public static void addRawXPOffline(UUID uuid, String skillType, float XP) {
  177. addOfflineXP(uuid, getSkillType(skillType), (int) Math.floor(XP));
  178. }
  179. /**
  180. * Adds XP to the player, calculates for XP Rate only.
  181. * </br>
  182. * This function is designed for API usage.
  183. *
  184. * @param player The player to add XP to
  185. * @param skillType The skill to add XP to
  186. * @param XP The amount of XP to add
  187. *
  188. * @throws InvalidSkillException if the given skill is not valid
  189. */
  190. @Deprecated
  191. public static void addMultipliedXP(Player player, String skillType, int XP) {
  192. addMultipliedXP(player, skillType, XP, "UNKNOWN");
  193. }
  194. /**
  195. * Adds XP to the player, calculates for XP Rate only.
  196. * </br>
  197. * This function is designed for API usage.
  198. *
  199. * @param player The player to add XP to
  200. * @param skillType The skill to add XP to
  201. * @param XP The amount of XP to add
  202. * @param xpGainReason The reason to gain XP
  203. *
  204. * @throws InvalidSkillException if the given skill is not valid
  205. * @throws InvalidXPGainReasonException if the given xpGainReason is not valid
  206. */
  207. public static void addMultipliedXP(Player player, String skillType, int XP, String xpGainReason) {
  208. getPlayer(player).applyXpGain(getSkillType(skillType), (int) (XP * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()), getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
  209. }
  210. /**
  211. * Adds XP to an offline player, calculates for XP Rate only.
  212. * </br>
  213. * This function is designed for API usage.
  214. *
  215. * @param playerName The player to add XP to
  216. * @param skillType The skill to add XP to
  217. * @param XP The amount of XP to add
  218. *
  219. * @throws InvalidSkillException if the given skill is not valid
  220. * @throws InvalidPlayerException if the given player does not exist in the database
  221. */
  222. @Deprecated
  223. public static void addMultipliedXPOffline(String playerName, String skillType, int XP) {
  224. addOfflineXP(playerName, getSkillType(skillType), (int) (XP * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()));
  225. }
  226. /**
  227. * Adds XP to the player, calculates for XP Rate and skill modifier.
  228. * </br>
  229. * This function is designed for API usage.
  230. *
  231. * @param player The player to add XP to
  232. * @param skillType The skill to add XP to
  233. * @param XP The amount of XP to add
  234. *
  235. * @throws InvalidSkillException if the given skill is not valid
  236. */
  237. @Deprecated
  238. public static void addModifiedXP(Player player, String skillType, int XP) {
  239. addModifiedXP(player, skillType, XP, "UNKNOWN");
  240. }
  241. /**
  242. * Adds XP to the player, calculates for XP Rate and skill modifier.
  243. * </br>
  244. * This function is designed for API usage.
  245. *
  246. * @param player The player to add XP to
  247. * @param skillType The skill to add XP to
  248. * @param XP The amount of XP to add
  249. * @param xpGainReason The reason to gain XP
  250. *
  251. * @throws InvalidSkillException if the given skill is not valid
  252. * @throws InvalidXPGainReasonException if the given xpGainReason is not valid
  253. */
  254. public static void addModifiedXP(Player player, String skillType, int XP, String xpGainReason) {
  255. addModifiedXP(player, skillType, XP, xpGainReason, false);
  256. }
  257. /**
  258. * Adds XP to the player, calculates for XP Rate and skill modifier.
  259. * </br>
  260. * This function is designed for API usage.
  261. *
  262. * @param player The player to add XP to
  263. * @param skillType The skill to add XP to
  264. * @param XP The amount of XP to add
  265. * @param xpGainReason The reason to gain XP
  266. * @param isUnshared true if the XP cannot be shared with party members
  267. *
  268. * @throws InvalidSkillException if the given skill is not valid
  269. * @throws InvalidXPGainReasonException if the given xpGainReason is not valid
  270. */
  271. public static void addModifiedXP(Player player, String skillType, int XP, String xpGainReason, boolean isUnshared) {
  272. PrimarySkillType skill = getSkillType(skillType);
  273. if (isUnshared) {
  274. getPlayer(player).beginUnsharedXpGain(skill,
  275. (int) (XP / ExperienceConfig.getInstance().getFormulaSkillModifier(skill) * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()), getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
  276. return;
  277. }
  278. getPlayer(player).applyXpGain(skill, (int) (XP / ExperienceConfig.getInstance().getFormulaSkillModifier(skill) * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()), getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
  279. }
  280. /**
  281. * Adds XP to an offline player, calculates for XP Rate and skill modifier.
  282. * </br>
  283. * This function is designed for API usage.
  284. *
  285. * @param playerName The player to add XP to
  286. * @param skillType The skill to add XP to
  287. * @param XP The amount of XP to add
  288. *
  289. * @throws InvalidSkillException if the given skill is not valid
  290. * @throws InvalidPlayerException if the given player does not exist in the database
  291. */
  292. @Deprecated
  293. public static void addModifiedXPOffline(String playerName, String skillType, int XP) {
  294. PrimarySkillType skill = getSkillType(skillType);
  295. addOfflineXP(playerName, skill, (int) (XP / ExperienceConfig.getInstance().getFormulaSkillModifier(skill) * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()));
  296. }
  297. /**
  298. * Adds XP to the player, calculates for XP Rate, skill modifiers, perks, child skills,
  299. * and party sharing.
  300. * </br>
  301. * This function is designed for API usage.
  302. *
  303. * @param player The player to add XP to
  304. * @param skillType The skill to add XP to
  305. * @param XP The amount of XP to add
  306. *
  307. * @throws InvalidSkillException if the given skill is not valid
  308. */
  309. @Deprecated
  310. public static void addXP(Player player, String skillType, int XP) {
  311. addXP(player, skillType, XP, "UNKNOWN");
  312. }
  313. /**
  314. * Adds XP to the player, calculates for XP Rate, skill modifiers, perks, child skills,
  315. * and party sharing.
  316. * </br>
  317. * This function is designed for API usage.
  318. *
  319. * @param player The player to add XP to
  320. * @param skillType The skill to add XP to
  321. * @param XP The amount of XP to add
  322. * @param xpGainReason The reason to gain XP
  323. *
  324. * @throws InvalidSkillException if the given skill is not valid
  325. * @throws InvalidXPGainReasonException if the given xpGainReason is not valid
  326. */
  327. public static void addXP(Player player, String skillType, int XP, String xpGainReason) {
  328. addXP(player, skillType, XP, xpGainReason, false);
  329. }
  330. /**
  331. * Adds XP to the player, calculates for XP Rate, skill modifiers, perks, child skills,
  332. * and party sharing.
  333. * </br>
  334. * This function is designed for API usage.
  335. *
  336. * @param player The player to add XP to
  337. * @param skillType The skill to add XP to
  338. * @param XP The amount of XP to add
  339. * @param xpGainReason The reason to gain XP
  340. * @param isUnshared true if the XP cannot be shared with party members
  341. *
  342. * @throws InvalidSkillException if the given skill is not valid
  343. * @throws InvalidXPGainReasonException if the given xpGainReason is not valid
  344. */
  345. public static void addXP(Player player, String skillType, int XP, String xpGainReason, boolean isUnshared) {
  346. if (isUnshared) {
  347. getPlayer(player).beginUnsharedXpGain(getSkillType(skillType), XP, getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
  348. return;
  349. }
  350. getPlayer(player).beginXpGain(getSkillType(skillType), XP, getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
  351. }
  352. /**
  353. * Get the amount of XP a player has in a specific skill.
  354. * </br>
  355. * This function is designed for API usage.
  356. *
  357. * @param player The player to get XP for
  358. * @param skillType The skill to get XP for
  359. * @return the amount of XP in a given skill
  360. *
  361. * @throws InvalidSkillException if the given skill is not valid
  362. * @throws UnsupportedOperationException if the given skill is a child skill
  363. */
  364. public static int getXP(Player player, String skillType) {
  365. return getPlayer(player).getSkillXpLevel(getNonChildSkillType(skillType));
  366. }
  367. /**
  368. * Get the amount of XP an offline player has in a specific skill.
  369. * </br>
  370. * This function is designed for API usage.
  371. *
  372. * @param playerName The player to get XP for
  373. * @param skillType The skill to get XP for
  374. * @return the amount of XP in a given skill
  375. *
  376. * @throws InvalidSkillException if the given skill is not valid
  377. * @throws InvalidPlayerException if the given player does not exist in the database
  378. * @throws UnsupportedOperationException if the given skill is a child skill
  379. */
  380. @Deprecated
  381. public static int getOfflineXP(String playerName, String skillType) {
  382. return getOfflineProfile(playerName).getSkillXpLevel(getNonChildSkillType(skillType));
  383. }
  384. /**
  385. * Get the amount of XP an offline player has in a specific skill.
  386. * </br>
  387. * This function is designed for API usage.
  388. *
  389. * @param uuid The player to get XP for
  390. * @param skillType The skill to get XP for
  391. * @return the amount of XP in a given skill
  392. *
  393. * @throws InvalidSkillException if the given skill is not valid
  394. * @throws InvalidPlayerException if the given player does not exist in the database
  395. * @throws UnsupportedOperationException if the given skill is a child skill
  396. */
  397. public static int getOfflineXP(UUID uuid, String skillType) {
  398. return getOfflineProfile(uuid).getSkillXpLevel(getNonChildSkillType(skillType));
  399. }
  400. /**
  401. * Get the raw amount of XP a player has in a specific skill.
  402. * </br>
  403. * This function is designed for API usage.
  404. *
  405. * @param player The player to get XP for
  406. * @param skillType The skill to get XP for
  407. * @return the amount of XP in a given skill
  408. *
  409. * @throws InvalidSkillException if the given skill is not valid
  410. * @throws UnsupportedOperationException if the given skill is a child skill
  411. */
  412. public static float getXPRaw(Player player, String skillType) {
  413. return getPlayer(player).getSkillXpLevelRaw(getNonChildSkillType(skillType));
  414. }
  415. /**
  416. * Get the raw amount of XP an offline player has in a specific skill.
  417. * </br>
  418. * This function is designed for API usage.
  419. *
  420. * @param playerName The player to get XP for
  421. * @param skillType The skill to get XP for
  422. * @return the amount of XP in a given skill
  423. *
  424. * @throws InvalidSkillException if the given skill is not valid
  425. * @throws InvalidPlayerException if the given player does not exist in the database
  426. * @throws UnsupportedOperationException if the given skill is a child skill
  427. */
  428. @Deprecated
  429. public static float getOfflineXPRaw(String playerName, String skillType) {
  430. return getOfflineProfile(playerName).getSkillXpLevelRaw(getNonChildSkillType(skillType));
  431. }
  432. /**
  433. * Get the raw amount of XP an offline player has in a specific skill.
  434. * </br>
  435. * This function is designed for API usage.
  436. *
  437. * @param uuid The player to get XP for
  438. * @param skillType The skill to get XP for
  439. * @return the amount of XP in a given skill
  440. *
  441. * @throws InvalidSkillException if the given skill is not valid
  442. * @throws InvalidPlayerException if the given player does not exist in the database
  443. * @throws UnsupportedOperationException if the given skill is a child skill
  444. */
  445. public static float getOfflineXPRaw(UUID uuid, String skillType) {
  446. return getOfflineProfile(uuid).getSkillXpLevelRaw(getNonChildSkillType(skillType));
  447. }
  448. /**
  449. * Get the total amount of XP needed to reach the next level.
  450. * </br>
  451. * This function is designed for API usage.
  452. *
  453. * @param player The player to get the XP amount for
  454. * @param skillType The skill to get the XP amount for
  455. * @return the total amount of XP needed to reach the next level
  456. *
  457. * @throws InvalidSkillException if the given skill is not valid
  458. * @throws UnsupportedOperationException if the given skill is a child skill
  459. */
  460. public static int getXPToNextLevel(Player player, String skillType) {
  461. return getPlayer(player).getXpToLevel(getNonChildSkillType(skillType));
  462. }
  463. /**
  464. * Get the total amount of XP an offline player needs to reach the next level.
  465. * </br>
  466. * This function is designed for API usage.
  467. *
  468. * @param playerName The player to get XP for
  469. * @param skillType The skill to get XP for
  470. * @return the total amount of XP needed to reach the next level
  471. *
  472. * @throws InvalidSkillException if the given skill is not valid
  473. * @throws InvalidPlayerException if the given player does not exist in the database
  474. * @throws UnsupportedOperationException if the given skill is a child skill
  475. */
  476. @Deprecated
  477. public static int getOfflineXPToNextLevel(String playerName, String skillType) {
  478. return getOfflineProfile(playerName).getXpToLevel(getNonChildSkillType(skillType));
  479. }
  480. /**
  481. * Get the total amount of XP an offline player needs to reach the next level.
  482. * </br>
  483. * This function is designed for API usage.
  484. *
  485. * @param uuid The player to get XP for
  486. * @param skillType The skill to get XP for
  487. * @return the total amount of XP needed to reach the next level
  488. *
  489. * @throws InvalidSkillException if the given skill is not valid
  490. * @throws InvalidPlayerException if the given player does not exist in the database
  491. * @throws UnsupportedOperationException if the given skill is a child skill
  492. */
  493. public static int getOfflineXPToNextLevel(UUID uuid, String skillType) {
  494. return getOfflineProfile(uuid).getXpToLevel(getNonChildSkillType(skillType));
  495. }
  496. /**
  497. * Get the amount of XP remaining until the next level.
  498. * </br>
  499. * This function is designed for API usage.
  500. *
  501. * @param player The player to get the XP amount for
  502. * @param skillType The skill to get the XP amount for
  503. * @return the amount of XP remaining until the next level
  504. *
  505. * @throws InvalidSkillException if the given skill is not valid
  506. * @throws UnsupportedOperationException if the given skill is a child skill
  507. */
  508. public static int getXPRemaining(Player player, String skillType) {
  509. PrimarySkillType skill = getNonChildSkillType(skillType);
  510. PlayerProfile profile = getPlayer(player).getProfile();
  511. return profile.getXpToLevel(skill) - profile.getSkillXpLevel(skill);
  512. }
  513. /**
  514. * Get the amount of XP an offline player has left before leveling up.
  515. * </br>
  516. * This function is designed for API usage.
  517. *
  518. * @param playerName The player to get XP for
  519. * @param skillType The skill to get XP for
  520. * @return the amount of XP needed to reach the next level
  521. *
  522. * @throws InvalidSkillException if the given skill is not valid
  523. * @throws InvalidPlayerException if the given player does not exist in the database
  524. * @throws UnsupportedOperationException if the given skill is a child skill
  525. */
  526. @Deprecated
  527. public static int getOfflineXPRemaining(String playerName, String skillType) {
  528. PrimarySkillType skill = getNonChildSkillType(skillType);
  529. PlayerProfile profile = getOfflineProfile(playerName);
  530. return profile.getXpToLevel(skill) - profile.getSkillXpLevel(skill);
  531. }
  532. /**
  533. * Get the amount of XP an offline player has left before leveling up.
  534. * </br>
  535. * This function is designed for API usage.
  536. *
  537. * @param uuid The player to get XP for
  538. * @param skillType The skill to get XP for
  539. * @return the amount of XP needed to reach the next level
  540. *
  541. * @throws InvalidSkillException if the given skill is not valid
  542. * @throws InvalidPlayerException if the given player does not exist in the database
  543. * @throws UnsupportedOperationException if the given skill is a child skill
  544. */
  545. public static float getOfflineXPRemaining(UUID uuid, String skillType) {
  546. PrimarySkillType skill = getNonChildSkillType(skillType);
  547. PlayerProfile profile = getOfflineProfile(uuid);
  548. return profile.getXpToLevel(skill) - profile.getSkillXpLevelRaw(skill);
  549. }
  550. /**
  551. * Add levels to a skill.
  552. * </br>
  553. * This function is designed for API usage.
  554. *
  555. * @param player The player to add levels to
  556. * @param skillType Type of skill to add levels to
  557. * @param levels Number of levels to add
  558. *
  559. * @throws InvalidSkillException if the given skill is not valid
  560. */
  561. public static void addLevel(Player player, String skillType, int levels) {
  562. getPlayer(player).addLevels(getSkillType(skillType), levels);
  563. }
  564. /**
  565. * Add levels to a skill for an offline player.
  566. * </br>
  567. * This function is designed for API usage.
  568. *
  569. * @param playerName The player to add levels to
  570. * @param skillType Type of skill to add levels to
  571. * @param levels Number of levels to add
  572. *
  573. * @throws InvalidSkillException if the given skill is not valid
  574. * @throws InvalidPlayerException if the given player does not exist in the database
  575. */
  576. @Deprecated
  577. public static void addLevelOffline(String playerName, String skillType, int levels) {
  578. PlayerProfile profile = getOfflineProfile(playerName);
  579. PrimarySkillType skill = getSkillType(skillType);
  580. if (mcMMO.p.getSkillTools().isChildSkill(skill)) {
  581. Set<PrimarySkillType> parentSkills = FamilyTree.getParents(skill);
  582. for (PrimarySkillType parentSkill : parentSkills) {
  583. profile.addLevels(parentSkill, (levels / parentSkills.size()));
  584. }
  585. profile.scheduleAsyncSave();
  586. return;
  587. }
  588. profile.addLevels(skill, levels);
  589. profile.scheduleAsyncSave();
  590. }
  591. /**
  592. * Add levels to a skill for an offline player.
  593. * </br>
  594. * This function is designed for API usage.
  595. *
  596. * @param uuid The player to add levels to
  597. * @param skillType Type of skill to add levels to
  598. * @param levels Number of levels to add
  599. *
  600. * @throws InvalidSkillException if the given skill is not valid
  601. * @throws InvalidPlayerException if the given player does not exist in the database
  602. */
  603. public static void addLevelOffline(UUID uuid, String skillType, int levels) {
  604. PlayerProfile profile = getOfflineProfile(uuid);
  605. PrimarySkillType skill = getSkillType(skillType);
  606. if (mcMMO.p.getSkillTools().isChildSkill(skill)) {
  607. Set<PrimarySkillType> parentSkills = FamilyTree.getParents(skill);
  608. for (PrimarySkillType parentSkill : parentSkills) {
  609. profile.addLevels(parentSkill, (levels / parentSkills.size()));
  610. }
  611. profile.scheduleAsyncSave();
  612. return;
  613. }
  614. profile.addLevels(skill, levels);
  615. profile.scheduleAsyncSave();
  616. }
  617. /**
  618. * Get the level a player has in a specific skill.
  619. * </br>
  620. * This function is designed for API usage.
  621. *
  622. * @param player The player to get the level for
  623. * @param skillType The skill to get the level for
  624. * @return the level of a given skill
  625. *
  626. * @throws InvalidSkillException if the given skill is not valid
  627. * @deprecated Use getLevel(Player player, PrimarySkillType skillType) instead
  628. */
  629. @Deprecated
  630. public static int getLevel(Player player, String skillType) {
  631. return getPlayer(player).getSkillLevel(getSkillType(skillType));
  632. }
  633. /**
  634. * Get the level a player has in a specific skill.
  635. * </br>
  636. * This function is designed for API usage.
  637. *
  638. * @param player The player to get the level for
  639. * @param skillType The skill to get the level for
  640. * @return the level of a given skill
  641. *
  642. * @throws InvalidSkillException if the given skill is not valid
  643. */
  644. public static int getLevel(Player player, PrimarySkillType skillType) {
  645. return getPlayer(player).getSkillLevel(skillType);
  646. }
  647. /**
  648. * Get the level an offline player has in a specific skill.
  649. * </br>
  650. * This function is designed for API usage.
  651. *
  652. * @param playerName The player to get the level for
  653. * @param skillType The skill to get the level for
  654. * @return the level of a given skill
  655. *
  656. * @throws InvalidSkillException if the given skill is not valid
  657. * @throws InvalidPlayerException if the given player does not exist in the database
  658. */
  659. public static int getLevelOffline(String playerName, String skillType) {
  660. return getOfflineProfile(playerName).getSkillLevel(getSkillType(skillType));
  661. }
  662. /**
  663. * Get the level an offline player has in a specific skill.
  664. * </br>
  665. * This function is designed for API usage.
  666. *
  667. * @param uuid The player to get the level for
  668. * @param skillType The skill to get the level for
  669. * @return the level of a given skill
  670. *
  671. * @throws InvalidSkillException if the given skill is not valid
  672. * @throws InvalidPlayerException if the given player does not exist in the database
  673. */
  674. public static int getLevelOffline(UUID uuid, String skillType) {
  675. return getOfflineProfile(uuid).getSkillLevel(getSkillType(skillType));
  676. }
  677. /**
  678. * Gets the power level of a player.
  679. * </br>
  680. * This function is designed for API usage.
  681. *
  682. * @param player The player to get the power level for
  683. * @return the power level of the player
  684. */
  685. public static int getPowerLevel(Player player) {
  686. return getPlayer(player).getPowerLevel();
  687. }
  688. /**
  689. * Gets the power level of an offline player.
  690. * </br>
  691. * This function is designed for API usage.
  692. *
  693. * @param playerName The player to get the power level for
  694. * @return the power level of the player
  695. *
  696. * @throws InvalidPlayerException if the given player does not exist in the database
  697. */
  698. @Deprecated
  699. public static int getPowerLevelOffline(String playerName) {
  700. int powerLevel = 0;
  701. PlayerProfile profile = getOfflineProfile(playerName);
  702. for (PrimarySkillType type : mcMMO.p.getSkillTools().NON_CHILD_SKILLS) {
  703. powerLevel += profile.getSkillLevel(type);
  704. }
  705. return powerLevel;
  706. }
  707. /**
  708. * Gets the power level of an offline player.
  709. * </br>
  710. * This function is designed for API usage.
  711. *
  712. * @param uuid The player to get the power level for
  713. * @return the power level of the player
  714. *
  715. * @throws InvalidPlayerException if the given player does not exist in the database
  716. */
  717. public static int getPowerLevelOffline(UUID uuid) {
  718. int powerLevel = 0;
  719. PlayerProfile profile = getOfflineProfile(uuid);
  720. for (PrimarySkillType type : mcMMO.p.getSkillTools().NON_CHILD_SKILLS) {
  721. powerLevel += profile.getSkillLevel(type);
  722. }
  723. return powerLevel;
  724. }
  725. /**
  726. * Get the level cap of a specific skill.
  727. * </br>
  728. * This function is designed for API usage.
  729. *
  730. * @param skillType The skill to get the level cap for
  731. * @return the level cap of a given skill
  732. *
  733. * @throws InvalidSkillException if the given skill is not valid
  734. */
  735. public static int getLevelCap(String skillType) {
  736. return mcMMO.p.getSkillTools().getLevelCap(getSkillType(skillType));
  737. }
  738. /**
  739. * Get the power level cap.
  740. * </br>
  741. * This function is designed for API usage.
  742. *
  743. * @return the overall power level cap
  744. */
  745. public static int getPowerLevelCap() {
  746. return mcMMO.p.getGeneralConfig().getPowerLevelCap();
  747. }
  748. /**
  749. * Get the position on the leaderboard of a player.
  750. * </br>
  751. * This function is designed for API usage.
  752. *
  753. * @param playerName The name of the player to check
  754. * @param skillType The skill to check
  755. *
  756. * @throws InvalidSkillException if the given skill is not valid
  757. * @throws InvalidPlayerException if the given player does not exist in the database
  758. * @throws UnsupportedOperationException if the given skill is a child skill
  759. *
  760. * @return the position on the leaderboard
  761. */
  762. @Deprecated
  763. public static int getPlayerRankSkill(String playerName, String skillType) {
  764. return mcMMO.getDatabaseManager().readRank(mcMMO.p.getServer().getOfflinePlayer(playerName).getName()).get(getNonChildSkillType(skillType));
  765. }
  766. /**
  767. * Get the position on the leaderboard of a player.
  768. * </br>
  769. * This function is designed for API usage.
  770. *
  771. * @param uuid The name of the player to check
  772. * @param skillType The skill to check
  773. *
  774. * @throws InvalidSkillException if the given skill is not valid
  775. * @throws InvalidPlayerException if the given player does not exist in the database
  776. * @throws UnsupportedOperationException if the given skill is a child skill
  777. *
  778. * @return the position on the leaderboard
  779. */
  780. public static int getPlayerRankSkill(UUID uuid, String skillType) {
  781. return mcMMO.getDatabaseManager().readRank(mcMMO.p.getServer().getOfflinePlayer(uuid).getName()).get(getNonChildSkillType(skillType));
  782. }
  783. /**
  784. * Get the position on the power level leaderboard of a player.
  785. * </br>
  786. * This function is designed for API usage.
  787. *
  788. * @param playerName The name of the player to check
  789. *
  790. * @throws InvalidPlayerException if the given player does not exist in the database
  791. *
  792. * @return the position on the power level leaderboard
  793. */
  794. @Deprecated
  795. public static int getPlayerRankOverall(String playerName) {
  796. return mcMMO.getDatabaseManager().readRank(mcMMO.p.getServer().getOfflinePlayer(playerName).getName()).get(null);
  797. }
  798. /**
  799. * Get the position on the power level leaderboard of a player.
  800. * </br>
  801. * This function is designed for API usage.
  802. *
  803. * @param uuid The name of the player to check
  804. *
  805. * @throws InvalidPlayerException if the given player does not exist in the database
  806. *
  807. * @return the position on the power level leaderboard
  808. */
  809. public static int getPlayerRankOverall(UUID uuid) {
  810. return mcMMO.getDatabaseManager().readRank(mcMMO.p.getServer().getOfflinePlayer(uuid).getName()).get(null);
  811. }
  812. /**
  813. * Sets the level of a player in a specific skill type.
  814. * </br>
  815. * This function is designed for API usage.
  816. *
  817. * @param player The player to set the level of
  818. * @param skillType The skill to set the level for
  819. * @param skillLevel The value to set the level to
  820. *
  821. * @throws InvalidSkillException if the given skill is not valid
  822. */
  823. public static void setLevel(Player player, String skillType, int skillLevel) {
  824. getPlayer(player).modifySkill(getSkillType(skillType), skillLevel);
  825. }
  826. /**
  827. * Sets the level of an offline player in a specific skill type.
  828. * </br>
  829. * This function is designed for API usage.
  830. *
  831. * @param playerName The player to set the level of
  832. * @param skillType The skill to set the level for
  833. * @param skillLevel The value to set the level to
  834. *
  835. * @throws InvalidSkillException if the given skill is not valid
  836. * @throws InvalidPlayerException if the given player does not exist in the database
  837. */
  838. @Deprecated
  839. public static void setLevelOffline(String playerName, String skillType, int skillLevel) {
  840. getOfflineProfile(playerName).modifySkill(getSkillType(skillType), skillLevel);
  841. }
  842. /**
  843. * Sets the level of an offline player in a specific skill type.
  844. * </br>
  845. * This function is designed for API usage.
  846. *
  847. * @param uuid The player to set the level of
  848. * @param skillType The skill to set the level for
  849. * @param skillLevel The value to set the level to
  850. *
  851. * @throws InvalidSkillException if the given skill is not valid
  852. * @throws InvalidPlayerException if the given player does not exist in the database
  853. */
  854. public static void setLevelOffline(UUID uuid, String skillType, int skillLevel) {
  855. getOfflineProfile(uuid).modifySkill(getSkillType(skillType), skillLevel);
  856. }
  857. /**
  858. * Sets the XP of a player in a specific skill type.
  859. * </br>
  860. * This function is designed for API usage.
  861. *
  862. * @param player The player to set the XP of
  863. * @param skillType The skill to set the XP for
  864. * @param newValue The value to set the XP to
  865. *
  866. * @throws InvalidSkillException if the given skill is not valid
  867. * @throws UnsupportedOperationException if the given skill is a child skill
  868. */
  869. public static void setXP(Player player, String skillType, int newValue) {
  870. getPlayer(player).setSkillXpLevel(getNonChildSkillType(skillType), newValue);
  871. }
  872. /**
  873. * Sets the XP of an offline player in a specific skill type.
  874. * </br>
  875. * This function is designed for API usage.
  876. *
  877. * @param playerName The player to set the XP of
  878. * @param skillType The skill to set the XP for
  879. * @param newValue The value to set the XP to
  880. *
  881. * @throws InvalidSkillException if the given skill is not valid
  882. * @throws InvalidPlayerException if the given player does not exist in the database
  883. * @throws UnsupportedOperationException if the given skill is a child skill
  884. */
  885. @Deprecated
  886. public static void setXPOffline(String playerName, String skillType, int newValue) {
  887. getOfflineProfile(playerName).setSkillXpLevel(getNonChildSkillType(skillType), newValue);
  888. }
  889. /**
  890. * Sets the XP of an offline player in a specific skill type.
  891. * </br>
  892. * This function is designed for API usage.
  893. *
  894. * @param uuid The player to set the XP of
  895. * @param skillType The skill to set the XP for
  896. * @param newValue The value to set the XP to
  897. *
  898. * @throws InvalidSkillException if the given skill is not valid
  899. * @throws InvalidPlayerException if the given player does not exist in the database
  900. * @throws UnsupportedOperationException if the given skill is a child skill
  901. */
  902. public static void setXPOffline(UUID uuid, String skillType, int newValue) {
  903. getOfflineProfile(uuid).setSkillXpLevel(getNonChildSkillType(skillType), newValue);
  904. }
  905. /**
  906. * Removes XP from a player in a specific skill type.
  907. * </br>
  908. * This function is designed for API usage.
  909. *
  910. * @param player The player to change the XP of
  911. * @param skillType The skill to change the XP for
  912. * @param xp The amount of XP to remove
  913. *
  914. * @throws InvalidSkillException if the given skill is not valid
  915. * @throws UnsupportedOperationException if the given skill is a child skill
  916. */
  917. public static void removeXP(Player player, String skillType, int xp) {
  918. getPlayer(player).removeXp(getNonChildSkillType(skillType), xp);
  919. }
  920. /**
  921. * Removes XP from an offline player in a specific skill type.
  922. * </br>
  923. * This function is designed for API usage.
  924. *
  925. * @param playerName The player to change the XP of
  926. * @param skillType The skill to change the XP for
  927. * @param xp The amount of XP to remove
  928. *
  929. * @throws InvalidSkillException if the given skill is not valid
  930. * @throws InvalidPlayerException if the given player does not exist in the database
  931. * @throws UnsupportedOperationException if the given skill is a child skill
  932. */
  933. @Deprecated
  934. public static void removeXPOffline(String playerName, String skillType, int xp) {
  935. getOfflineProfile(playerName).removeXp(getNonChildSkillType(skillType), xp);
  936. }
  937. /**
  938. * Removes XP from an offline player in a specific skill type.
  939. * </br>
  940. * This function is designed for API usage.
  941. *
  942. * @param uuid The player to change the XP of
  943. * @param skillType The skill to change the XP for
  944. * @param xp The amount of XP to remove
  945. *
  946. * @throws InvalidSkillException if the given skill is not valid
  947. * @throws InvalidPlayerException if the given player does not exist in the database
  948. * @throws UnsupportedOperationException if the given skill is a child skill
  949. */
  950. public static void removeXPOffline(UUID uuid, String skillType, int xp) {
  951. getOfflineProfile(uuid).removeXp(getNonChildSkillType(skillType), xp);
  952. }
  953. /**
  954. * Check how much XP is needed for a specific level with the selected level curve.
  955. * </br>
  956. * This function is designed for API usage.
  957. *
  958. * @param level The level to get the amount of XP for
  959. *
  960. * @throws InvalidFormulaTypeException if the given formulaType is not valid
  961. */
  962. public static int getXpNeededToLevel(int level) {
  963. return mcMMO.getFormulaManager().getXPtoNextLevel(level, ExperienceConfig.getInstance().getFormulaType());
  964. }
  965. /**
  966. * Check how much XP is needed for a specific level with the provided level curve.
  967. * </br>
  968. * This function is designed for API usage.
  969. *
  970. * @param level The level to get the amount of XP for
  971. * @param formulaType The formula type to get the amount of XP for
  972. *
  973. * @throws InvalidFormulaTypeException if the given formulaType is not valid
  974. */
  975. public static int getXpNeededToLevel(int level, String formulaType) {
  976. return mcMMO.getFormulaManager().getXPtoNextLevel(level, getFormulaType(formulaType));
  977. }
  978. /**
  979. * Will add the appropriate type of XP from the block to the player based on the material of the blocks given
  980. * @param blockStates the blocks to reward XP for
  981. * @param mcMMOPlayer the target player
  982. */
  983. public static void addXpFromBlocks(ArrayList<BlockState> blockStates, McMMOPlayer mcMMOPlayer)
  984. {
  985. for(BlockState bs : blockStates)
  986. {
  987. for(PrimarySkillType skillType : PrimarySkillType.values())
  988. {
  989. if(ExperienceConfig.getInstance().getXp(skillType, bs.getType()) > 0)
  990. {
  991. mcMMOPlayer.applyXpGain(skillType, ExperienceConfig.getInstance().getXp(skillType, bs.getType()), XPGainReason.PVE, XPGainSource.SELF);
  992. }
  993. }
  994. }
  995. }
  996. /**
  997. * 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
  998. * @param blockStates the blocks to reward XP for
  999. * @param mcMMOPlayer the target player
  1000. * @param skillType target primary skill
  1001. */
  1002. public static void addXpFromBlocksBySkill(ArrayList<BlockState> blockStates, McMMOPlayer mcMMOPlayer, PrimarySkillType skillType)
  1003. {
  1004. for(BlockState bs : blockStates)
  1005. {
  1006. if(ExperienceConfig.getInstance().getXp(skillType, bs.getType()) > 0)
  1007. {
  1008. mcMMOPlayer.applyXpGain(skillType, ExperienceConfig.getInstance().getXp(skillType, bs.getType()), XPGainReason.PVE, XPGainSource.SELF);
  1009. }
  1010. }
  1011. }
  1012. /**
  1013. * Will add the appropriate type of XP from the block to the player based on the material of the blocks given
  1014. * @param blockState The target blockstate
  1015. * @param mcMMOPlayer The target player
  1016. */
  1017. public static void addXpFromBlock(BlockState blockState, McMMOPlayer mcMMOPlayer)
  1018. {
  1019. for(PrimarySkillType skillType : PrimarySkillType.values())
  1020. {
  1021. if(ExperienceConfig.getInstance().getXp(skillType, blockState.getType()) > 0)
  1022. {
  1023. mcMMOPlayer.applyXpGain(skillType, ExperienceConfig.getInstance().getXp(skillType, blockState.getType()), XPGainReason.PVE, XPGainSource.SELF);
  1024. }
  1025. }
  1026. }
  1027. /**
  1028. * 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
  1029. * @param blockState The target blockstate
  1030. * @param mcMMOPlayer The target player
  1031. * @param skillType target primary skill
  1032. */
  1033. public static void addXpFromBlockBySkill(BlockState blockState, McMMOPlayer mcMMOPlayer, PrimarySkillType skillType)
  1034. {
  1035. if(ExperienceConfig.getInstance().getXp(skillType, blockState.getType()) > 0)
  1036. {
  1037. mcMMOPlayer.applyXpGain(skillType, ExperienceConfig.getInstance().getXp(skillType, blockState.getType()), XPGainReason.PVE, XPGainSource.SELF);
  1038. }
  1039. }
  1040. // Utility methods follow.
  1041. private static void addOfflineXP(UUID playerUniqueId, PrimarySkillType skill, int XP) {
  1042. PlayerProfile profile = getOfflineProfile(playerUniqueId);
  1043. profile.addXp(skill, XP);
  1044. profile.save(true);
  1045. }
  1046. @Deprecated
  1047. private static void addOfflineXP(String playerName, PrimarySkillType skill, int XP) {
  1048. PlayerProfile profile = getOfflineProfile(playerName);
  1049. profile.addXp(skill, XP);
  1050. profile.scheduleAsyncSave();
  1051. }
  1052. private static PlayerProfile getOfflineProfile(UUID uuid) throws InvalidPlayerException {
  1053. OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(uuid);
  1054. String playerName = offlinePlayer.getName();
  1055. PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(uuid, playerName);
  1056. if (!profile.isLoaded()) {
  1057. throw new InvalidPlayerException();
  1058. }
  1059. return profile;
  1060. }
  1061. @Deprecated
  1062. private static PlayerProfile getOfflineProfile(String playerName) throws InvalidPlayerException {
  1063. OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(playerName);
  1064. UUID uuid = offlinePlayer.getUniqueId();
  1065. PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(uuid, playerName);
  1066. if (!profile.isLoaded()) {
  1067. throw new InvalidPlayerException();
  1068. }
  1069. return profile;
  1070. }
  1071. private static PrimarySkillType getSkillType(String skillType) throws InvalidSkillException {
  1072. PrimarySkillType skill = mcMMO.p.getSkillTools().matchSkill(skillType);
  1073. if (skill == null) {
  1074. throw new InvalidSkillException();
  1075. }
  1076. return skill;
  1077. }
  1078. private static PrimarySkillType getNonChildSkillType(String skillType) throws InvalidSkillException, UnsupportedOperationException {
  1079. PrimarySkillType skill = getSkillType(skillType);
  1080. if (mcMMO.p.getSkillTools().isChildSkill(skill)) {
  1081. throw new UnsupportedOperationException("Child skills do not have XP");
  1082. }
  1083. return skill;
  1084. }
  1085. private static XPGainReason getXPGainReason(String reason) throws InvalidXPGainReasonException {
  1086. XPGainReason xpGainReason = XPGainReason.getXPGainReason(reason);
  1087. if (xpGainReason == null) {
  1088. throw new InvalidXPGainReasonException();
  1089. }
  1090. return xpGainReason;
  1091. }
  1092. private static FormulaType getFormulaType(String formula) throws InvalidFormulaTypeException {
  1093. FormulaType formulaType = FormulaType.getFormulaType(formula);
  1094. if (formulaType == null) {
  1095. throw new InvalidFormulaTypeException();
  1096. }
  1097. return formulaType;
  1098. }
  1099. /**
  1100. * @deprecated Use UserManager::getPlayer(Player player) instead
  1101. * @param player target player
  1102. * @return McMMOPlayer for that player if the profile is loaded, otherwise null
  1103. * @throws McMMOPlayerNotFoundException
  1104. */
  1105. @Deprecated
  1106. private static McMMOPlayer getPlayer(Player player) throws McMMOPlayerNotFoundException {
  1107. if (!UserManager.hasPlayerDataKey(player)) {
  1108. throw new McMMOPlayerNotFoundException(player);
  1109. }
  1110. return UserManager.getPlayer(player);
  1111. }
  1112. }