From 8b2947e3129c4ca3eb53ef284d7935c2b61cb255 Mon Sep 17 00:00:00 2001 From: Gabriel Tofvesson Date: Thu, 20 May 2021 01:25:01 +0200 Subject: [PATCH] Fix stack clearing bug for throwable projectiles --- src/dev/w1zzrd/invtweaks/InvTweaksPlugin.java | 2 +- .../listener/StackReplaceListener.java | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/dev/w1zzrd/invtweaks/InvTweaksPlugin.java b/src/dev/w1zzrd/invtweaks/InvTweaksPlugin.java index 3d03425..239736b 100644 --- a/src/dev/w1zzrd/invtweaks/InvTweaksPlugin.java +++ b/src/dev/w1zzrd/invtweaks/InvTweaksPlugin.java @@ -98,7 +98,7 @@ public final class InvTweaksPlugin extends JavaPlugin { private void initEvents() { final PluginManager pluginManager = getServer().getPluginManager(); - pluginManager.registerEvents(new StackReplaceListener(), this); + pluginManager.registerEvents(new StackReplaceListener(this), this); pluginManager.registerEvents(new SortListener(), this); pluginManager.registerEvents(new MagnetismListener(magnetCommandExecutor), this); pluginManager.registerEvents(new TabCompletionListener(), this); diff --git a/src/dev/w1zzrd/invtweaks/listener/StackReplaceListener.java b/src/dev/w1zzrd/invtweaks/listener/StackReplaceListener.java index 19b0510..cc3f285 100644 --- a/src/dev/w1zzrd/invtweaks/listener/StackReplaceListener.java +++ b/src/dev/w1zzrd/invtweaks/listener/StackReplaceListener.java @@ -12,6 +12,7 @@ import org.bukkit.event.player.PlayerItemBreakEvent; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; +import org.bukkit.plugin.Plugin; import java.util.logging.Logger; @@ -22,6 +23,12 @@ import static dev.w1zzrd.invtweaks.InvTweaksPlugin.LOG_PLUGIN_NAME; */ public class StackReplaceListener implements Listener { + private final Plugin plugin; + + public StackReplaceListener(final Plugin plugin) { + this.plugin = plugin; + } + /** * Max index for main player inventory */ @@ -73,9 +80,14 @@ public class StackReplaceListener implements Listener { slot = EquipmentSlot.OFF_HAND; else return; - if (inventory.getItem(slot).getAmount() == 1 && - findAndMoveSimilarStack(stack, slot, inventory, CompareFunc.defaultFunc())) - logger.fine(LOG_PLUGIN_NAME + " Moved snowball into empty hand for player " + thrower.getName()); + if (inventory.getItem(slot).getAmount() == 1) + Bukkit.getScheduler().runTaskLater( + plugin, + () -> { + if (findAndMoveSimilarStack(stack, slot, inventory, CompareFunc.defaultFunc())) + logger.fine(LOG_PLUGIN_NAME + " Moved snowball into empty hand for player " + thrower.getName()); + }, + 1); } }