From 4eecd344942b5ff509210c48014596ef85c63498 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Fri, 26 Feb 2021 17:48:20 -0800 Subject: [PATCH 1/5] 2.1.175 - Hotfix --- Changelog.txt | 2 ++ pom.xml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Changelog.txt b/Changelog.txt index 4d892cafb..5a4497562 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -2,6 +2,8 @@ Version 2.1.175 Fixed a bug where mcMMO would occasionally give a 65 item stack from a double smelt on a furnace Fixed a bug where arrows could be duped when fired from a crossbow with piercing enchantment Added setting to enable or disable Green Thumb automatically replanting crops per crop to config.yml under 'Green_Thumb_Replanting_Crops' section + Updated Adventure (our text dependency) fixes some errors when using color codes in party/admin chat (thanks TheBusyBiscuit) + Added some support for negative Y values in anticipation of 1.17 world height changes (thanks t00thpick1) Version 2.1.174 Some legacy color codes in our locale file were swapped to &-code equivalents (thanks ViaSnake) diff --git a/pom.xml b/pom.xml index 485f4d7f9..cc7ccea82 100755 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 com.gmail.nossr50.mcMMO mcMMO - 2.1.175-SNAPSHOT + 2.1.175 mcMMO https://github.com/mcMMO-Dev/mcMMO From ac618cf48a4bd5d8207811c18282b54a5482bad2 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Tue, 2 Mar 2021 11:15:52 -0800 Subject: [PATCH 2/5] Add another measure to stop item stacks from becoming illegal sizes from double smelt --- Changelog.txt | 3 ++ pom.xml | 2 +- .../nossr50/listeners/InventoryListener.java | 2 +- .../skills/smelting/SmeltingManager.java | 28 +++++++++++++++---- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index 5a4497562..a0da56a3d 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,3 +1,6 @@ +Version 2.1.176 + Added another measure to prevent item stacks from reaching 65 from double smelt + Version 2.1.175 Fixed a bug where mcMMO would occasionally give a 65 item stack from a double smelt on a furnace Fixed a bug where arrows could be duped when fired from a crossbow with piercing enchantment diff --git a/pom.xml b/pom.xml index cc7ccea82..9c3b05df6 100755 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 com.gmail.nossr50.mcMMO mcMMO - 2.1.175 + 2.1.176-SNAPSHOT mcMMO https://github.com/mcMMO-Dev/mcMMO diff --git a/src/main/java/com/gmail/nossr50/listeners/InventoryListener.java b/src/main/java/com/gmail/nossr50/listeners/InventoryListener.java index c3a0aa838..c110de94c 100644 --- a/src/main/java/com/gmail/nossr50/listeners/InventoryListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/InventoryListener.java @@ -117,7 +117,7 @@ public class InventoryListener implements Listener { //Profile doesn't exist if(offlineProfile != null) { //Process smelting - offlineProfile.getSmeltingManager().smeltProcessing(event); + offlineProfile.getSmeltingManager().smeltProcessing(event, furnace); } } } diff --git a/src/main/java/com/gmail/nossr50/skills/smelting/SmeltingManager.java b/src/main/java/com/gmail/nossr50/skills/smelting/SmeltingManager.java index 0ad1a4803..0f1b342f9 100644 --- a/src/main/java/com/gmail/nossr50/skills/smelting/SmeltingManager.java +++ b/src/main/java/com/gmail/nossr50/skills/smelting/SmeltingManager.java @@ -11,6 +11,7 @@ import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.random.RandomChanceUtil; import com.gmail.nossr50.util.skills.RankUtils; import com.gmail.nossr50.util.skills.SkillActivationType; +import org.bukkit.block.Furnace; import org.bukkit.event.inventory.FurnaceBurnEvent; import org.bukkit.event.inventory.FurnaceSmeltEvent; import org.bukkit.inventory.ItemStack; @@ -110,23 +111,40 @@ public class SmeltingManager extends SkillManager { } } - public void smeltProcessing(@NotNull FurnaceSmeltEvent furnaceSmeltEvent) { + public void smeltProcessing(@NotNull FurnaceSmeltEvent furnaceSmeltEvent, @NotNull Furnace furnace) { ItemStack sourceItemStack = furnaceSmeltEvent.getSource(); ItemStack resultItemStack = furnaceSmeltEvent.getResult(); applyXpGain(Smelting.getResourceXp(sourceItemStack), XPGainReason.PVE, XPGainSource.PASSIVE); //Add XP - int itemLimit = resultItemStack.getMaxStackSize(); - processDoubleSmelt(furnaceSmeltEvent, resultItemStack, itemLimit); + + processDoubleSmelt(furnaceSmeltEvent, resultItemStack, furnace); } - private void processDoubleSmelt(@NotNull FurnaceSmeltEvent furnaceSmeltEvent, @NotNull ItemStack resultItemStack, int itemLimit) { + private void processDoubleSmelt(@NotNull FurnaceSmeltEvent furnaceSmeltEvent, @NotNull ItemStack resultItemStack, @NotNull Furnace furnace) { + int itemLimit = resultItemStack.getMaxStackSize(); + + //Check for viewers + if(furnace.getInventory().getViewers().size() > 0) { + 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 + /* + Momshroom02/26/2021 + 1) have max (or close to it) smelting. + 2) put more than half a stack of an ore in a furnace and wait for it to smelt. + 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). + 4) shift click on the furnace output to remove only one item-- leaving 63. + 5) let one more item smelt so the furnace appears to have 64 + 6) manually drag (don't shift click) the stack of product out of the furnace- it'll be 65 items + 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. + */ + } + //TODO: Permission check work around, could store it as NBT on the furnace //We don't do permission checks because this can be for an offline player and Bukkit has nothing to grab permissions for offline players //Process double smelt if (Config.getInstance().getDoubleDropsEnabled(PrimarySkillType.SMELTING, resultItemStack.getType()) - && resultItemStack.getAmount() < itemLimit + && resultItemStack.getAmount() < itemLimit //We take away 1 because there's a certain "exploit" when certain plugins are used in combination && isSecondSmeltSuccessful()) { ItemStack newResult = resultItemStack.clone(); From afd2b509009acf8c4d185cd831d1103ec13ec9f7 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Tue, 2 Mar 2021 11:24:44 -0800 Subject: [PATCH 3/5] Remove unecessary comment --- .../java/com/gmail/nossr50/skills/smelting/SmeltingManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/gmail/nossr50/skills/smelting/SmeltingManager.java b/src/main/java/com/gmail/nossr50/skills/smelting/SmeltingManager.java index 0f1b342f9..d5b203c42 100644 --- a/src/main/java/com/gmail/nossr50/skills/smelting/SmeltingManager.java +++ b/src/main/java/com/gmail/nossr50/skills/smelting/SmeltingManager.java @@ -144,7 +144,7 @@ public class SmeltingManager extends SkillManager { //Process double smelt if (Config.getInstance().getDoubleDropsEnabled(PrimarySkillType.SMELTING, resultItemStack.getType()) - && resultItemStack.getAmount() < itemLimit //We take away 1 because there's a certain "exploit" when certain plugins are used in combination + && resultItemStack.getAmount() < itemLimit && isSecondSmeltSuccessful()) { ItemStack newResult = resultItemStack.clone(); From e38bc14e860c5c50a2fc5d46ae87a0a8f9e0b19f Mon Sep 17 00:00:00 2001 From: nossr50 Date: Tue, 2 Mar 2021 13:54:20 -0800 Subject: [PATCH 4/5] Sometimes I hate being dyslexic, fixing illegal stack sizes in smelting.. again --- .../nossr50/listeners/InventoryListener.java | 2 +- .../skills/smelting/SmeltingManager.java | 52 +++++++------------ 2 files changed, 21 insertions(+), 33 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/listeners/InventoryListener.java b/src/main/java/com/gmail/nossr50/listeners/InventoryListener.java index c110de94c..c3a0aa838 100644 --- a/src/main/java/com/gmail/nossr50/listeners/InventoryListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/InventoryListener.java @@ -117,7 +117,7 @@ public class InventoryListener implements Listener { //Profile doesn't exist if(offlineProfile != null) { //Process smelting - offlineProfile.getSmeltingManager().smeltProcessing(event, furnace); + offlineProfile.getSmeltingManager().smeltProcessing(event); } } } diff --git a/src/main/java/com/gmail/nossr50/skills/smelting/SmeltingManager.java b/src/main/java/com/gmail/nossr50/skills/smelting/SmeltingManager.java index d5b203c42..f6b52646b 100644 --- a/src/main/java/com/gmail/nossr50/skills/smelting/SmeltingManager.java +++ b/src/main/java/com/gmail/nossr50/skills/smelting/SmeltingManager.java @@ -11,7 +11,6 @@ import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.random.RandomChanceUtil; import com.gmail.nossr50.util.skills.RankUtils; import com.gmail.nossr50.util.skills.SkillActivationType; -import org.bukkit.block.Furnace; import org.bukkit.event.inventory.FurnaceBurnEvent; import org.bukkit.event.inventory.FurnaceSmeltEvent; import org.bukkit.inventory.ItemStack; @@ -111,48 +110,37 @@ public class SmeltingManager extends SkillManager { } } - public void smeltProcessing(@NotNull FurnaceSmeltEvent furnaceSmeltEvent, @NotNull Furnace furnace) { - ItemStack sourceItemStack = furnaceSmeltEvent.getSource(); - ItemStack resultItemStack = furnaceSmeltEvent.getResult(); + public void smeltProcessing(@NotNull FurnaceSmeltEvent furnaceSmeltEvent) { + applyXpGain(Smelting.getResourceXp(furnaceSmeltEvent.getSource()), XPGainReason.PVE, XPGainSource.PASSIVE); //Add XP - applyXpGain(Smelting.getResourceXp(sourceItemStack), XPGainReason.PVE, XPGainSource.PASSIVE); //Add XP - - - processDoubleSmelt(furnaceSmeltEvent, resultItemStack, furnace); + processDoubleSmelt(furnaceSmeltEvent); } - private void processDoubleSmelt(@NotNull FurnaceSmeltEvent furnaceSmeltEvent, @NotNull ItemStack resultItemStack, @NotNull Furnace furnace) { - int itemLimit = resultItemStack.getMaxStackSize(); - - //Check for viewers - if(furnace.getInventory().getViewers().size() > 0) { - 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 - /* - Momshroom02/26/2021 - 1) have max (or close to it) smelting. - 2) put more than half a stack of an ore in a furnace and wait for it to smelt. - 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). - 4) shift click on the furnace output to remove only one item-- leaving 63. - 5) let one more item smelt so the furnace appears to have 64 - 6) manually drag (don't shift click) the stack of product out of the furnace- it'll be 65 items - 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. - */ - } - - //TODO: Permission check work around, could store it as NBT on the furnace - //We don't do permission checks because this can be for an offline player and Bukkit has nothing to grab permissions for offline players + private void processDoubleSmelt(@NotNull FurnaceSmeltEvent furnaceSmeltEvent) { + ItemStack resultItemStack = furnaceSmeltEvent.getResult(); + /* + doubleSmeltCondition should be equal to the max + */ //Process double smelt if (Config.getInstance().getDoubleDropsEnabled(PrimarySkillType.SMELTING, resultItemStack.getType()) - && resultItemStack.getAmount() < itemLimit + && canDoubleSmeltItemStack(resultItemStack) //Effectively two less than max stack size && isSecondSmeltSuccessful()) { - ItemStack newResult = resultItemStack.clone(); - newResult.setAmount(Math.min(resultItemStack.getAmount() + 1, itemLimit)); //Don't go over max stack limits - furnaceSmeltEvent.setResult(newResult); + ItemStack doubleSmeltStack = resultItemStack.clone(); //TODO: Necessary? + doubleSmeltStack.setAmount(resultItemStack.getAmount() + 1); //Add one + furnaceSmeltEvent.setResult(doubleSmeltStack); //Set result } } + private boolean canDoubleSmeltItemStack(@NotNull ItemStack itemStack) { + int resultAmount = itemStack.getAmount(); //Amount before double smelt + int itemLimit = itemStack.getMaxStackSize(); + int doubleSmeltCondition = itemLimit - 2; //Don't double smelt if it would cause an illegal stack size + + return resultAmount <= doubleSmeltCondition; + } + public int vanillaXPBoost(int experience) { return experience * getVanillaXpMultiplier(); } From 4bd9ee0aa5698a21d5f6da9a58c0de254962f4b2 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Tue, 2 Mar 2021 15:17:55 -0800 Subject: [PATCH 5/5] Never expect bukkit API to be intuitive --- .../nossr50/listeners/InventoryListener.java | 2 +- .../skills/smelting/SmeltingManager.java | 22 +++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/listeners/InventoryListener.java b/src/main/java/com/gmail/nossr50/listeners/InventoryListener.java index c3a0aa838..c110de94c 100644 --- a/src/main/java/com/gmail/nossr50/listeners/InventoryListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/InventoryListener.java @@ -117,7 +117,7 @@ public class InventoryListener implements Listener { //Profile doesn't exist if(offlineProfile != null) { //Process smelting - offlineProfile.getSmeltingManager().smeltProcessing(event); + offlineProfile.getSmeltingManager().smeltProcessing(event, furnace); } } } diff --git a/src/main/java/com/gmail/nossr50/skills/smelting/SmeltingManager.java b/src/main/java/com/gmail/nossr50/skills/smelting/SmeltingManager.java index f6b52646b..ddda94ba1 100644 --- a/src/main/java/com/gmail/nossr50/skills/smelting/SmeltingManager.java +++ b/src/main/java/com/gmail/nossr50/skills/smelting/SmeltingManager.java @@ -11,8 +11,10 @@ import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.random.RandomChanceUtil; import com.gmail.nossr50.util.skills.RankUtils; import com.gmail.nossr50.util.skills.SkillActivationType; +import org.bukkit.block.Furnace; import org.bukkit.event.inventory.FurnaceBurnEvent; import org.bukkit.event.inventory.FurnaceSmeltEvent; +import org.bukkit.inventory.FurnaceInventory; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; @@ -110,13 +112,13 @@ public class SmeltingManager extends SkillManager { } } - public void smeltProcessing(@NotNull FurnaceSmeltEvent furnaceSmeltEvent) { + public void smeltProcessing(@NotNull FurnaceSmeltEvent furnaceSmeltEvent, @NotNull Furnace furnace) { applyXpGain(Smelting.getResourceXp(furnaceSmeltEvent.getSource()), XPGainReason.PVE, XPGainSource.PASSIVE); //Add XP - processDoubleSmelt(furnaceSmeltEvent); + processDoubleSmelt(furnaceSmeltEvent, furnace); } - private void processDoubleSmelt(@NotNull FurnaceSmeltEvent furnaceSmeltEvent) { + private void processDoubleSmelt(@NotNull FurnaceSmeltEvent furnaceSmeltEvent, @NotNull Furnace furnace) { ItemStack resultItemStack = furnaceSmeltEvent.getResult(); /* doubleSmeltCondition should be equal to the max @@ -124,7 +126,7 @@ public class SmeltingManager extends SkillManager { //Process double smelt if (Config.getInstance().getDoubleDropsEnabled(PrimarySkillType.SMELTING, resultItemStack.getType()) - && canDoubleSmeltItemStack(resultItemStack) //Effectively two less than max stack size + && canDoubleSmeltItemStack(furnace) //Effectively two less than max stack size && isSecondSmeltSuccessful()) { ItemStack doubleSmeltStack = resultItemStack.clone(); //TODO: Necessary? @@ -133,9 +135,15 @@ public class SmeltingManager extends SkillManager { } } - private boolean canDoubleSmeltItemStack(@NotNull ItemStack itemStack) { - int resultAmount = itemStack.getAmount(); //Amount before double smelt - int itemLimit = itemStack.getMaxStackSize(); + private boolean canDoubleSmeltItemStack(@NotNull Furnace furnace) { + FurnaceInventory furnaceInventory = furnace.getInventory(); + ItemStack furnaceResult = furnaceInventory.getResult(); + + if(furnaceResult == null) + return false; + + int resultAmount = furnaceResult.getAmount(); //Amount before double smelt + int itemLimit = furnaceResult.getMaxStackSize(); int doubleSmeltCondition = itemLimit - 2; //Don't double smelt if it would cause an illegal stack size return resultAmount <= doubleSmeltCondition;