SmeltingManager.java 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. package com.gmail.nossr50.skills.smelting;
  2. import com.gmail.nossr50.config.Config;
  3. import com.gmail.nossr50.datatypes.experience.XPGainReason;
  4. import com.gmail.nossr50.datatypes.experience.XPGainSource;
  5. import com.gmail.nossr50.datatypes.player.McMMOPlayer;
  6. import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
  7. import com.gmail.nossr50.datatypes.skills.SubSkillType;
  8. import com.gmail.nossr50.skills.SkillManager;
  9. import com.gmail.nossr50.util.Permissions;
  10. import com.gmail.nossr50.util.random.RandomChanceUtil;
  11. import com.gmail.nossr50.util.skills.RankUtils;
  12. import com.gmail.nossr50.util.skills.SkillActivationType;
  13. import org.bukkit.block.Furnace;
  14. import org.bukkit.event.inventory.FurnaceBurnEvent;
  15. import org.bukkit.event.inventory.FurnaceSmeltEvent;
  16. import org.bukkit.inventory.ItemStack;
  17. import org.jetbrains.annotations.NotNull;
  18. public class SmeltingManager extends SkillManager {
  19. public SmeltingManager(McMMOPlayer mcMMOPlayer) {
  20. super(mcMMOPlayer, PrimarySkillType.SMELTING);
  21. }
  22. /*public boolean canUseFluxMining(BlockState blockState) {
  23. return getSkillLevel() >= Smelting.fluxMiningUnlockLevel
  24. && BlockUtils.affectedByFluxMining(blockState)
  25. && Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.SMELTING_FLUX_MINING)
  26. && !mcMMO.getPlaceStore().isTrue(blockState);
  27. }*/
  28. public boolean isSecondSmeltSuccessful() {
  29. return Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.SMELTING_SECOND_SMELT)
  30. && RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.SMELTING_SECOND_SMELT, getPlayer());
  31. }
  32. /*
  33. Process the Flux Mining ability.
  34. @param blockState The {@link BlockState} to check ability activation for
  35. * @return true if the ability was successful, false otherwise
  36. */
  37. /*public boolean processFluxMining(BlockState blockState) {
  38. Player player = getPlayer();
  39. if (RandomChanceUtil.checkRandomChanceExecutionSuccess(getPlayer(), SubSkillType.SMELTING_FLUX_MINING, true)) {
  40. ItemStack item = null;
  41. switch (blockState.getType()) {
  42. case IRON_ORE:
  43. item = new ItemStack(Material.IRON_INGOT);
  44. break;
  45. case GOLD_ORE:
  46. item = new ItemStack(Material.GOLD_INGOT);
  47. break;
  48. default:
  49. break;
  50. }
  51. if (item == null) {
  52. return false;
  53. }
  54. if (!EventUtils.simulateBlockBreak(blockState.getBlock(), player, true)) {
  55. return false;
  56. }
  57. // We need to distribute Mining XP here, because the block break event gets cancelled
  58. applyXpGain(Mining.getBlockXp(blockState), XPGainReason.PVE, XPGainSource.PASSIVE);
  59. SkillUtils.handleDurabilityChange(getPlayer().getInventory().getItemInMainHand(), Config.getInstance().getAbilityToolDamage());
  60. Misc.dropItems(Misc.getBlockCenter(blockState), item, isSecondSmeltSuccessful() ? 2 : 1);
  61. blockState.setType(Material.AIR);
  62. if (Config.getInstance().getFluxPickaxeSoundEnabled()) {
  63. SoundManager.sendSound(player, blockState.getLocation(), SoundType.FIZZ);
  64. }
  65. ParticleEffectUtils.playFluxEffect(blockState.getLocation());
  66. return true;
  67. }
  68. return false;
  69. }*/
  70. /**
  71. * Increases burn time for furnace fuel.
  72. *
  73. * @param burnTime The initial burn time from the {@link FurnaceBurnEvent}
  74. */
  75. public int fuelEfficiency(int burnTime) {
  76. return burnTime * getFuelEfficiencyMultiplier();
  77. }
  78. public int getFuelEfficiencyMultiplier()
  79. {
  80. switch(RankUtils.getRank(getPlayer(), SubSkillType.SMELTING_FUEL_EFFICIENCY))
  81. {
  82. case 1:
  83. return 2;
  84. case 2:
  85. return 3;
  86. case 3:
  87. return 4;
  88. default:
  89. return 1;
  90. }
  91. }
  92. public void smeltProcessing(@NotNull FurnaceSmeltEvent furnaceSmeltEvent, @NotNull Furnace furnace) {
  93. ItemStack sourceItemStack = furnaceSmeltEvent.getSource();
  94. ItemStack resultItemStack = furnaceSmeltEvent.getResult();
  95. applyXpGain(Smelting.getResourceXp(sourceItemStack), XPGainReason.PVE, XPGainSource.PASSIVE); //Add XP
  96. processDoubleSmelt(furnaceSmeltEvent, resultItemStack, furnace);
  97. }
  98. private void processDoubleSmelt(@NotNull FurnaceSmeltEvent furnaceSmeltEvent, @NotNull ItemStack resultItemStack, @NotNull Furnace furnace) {
  99. int itemLimit = resultItemStack.getMaxStackSize();
  100. //Check for viewers
  101. if(furnace.getInventory().getViewers().size() > 0) {
  102. itemLimit = itemLimit - 1; //Lower max size to prevent exploit, the exploit involves an open window and a stack at 63 which is about to double smelt, instructions to replicate below
  103. /*
  104. Momshroom02/26/2021
  105. 1) have max (or close to it) smelting.
  106. 2) put more than half a stack of an ore in a furnace and wait for it to smelt.
  107. 3) have your inv full except for one items worth of whatever the furnace product is. (so like a stack of 63 iron and the rest of your inv is full).
  108. 4) shift click on the furnace output to remove only one item-- leaving 63.
  109. 5) let one more item smelt so the furnace appears to have 64
  110. 6) manually drag (don't shift click) the stack of product out of the furnace- it'll be 65 items
  111. when you drop that and pick it up with only one free space in your inv, it'll look like there's more than one left on the ground, but for me, there was only one, and the "dupe" was visual only-- idk about VK's player.
  112. */
  113. }
  114. //TODO: Permission check work around, could store it as NBT on the furnace
  115. //We don't do permission checks because this can be for an offline player and Bukkit has nothing to grab permissions for offline players
  116. //Process double smelt
  117. if (Config.getInstance().getDoubleDropsEnabled(PrimarySkillType.SMELTING, resultItemStack.getType())
  118. && resultItemStack.getAmount() < itemLimit //We take away 1 because there's a certain "exploit" when certain plugins are used in combination
  119. && isSecondSmeltSuccessful()) {
  120. ItemStack newResult = resultItemStack.clone();
  121. newResult.setAmount(Math.min(resultItemStack.getAmount() + 1, itemLimit)); //Don't go over max stack limits
  122. furnaceSmeltEvent.setResult(newResult);
  123. }
  124. }
  125. public int vanillaXPBoost(int experience) {
  126. return experience * getVanillaXpMultiplier();
  127. }
  128. /**
  129. * Gets the vanilla XP multiplier
  130. *
  131. * @return the vanilla XP multiplier
  132. */
  133. public int getVanillaXpMultiplier() {
  134. return Math.max(1, RankUtils.getRank(getPlayer(), SubSkillType.SMELTING_UNDERSTANDING_THE_ART));
  135. }
  136. }