Excavation.java 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. package com.gmail.nossr50.skills.gathering;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import java.util.Random;
  5. import org.bukkit.Location;
  6. import org.bukkit.Material;
  7. import org.bukkit.block.Block;
  8. import org.bukkit.entity.Player;
  9. import org.bukkit.inventory.ItemStack;
  10. import org.bukkit.material.MaterialData;
  11. import org.getspout.spoutapi.sound.SoundEffect;
  12. import com.gmail.nossr50.mcMMO;
  13. import com.gmail.nossr50.config.Config;
  14. import com.gmail.nossr50.config.TreasuresConfig;
  15. import com.gmail.nossr50.config.mods.CustomBlocksConfig;
  16. import com.gmail.nossr50.datatypes.PlayerProfile;
  17. import com.gmail.nossr50.datatypes.SkillType;
  18. import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure;
  19. import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
  20. import com.gmail.nossr50.spout.SpoutSounds;
  21. import com.gmail.nossr50.util.Misc;
  22. import com.gmail.nossr50.util.ModChecks;
  23. import com.gmail.nossr50.util.Permissions;
  24. import com.gmail.nossr50.util.Skills;
  25. import com.gmail.nossr50.util.Users;
  26. public class Excavation {
  27. private static Random random = new Random();
  28. /**
  29. * Check to see if treasures were found.
  30. *
  31. * @param block The block to check
  32. * @param player The player who broke the block
  33. */
  34. public static void excavationProcCheck(Block block, Player player) {
  35. if(player == null)
  36. return;
  37. Material type = block.getType();
  38. Location location = block.getLocation();
  39. PlayerProfile profile = Users.getProfile(player);
  40. int skillLevel = profile.getSkillLevel(SkillType.EXCAVATION);
  41. ArrayList<ItemStack> is = new ArrayList<ItemStack>();
  42. List<ExcavationTreasure> treasures = new ArrayList<ExcavationTreasure>();
  43. int xp;
  44. ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
  45. if (Config.getInstance().getBlockModsEnabled() && CustomBlocksConfig.getInstance().customExcavationBlocks.contains(item)) {
  46. xp = ModChecks.getCustomBlock(block).getXpGain();
  47. }
  48. else {
  49. xp = Config.getInstance().getExcavationBaseXP();
  50. }
  51. if (Permissions.excavationTreasures(player)) {
  52. switch (type) {
  53. case DIRT:
  54. treasures = TreasuresConfig.getInstance().excavationFromDirt;
  55. break;
  56. case GRASS:
  57. treasures = TreasuresConfig.getInstance().excavationFromGrass;
  58. break;
  59. case SAND:
  60. treasures = TreasuresConfig.getInstance().excavationFromSand;
  61. break;
  62. case GRAVEL:
  63. treasures = TreasuresConfig.getInstance().excavationFromGravel;
  64. break;
  65. case CLAY:
  66. treasures = TreasuresConfig.getInstance().excavationFromClay;
  67. break;
  68. case MYCEL:
  69. treasures = TreasuresConfig.getInstance().excavationFromMycel;
  70. break;
  71. case SOUL_SAND:
  72. treasures = TreasuresConfig.getInstance().excavationFromSoulSand;
  73. break;
  74. default:
  75. break;
  76. }
  77. for (ExcavationTreasure treasure : treasures) {
  78. if (skillLevel >= treasure.getDropLevel()) {
  79. int randomChance = 100;
  80. if (Permissions.luckyExcavation(player)) {
  81. randomChance = (int) (randomChance * 0.75);
  82. }
  83. if (random.nextDouble() * randomChance <= treasure.getDropChance()) {
  84. xp += treasure.getXp();
  85. is.add(treasure.getDrop());
  86. }
  87. }
  88. }
  89. //Drop items
  90. for (ItemStack x : is) {
  91. if (x != null) {
  92. Misc.dropItem(location, x);
  93. }
  94. }
  95. }
  96. Skills.xpProcessing(player, profile, SkillType.EXCAVATION, xp);
  97. }
  98. /**
  99. * Handle triple drops from Giga Drill Breaker.
  100. *
  101. * @param player The player using the ability
  102. * @param block The block to check
  103. */
  104. public static void gigaDrillBreaker(Player player, Block block) {
  105. if(player == null)
  106. return;
  107. Skills.abilityDurabilityLoss(player.getItemInHand(), Config.getInstance().getAbilityToolDamage());
  108. if (!mcMMO.placeStore.isTrue(block) && Misc.blockBreakSimulate(block, player, true)) {
  109. FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player);
  110. mcMMO.p.getServer().getPluginManager().callEvent(armswing);
  111. Excavation.excavationProcCheck(block, player);
  112. Excavation.excavationProcCheck(block, player);
  113. }
  114. if (mcMMO.spoutEnabled) {
  115. SpoutSounds.playSoundForPlayer(SoundEffect.POP, player, block.getLocation());
  116. }
  117. }
  118. }