ExperienceAPI.java 46 KB

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