From 72958bb0f3b3a55d5c1b9e448a423276742cb8b8 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Fri, 2 Apr 2021 08:32:56 -0700 Subject: [PATCH] Herbalism XP exploit fix --- Changelog.txt | 3 ++ pom.xml | 2 +- .../nossr50/listeners/PlayerListener.java | 4 +- .../skills/herbalism/HerbalismManager.java | 45 ++++++++++++++----- 4 files changed, 40 insertions(+), 14 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index 269b0af14..fcb6d12e9 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,3 +1,6 @@ +Version 2.1.185 + Fixed an exploit for Herbalism + Version 2.1.184 Removed April Fools event Fixed a bug where the default treasures.yml file had incorrect keys (see notes) diff --git a/pom.xml b/pom.xml index e0acdc7b7..0707083c3 100755 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 com.gmail.nossr50.mcMMO mcMMO - 2.1.184 + 2.1.185-SNAPSHOT mcMMO https://github.com/mcMMO-Dev/mcMMO diff --git a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java index ab1c46c93..7a8262600 100644 --- a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java @@ -848,7 +848,9 @@ public class PlayerListener implements Listener { } } } else { - herbalismManager.processBerryBushHarvesting(blockState); + if(!event.getPlayer().isSneaking()) { + herbalismManager.processBerryBushHarvesting(blockState); + } } } break; diff --git a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java index f4bf66b1d..c4d4b6a32 100644 --- a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java +++ b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java @@ -29,6 +29,7 @@ import com.gmail.nossr50.util.skills.SkillUtils; import com.gmail.nossr50.util.sounds.SoundManager; import com.gmail.nossr50.util.sounds.SoundType; import com.gmail.nossr50.util.text.StringUtils; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -40,6 +41,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; +import org.bukkit.scheduler.BukkitRunnable; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; @@ -111,22 +113,41 @@ public class HerbalismManager extends SkillManager { mmoPlayer.getPlayer().sendMessage("Bush XP: " + xpReward); } -// //Check for double drops -// if(checkDoubleDrop(blockState)) { -// -// if(mmoPlayer.isDebugMode()) { -// mmoPlayer.getPlayer().sendMessage("Double Drops succeeded for Berry Bush"); -// } -// -// //Add metadata to mark this block for double or triple drops -// markForBonusDrops(blockState); -// } - - applyXpGain(xpReward, XPGainReason.PVE, XPGainSource.SELF); + CheckBushAge checkBushAge = new CheckBushAge(blockState.getBlock(), mmoPlayer, xpReward); + checkBushAge.runTaskLater(mcMMO.p, 1); } } } + private class CheckBushAge extends BukkitRunnable { + + @NotNull Block block; + @NotNull McMMOPlayer mmoPlayer; + int xpReward; + + public CheckBushAge(@NotNull Block block, @NotNull McMMOPlayer mmoPlayer, int xpReward) { + this.block = block; + this.mmoPlayer = mmoPlayer; + this.xpReward = xpReward; + } + + @Override + public void run() { + BlockState blockState = block.getState(); + + if(blockState.getType().toString().equalsIgnoreCase("sweet_berry_bush")) { + if(blockState.getBlockData() instanceof Ageable) { + Ageable ageable = (Ageable) blockState.getBlockData(); + + if(ageable.getAge() <= 1) { + applyXpGain(xpReward, XPGainReason.PVE, XPGainSource.SELF); + } + } + } + } + } + + public boolean canUseHylianLuck() { if(!RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.HERBALISM_HYLIAN_LUCK)) return false;