SmeltingManager.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. package com.gmail.nossr50.skills.smelting;
  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.datatypes.skills.SubSkillType;
  7. import com.gmail.nossr50.skills.SkillManager;
  8. import com.gmail.nossr50.util.Permissions;
  9. import com.gmail.nossr50.util.random.RandomChanceUtil;
  10. import com.gmail.nossr50.util.skills.RankUtils;
  11. import com.gmail.nossr50.util.skills.SkillActivationType;
  12. import org.bukkit.block.BlockState;
  13. import org.bukkit.event.inventory.FurnaceBurnEvent;
  14. import org.bukkit.inventory.ItemStack;
  15. public class SmeltingManager extends SkillManager {
  16. public SmeltingManager(McMMOPlayer mcMMOPlayer) {
  17. super(mcMMOPlayer, PrimarySkillType.SMELTING);
  18. }
  19. /*public boolean canUseFluxMining(BlockState blockState) {
  20. return getSkillLevel() >= Smelting.fluxMiningUnlockLevel
  21. && BlockUtils.affectedByFluxMining(blockState)
  22. && Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.SMELTING_FLUX_MINING)
  23. && !mcMMO.getPlaceStore().isTrue(blockState);
  24. }*/
  25. public boolean isSecondSmeltSuccessful() {
  26. return Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.SMELTING_SECOND_SMELT)
  27. && RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.SMELTING_SECOND_SMELT, getPlayer());
  28. }
  29. /**
  30. * Process the Flux Mining ability.
  31. *
  32. * @param blockState The {@link BlockState} to check ability activation for
  33. * @return true if the ability was successful, false otherwise
  34. */
  35. /*public boolean processFluxMining(BlockState blockState) {
  36. Player player = getPlayer();
  37. if (RandomChanceUtil.checkRandomChanceExecutionSuccess(getPlayer(), SubSkillType.SMELTING_FLUX_MINING, true)) {
  38. ItemStack item = null;
  39. switch (blockState.getType()) {
  40. case IRON_ORE:
  41. item = new ItemStack(Material.IRON_INGOT);
  42. break;
  43. case GOLD_ORE:
  44. item = new ItemStack(Material.GOLD_INGOT);
  45. break;
  46. default:
  47. break;
  48. }
  49. if (item == null) {
  50. return false;
  51. }
  52. if (!EventUtils.simulateBlockBreak(blockState.getBlock(), player, true)) {
  53. return false;
  54. }
  55. // We need to distribute Mining XP here, because the block break event gets cancelled
  56. applyXpGain(Mining.getBlockXp(blockState), XPGainReason.PVE, XPGainSource.PASSIVE);
  57. SkillUtils.handleDurabilityChange(getPlayer().getInventory().getItemInMainHand(), MainConfig.getInstance().getAbilityToolDamage());
  58. Misc.dropItems(Misc.getBlockCenter(blockState), item, isSecondSmeltSuccessful() ? 2 : 1);
  59. blockState.setType(Material.AIR);
  60. if (MainConfig.getInstance().getFluxPickaxeSoundEnabled()) {
  61. SoundManager.sendSound(player, blockState.getLocation(), SoundType.FIZZ);
  62. }
  63. ParticleEffectUtils.playFluxEffect(blockState.getLocation());
  64. return true;
  65. }
  66. return false;
  67. }*/
  68. /**
  69. * Increases burn time for furnace fuel.
  70. *
  71. * @param burnTime The initial burn time from the {@link FurnaceBurnEvent}
  72. */
  73. public int fuelEfficiency(int burnTime) {
  74. return burnTime * getFuelEfficiencyMultiplier();
  75. }
  76. public int getFuelEfficiencyMultiplier() {
  77. switch (RankUtils.getRank(getPlayer(), SubSkillType.SMELTING_FUEL_EFFICIENCY)) {
  78. case 1:
  79. return 2;
  80. case 2:
  81. return 3;
  82. case 3:
  83. return 4;
  84. default:
  85. return 1;
  86. }
  87. }
  88. public ItemStack smeltProcessing(ItemStack smelting, ItemStack result) {
  89. applyXpGain(Smelting.getResourceXp(smelting), XPGainReason.PVE, XPGainSource.PASSIVE);
  90. if (isSecondSmeltSuccessful()) {
  91. ItemStack newResult = result.clone();
  92. newResult.setAmount(result.getAmount() + 1);
  93. return newResult;
  94. }
  95. return result;
  96. }
  97. public int vanillaXPBoost(int experience) {
  98. return experience * getVanillaXpMultiplier();
  99. }
  100. /**
  101. * Gets the vanilla XP multiplier
  102. *
  103. * @return the vanilla XP multiplier
  104. */
  105. public int getVanillaXpMultiplier() {
  106. return Math.max(1, RankUtils.getRank(getPlayer(), SubSkillType.SMELTING_UNDERSTANDING_THE_ART));
  107. }
  108. }