From ddbd621535249fb59d731f0c2dfa5e5070272878 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Tue, 8 Jun 2021 19:55:11 +0200 Subject: [PATCH] Change dragging events Now fires a start dragging, then a dragging for each slot and then an end dragging. --- .../server/inventory/click/ClickType.java | 3 ++ .../click/InventoryClickProcessor.java | 30 ++++++++++--------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/main/java/net/minestom/server/inventory/click/ClickType.java b/src/main/java/net/minestom/server/inventory/click/ClickType.java index ae1a3f97e..c6fe8eda8 100644 --- a/src/main/java/net/minestom/server/inventory/click/ClickType.java +++ b/src/main/java/net/minestom/server/inventory/click/ClickType.java @@ -15,6 +15,9 @@ public enum ClickType { LEFT_DRAGGING, RIGHT_DRAGGING, + END_LEFT_DRAGGING, + END_RIGHT_DRAGGING, + START_DOUBLE_CLICK, DOUBLE_CLICK, diff --git a/src/main/java/net/minestom/server/inventory/click/InventoryClickProcessor.java b/src/main/java/net/minestom/server/inventory/click/InventoryClickProcessor.java index b1fd60cc2..a0bf5ff3d 100644 --- a/src/main/java/net/minestom/server/inventory/click/InventoryClickProcessor.java +++ b/src/main/java/net/minestom/server/inventory/click/InventoryClickProcessor.java @@ -261,9 +261,6 @@ public class InventoryClickProcessor { final int slotSize = (int) ((float) cursorAmount / (float) slotCount); int finalCursorAmount = cursorAmount; - // Set to a value in case there are no slots - clickResult = startCondition(inventory, player, slot, ClickType.START_LEFT_DRAGGING, clicked, cursor); - for (int s : slots) { ItemStack slotItem = itemGetter.apply(s); @@ -291,8 +288,14 @@ public class InventoryClickProcessor { callClickEvent(player, inventory, s, ClickType.LEFT_DRAGGING, slotItem, cursor); } - cursor = stackingRule.apply(cursor, finalCursorAmount); - clickResult.setCursor(cursor); + + // If no slots were dragged over, no need to apply any kind of stacking rules + if (clickResult != null) { + cursor = stackingRule.apply(cursor, finalCursorAmount); + clickResult.setCursor(cursor); + } + + clickResult = startCondition(inventory, player, slot, ClickType.END_LEFT_DRAGGING, clicked, cursor); leftDraggingMap.remove(player); } else if (button == 6) { @@ -305,9 +308,6 @@ public class InventoryClickProcessor { if (size > cursorAmount) return null; - // Set to a value in case there are no slots - clickResult = startCondition(inventory, player, slot, ClickType.START_RIGHT_DRAGGING, clicked, cursor); - for (int s : slots) { ItemStack draggedItem = cursor; ItemStack slotItem = itemGetter.apply(s); @@ -332,8 +332,14 @@ public class InventoryClickProcessor { callClickEvent(player, inventory, s, ClickType.RIGHT_DRAGGING, draggedItem, cursor); } - cursor = stackingRule.apply(cursor, cursorAmount); - clickResult.setCursor(cursor); + + // If no slots were dragged over, no need to apply any kind of stacking rules + if (clickResult != null) { + cursor = stackingRule.apply(cursor, cursorAmount); + clickResult.setCursor(cursor); + } + + clickResult = startCondition(inventory, player, slot, ClickType.END_RIGHT_DRAGGING, clicked, cursor); rightDraggingMap.remove(player); @@ -346,15 +352,11 @@ public class InventoryClickProcessor { return null; leftDraggingMap.get(player).add(slot); - clickResult = startCondition(inventory, player, slot, ClickType.START_LEFT_DRAGGING, clicked, cursor); - } else if (button == 5) { // Add right slot if (!rightDraggingMap.containsKey(player)) return null; rightDraggingMap.get(player).add(slot); - - clickResult = startCondition(inventory, player, slot, ClickType.START_RIGHT_DRAGGING, clicked, cursor); } }