BlastMining.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. package com.gmail.nossr50.skills.mining;
  2. import com.gmail.nossr50.config.AdvancedConfig;
  3. import com.gmail.nossr50.config.MainConfig;
  4. import com.gmail.nossr50.datatypes.skills.SubSkillType;
  5. import com.gmail.nossr50.mcMMO;
  6. import com.gmail.nossr50.util.player.UserManager;
  7. import com.gmail.nossr50.util.skills.RankUtils;
  8. import org.bukkit.Material;
  9. import org.bukkit.entity.Player;
  10. import org.bukkit.entity.TNTPrimed;
  11. import org.bukkit.event.entity.EntityDamageByEntityEvent;
  12. import org.bukkit.event.entity.EntityDamageEvent.DamageModifier;
  13. public class BlastMining {
  14. // The order of the values is extremely important, a few methods depend on it to work properly
  15. /* public enum Tier {
  16. EIGHT(8),
  17. SEVEN(7),
  18. SIX(6),
  19. FIVE(5),
  20. FOUR(4),
  21. THREE(3),
  22. TWO(2),
  23. ONE(1);
  24. int numerical;
  25. private Tier(int numerical) {
  26. this.numerical = numerical;
  27. }
  28. public int toNumerical() {
  29. return numerical;
  30. }
  31. protected int getLevel() {
  32. return AdvancedConfig.getInstance().getBlastMiningRankLevel(this);
  33. }
  34. }*/
  35. public final static int MAXIMUM_REMOTE_DETONATION_DISTANCE = 100;
  36. public static double getBlastRadiusModifier(int rank) {
  37. return AdvancedConfig.getInstance().getBlastRadiusModifier(rank);
  38. }
  39. public static double getBlastDamageDecrease(int rank) {
  40. return AdvancedConfig.getInstance().getBlastDamageDecrease(rank);
  41. }
  42. public static int getDemolitionExpertUnlockLevel() {
  43. /*List<Tier> tierList = Arrays.asList(Tier.values());
  44. for (Tier tier : tierList) {
  45. if (tier.getBlastDamageDecrease() > 0) {
  46. continue;
  47. }
  48. return tier == Tier.EIGHT ? tier.getLevel() : tierList.get(tierList.indexOf(tier) - 1).getLevel();
  49. }*/
  50. for(int i = 0; i < SubSkillType.MINING_BLAST_MINING.getNumRanks()-1; i++)
  51. {
  52. if(getBlastDamageDecrease(i+1) > 0)
  53. return RankUtils.getRankUnlockLevel(SubSkillType.MINING_BLAST_MINING, i+1);
  54. }
  55. return 0;
  56. }
  57. public static int getBiggerBombsUnlockLevel() {
  58. /*List<Tier> tierList = Arrays.asList(Tier.values());
  59. for (Tier tier : tierList) {
  60. if (tier.getBlastRadiusModifier() > 1.0) {
  61. continue;
  62. }
  63. return tier == Tier.EIGHT ? tier.getLevel() : tierList.get(tierList.indexOf(tier) - 1).getLevel();
  64. }*/
  65. for(int i = 0; i < SubSkillType.MINING_BLAST_MINING.getNumRanks()-1; i++)
  66. {
  67. if(getBlastRadiusModifier(i+1) > 0)
  68. return RankUtils.getRankUnlockLevel(SubSkillType.MINING_BLAST_MINING, i+1);
  69. }
  70. return 0;
  71. }
  72. public static boolean processBlastMiningExplosion(EntityDamageByEntityEvent event, TNTPrimed tnt, Player defender) {
  73. if (!tnt.hasMetadata(mcMMO.tntMetadataKey) || !UserManager.hasPlayerDataKey(defender)) {
  74. return false;
  75. }
  76. // We can make this assumption because we (should) be the only ones using this exact metadata
  77. Player player = mcMMO.p.getServer().getPlayerExact(tnt.getMetadata(mcMMO.tntMetadataKey).get(0).asString());
  78. if (!player.equals(defender)) {
  79. return false;
  80. }
  81. MiningManager miningManager = UserManager.getPlayer(defender).getMiningManager();
  82. if (!miningManager.canUseDemolitionsExpertise()) {
  83. return false;
  84. }
  85. event.setDamage(DamageModifier.BASE, miningManager.processDemolitionsExpertise(event.getDamage()));
  86. if (event.getFinalDamage() == 0) {
  87. event.setCancelled(true);
  88. return false;
  89. }
  90. return true;
  91. }
  92. }