SkillManager.java 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package com.gmail.nossr50.skills;
  2. import com.gmail.nossr50.datatypes.experience.XPGainReason;
  3. import com.gmail.nossr50.datatypes.experience.XPGainSource;
  4. import com.gmail.nossr50.datatypes.player.McMMOPlayer;
  5. import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
  6. import com.gmail.nossr50.mcMMO;
  7. import org.bukkit.entity.Entity;
  8. import org.bukkit.entity.LivingEntity;
  9. import org.bukkit.entity.Player;
  10. public abstract class SkillManager {
  11. protected McMMOPlayer mcMMOPlayer;
  12. protected PrimarySkillType skill;
  13. protected final mcMMO pluginRef;
  14. public SkillManager(mcMMO pluginRef, McMMOPlayer mcMMOPlayer, PrimarySkillType skill) {
  15. this.pluginRef = pluginRef;
  16. this.mcMMOPlayer = mcMMOPlayer;
  17. this.skill = skill;
  18. }
  19. public Player getPlayer() {
  20. return mcMMOPlayer.getPlayer();
  21. }
  22. public int getSkillLevel() {
  23. return mcMMOPlayer.getSkillLevel(skill);
  24. }
  25. /**
  26. * Applies XP to a player, provides SELF as an XpGainSource source
  27. *
  28. * @param xp amount of XP to apply
  29. * @param xpGainReason the reason for the XP gain
  30. * @deprecated use applyXpGain(float, XPGainReason, XPGainSource)
  31. */
  32. @Deprecated
  33. public void applyXpGain(double xp, XPGainReason xpGainReason) {
  34. mcMMOPlayer.beginXpGain(skill, xp, xpGainReason, XPGainSource.SELF);
  35. }
  36. /**
  37. * Applies XP to a player, provides SELF as an XpGainSource source
  38. *
  39. * @param xp amount of XP to apply
  40. * @param xpGainReason the reason for the XP gain
  41. * @deprecated use applyXpGain(float, XPGainReason, XPGainSource)
  42. */
  43. @Deprecated
  44. public void applyXpGain(float xp, XPGainReason xpGainReason) {
  45. mcMMOPlayer.beginXpGain(skill, xp, xpGainReason, XPGainSource.SELF);
  46. }
  47. /**
  48. * Applies XP to a player
  49. *
  50. * @param xp amount of XP to apply
  51. * @param xpGainReason the reason for the XP gain
  52. * @param xpGainSource the source of the XP
  53. */
  54. public void applyXpGain(float xp, XPGainReason xpGainReason, XPGainSource xpGainSource) {
  55. mcMMOPlayer.beginXpGain(skill, xp, xpGainReason, xpGainSource);
  56. }
  57. /**
  58. * Applies XP to a player
  59. *
  60. * @param xp amount of XP to apply
  61. * @param xpGainReason the reason for the XP gain
  62. * @param xpGainSource the source of the XP
  63. */
  64. public void applyXpGain(double xp, XPGainReason xpGainReason, XPGainSource xpGainSource) {
  65. mcMMOPlayer.beginXpGain(skill, xp, xpGainReason, xpGainSource);
  66. }
  67. public XPGainReason getXPGainReason(LivingEntity target, Entity damager) {
  68. return (damager instanceof Player && target instanceof Player) ? XPGainReason.PVP : XPGainReason.PVE;
  69. }
  70. }