PerksUtils.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package com.gmail.nossr50.util.skills;
  2. import com.gmail.nossr50.config.experience.ExperienceConfig;
  3. import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
  4. import com.gmail.nossr50.util.Permissions;
  5. import com.gmail.nossr50.util.player.UserManager;
  6. import org.bukkit.ChatColor;
  7. import org.bukkit.entity.Player;
  8. public final class PerksUtils {
  9. private static final int LUCKY_SKILL_ACTIVATION_CHANCE = 75;
  10. private static final int NORMAL_SKILL_ACTIVATION_CHANCE = 100;
  11. private PerksUtils() {}
  12. public static int handleCooldownPerks(Player player, int cooldown) {
  13. if (Permissions.halvedCooldowns(player)) {
  14. cooldown *= 0.5;
  15. }
  16. else if (Permissions.thirdedCooldowns(player)) {
  17. cooldown *= (2.0 / 3.0);
  18. }
  19. else if (Permissions.quarteredCooldowns(player)) {
  20. cooldown *= 0.75;
  21. }
  22. return cooldown;
  23. }
  24. public static int handleActivationPerks(Player player, int ticks, int maxTicks) {
  25. if (maxTicks != 0) {
  26. ticks = Math.min(ticks, maxTicks);
  27. }
  28. if (Permissions.twelveSecondActivationBoost(player)) {
  29. ticks += 12;
  30. }
  31. else if (Permissions.eightSecondActivationBoost(player)) {
  32. ticks += 8;
  33. }
  34. else if (Permissions.fourSecondActivationBoost(player)) {
  35. ticks += 4;
  36. }
  37. return ticks;
  38. }
  39. public static float handleXpPerks(Player player, float xp, PrimarySkillType skill) {
  40. double modifier = 1.0F;
  41. if (Permissions.customXpBoost(player, skill)) {
  42. if(UserManager.getPlayer(player) != null && UserManager.getPlayer(player).isDebugMode()) {
  43. player.sendMessage(ChatColor.GOLD + "[DEBUG] " + ChatColor.DARK_GRAY + "XP Perk Multiplier IS CUSTOM! ");
  44. }
  45. modifier = ExperienceConfig.getInstance().getCustomXpPerkBoost();
  46. }
  47. else if (Permissions.quadrupleXp(player, skill)) {
  48. modifier = 4;
  49. }
  50. else if (Permissions.tripleXp(player, skill)) {
  51. modifier = 3;
  52. }
  53. else if (Permissions.doubleAndOneHalfXp(player, skill)) {
  54. modifier = 2.5;
  55. }
  56. else if (Permissions.doubleXp(player, skill)) {
  57. modifier = 2;
  58. }
  59. else if (Permissions.oneAndOneHalfXp(player, skill)) {
  60. modifier = 1.5;
  61. }
  62. else if (Permissions.oneAndOneTenthXp(player, skill)) {
  63. modifier = 1.1;
  64. }
  65. float modifiedXP = (float) (xp * modifier);
  66. if(UserManager.getPlayer(player) != null && UserManager.getPlayer(player).isDebugMode()) {
  67. player.sendMessage(ChatColor.GOLD + "[DEBUG] " + ChatColor.RESET + "XP Perk Multiplier - " + ChatColor.GOLD + modifier);
  68. player.sendMessage(ChatColor.GOLD + "[DEBUG] " + ChatColor.RESET + "Original XP before perk boosts " + ChatColor.RED + (double) xp);
  69. player.sendMessage(ChatColor.GOLD + "[DEBUG] " + ChatColor.RESET + "XP AFTER PERKS " + ChatColor.DARK_RED + modifiedXP);
  70. }
  71. return modifiedXP;
  72. }
  73. /**
  74. * Calculate activation chance for a skill.
  75. *
  76. * @param player Player to check the activation chance for
  77. * @param skill PrimarySkillType to check the activation chance of
  78. * @return the activation chance with "lucky perk" accounted for
  79. */
  80. public static int handleLuckyPerks(Player player, PrimarySkillType skill) {
  81. if (Permissions.lucky(player, skill)) {
  82. return LUCKY_SKILL_ACTIVATION_CHANCE;
  83. }
  84. return NORMAL_SKILL_ACTIVATION_CHANCE;
  85. }
  86. }