|
4 | 4 | import net.kyori.adventure.text.Component; |
5 | 5 | import net.kyori.adventure.text.minimessage.MiniMessage; |
6 | 6 | import org.bukkit.GameMode; |
| 7 | +import org.bukkit.NamespacedKey; |
7 | 8 | import org.bukkit.entity.Player; |
8 | 9 | import org.bukkit.event.inventory.ClickType; |
9 | 10 | import org.bukkit.event.inventory.InventoryCloseEvent.Reason; |
10 | 11 | import org.bukkit.inventory.ItemStack; |
| 12 | +import org.bukkit.persistence.PersistentDataType; |
11 | 13 | import org.jetbrains.annotations.UnmodifiableView; |
12 | 14 | import org.jspecify.annotations.Nullable; |
13 | 15 | import xyz.xenondevs.invui.Click; |
14 | 16 | import xyz.xenondevs.invui.ClickEvent; |
| 17 | +import xyz.xenondevs.invui.InvUI; |
15 | 18 | import xyz.xenondevs.invui.gui.Gui; |
16 | 19 | import xyz.xenondevs.invui.gui.SlotElement; |
17 | 20 | import xyz.xenondevs.invui.i18n.Languages; |
|
36 | 39 |
|
37 | 40 | non-sealed abstract class AbstractWindow<M extends CustomContainerMenu> implements Window, WindowEventListener { |
38 | 41 |
|
| 42 | + private static final NamespacedKey SLOT_KEY = new NamespacedKey(InvUI.getInstance().getPlugin(), "slot"); |
39 | 43 | private static final ThreadLocal<Boolean> isInOpeningContext = ThreadLocal.withInitial(() -> false); |
40 | 44 | private static final ThreadLocal<Integer> isInCloseHandlerContext = ThreadLocal.withInitial(() -> 0); |
41 | 45 |
|
@@ -110,6 +114,11 @@ protected void update(int slot) { |
110 | 114 | SlotElement lastElement = newPath.getLast(); |
111 | 115 | if (!(lastElement instanceof SlotElement.GuiLink)) { |
112 | 116 | itemStack = lastElement.getItemStack(getViewer()); |
| 117 | + if (itemStack != null && lastElement instanceof SlotElement.Item) { |
| 118 | + // This makes every item unique to prevent Shift-DoubleClick "clicking" multiple items at the same time. |
| 119 | + itemStack = itemStack.clone(); // clone ItemStack in order to not modify the original |
| 120 | + itemStack.editPersistentDataContainer(pdc -> pdc.set(SLOT_KEY, PersistentDataType.BYTE, (byte) slot)); |
| 121 | + } |
113 | 122 | } else { // there is no holding element |
114 | 123 | // background by gui |
115 | 124 | itemStack = newPath.reversed().stream() |
|
0 commit comments