ExcavationManager.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package com.gmail.nossr50.skills.excavation;
  2. import com.gmail.nossr50.config.MainConfig;
  3. import com.gmail.nossr50.datatypes.experience.XPGainReason;
  4. import com.gmail.nossr50.datatypes.player.McMMOPlayer;
  5. import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
  6. import com.gmail.nossr50.datatypes.skills.SubSkillType;
  7. import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure;
  8. import com.gmail.nossr50.mcMMO;
  9. import com.gmail.nossr50.skills.SkillManager;
  10. import com.gmail.nossr50.util.Misc;
  11. import com.gmail.nossr50.util.Permissions;
  12. import com.gmail.nossr50.util.random.RandomChanceUtil;
  13. import com.gmail.nossr50.util.skills.SkillUtils;
  14. import org.bukkit.Location;
  15. import org.bukkit.block.BlockState;
  16. import org.bukkit.entity.Player;
  17. import java.util.List;
  18. public class ExcavationManager extends SkillManager {
  19. public ExcavationManager(McMMOPlayer mcMMOPlayer) {
  20. super(mcMMOPlayer, PrimarySkillType.EXCAVATION);
  21. }
  22. /**
  23. * Process treasure drops & XP gain for Excavation.
  24. *
  25. * @param blockState The {@link BlockState} to check ability activation for
  26. */
  27. public void excavationBlockCheck(BlockState blockState) {
  28. int xp = Excavation.getBlockXP(blockState);
  29. if (Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.EXCAVATION_ARCHAEOLOGY)) {
  30. List<ExcavationTreasure> treasures = Excavation.getTreasures(blockState);
  31. if (!treasures.isEmpty()) {
  32. int skillLevel = getSkillLevel();
  33. Location location = Misc.getBlockCenter(blockState);
  34. for (ExcavationTreasure treasure : treasures) {
  35. if (skillLevel >= treasure.getDropLevel()
  36. && RandomChanceUtil.checkRandomChanceExecutionSuccess(getPlayer(), PrimarySkillType.EXCAVATION, treasure.getDropChance())) {
  37. xp += treasure.getXp();
  38. Misc.dropItem(location, treasure.getDrop());
  39. }
  40. }
  41. }
  42. }
  43. applyXpGain(xp, XPGainReason.PVE);
  44. }
  45. public void printExcavationDebug(Player player, BlockState blockState)
  46. {
  47. if (Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.EXCAVATION_ARCHAEOLOGY)) {
  48. List<ExcavationTreasure> treasures = Excavation.getTreasures(blockState);
  49. if (!treasures.isEmpty()) {
  50. for (ExcavationTreasure treasure : treasures) {
  51. player.sendMessage("|||||||||||||||||||||||||||||||||");
  52. player.sendMessage("[mcMMO DEBUG] Treasure found: ("+treasure.getDrop().getType().toString()+")");
  53. player.sendMessage("[mcMMO DEBUG] Drop Chance for Treasure: "+treasure.getDropChance());
  54. player.sendMessage("[mcMMO DEBUG] Skill Level Required: "+treasure.getDropLevel());
  55. player.sendMessage("[mcMMO DEBUG] XP for Treasure: "+treasure.getXp());
  56. }
  57. } else {
  58. player.sendMessage("[mcMMO DEBUG] No treasures found for this block.");
  59. }
  60. }
  61. }
  62. /**
  63. * Process the Giga Drill Breaker ability.
  64. *
  65. * @param blockState The {@link BlockState} to check ability activation for
  66. */
  67. public void gigaDrillBreaker(BlockState blockState) {
  68. excavationBlockCheck(blockState);
  69. excavationBlockCheck(blockState);
  70. SkillUtils.handleDurabilityChange(getPlayer().getInventory().getItemInMainHand(), mcMMO.getConfigManager().getConfigSuperAbilities().getSuperAbilityLimits().getToolDurabilityDamage());
  71. }
  72. }