From 28e6ef9b877fe6b66782367b1dfafe408b00be8f Mon Sep 17 00:00:00 2001 From: Felix Cravic Date: Fri, 22 May 2020 23:26:18 +0200 Subject: [PATCH] Give the right result for InventoryClickHandler#drop --- .../server/inventory/InventoryClickHandler.java | 1 - .../inventory/click/InventoryClickProcessor.java | 16 ++++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/minestom/server/inventory/InventoryClickHandler.java b/src/main/java/net/minestom/server/inventory/InventoryClickHandler.java index 3f776f55a..96178c1fa 100644 --- a/src/main/java/net/minestom/server/inventory/InventoryClickHandler.java +++ b/src/main/java/net/minestom/server/inventory/InventoryClickHandler.java @@ -7,7 +7,6 @@ import net.minestom.server.item.ItemStack; /** * Represent an inventory which can receive click input - *

* all methods returning boolean returns true if the action is successful, false otherwise */ public interface InventoryClickHandler { 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 bfa64a713..2fe07ec2a 100644 --- a/src/main/java/net/minestom/server/inventory/click/InventoryClickProcessor.java +++ b/src/main/java/net/minestom/server/inventory/click/InventoryClickProcessor.java @@ -443,13 +443,17 @@ public class InventoryClickProcessor { // Left (drop all) int amount = cursorRule.getAmount(resultCursor); ItemStack dropItem = cursorRule.apply(resultCursor.clone(), amount); - if (player.dropItem(dropItem)) { + boolean dropResult = player.dropItem(dropItem); + clickResult.setCancel(!dropResult); + if (dropResult) { resultCursor = cursorRule.apply(resultCursor, 0); } } else if (button == 1) { // Right (drop 1) ItemStack dropItem = cursorRule.apply(resultCursor.clone(), 1); - if (player.dropItem(dropItem)) { + boolean dropResult = player.dropItem(dropItem); + clickResult.setCancel(!dropResult); + if (dropResult) { int amount = cursorRule.getAmount(resultCursor); int newAmount = amount - 1; resultCursor = cursorRule.apply(resultCursor, newAmount); @@ -460,7 +464,9 @@ public class InventoryClickProcessor { if (button == 0) { // Drop key Q (drop 1) ItemStack dropItem = cursorRule.apply(resultClicked.clone(), 1); - if (player.dropItem(dropItem)) { + boolean dropResult = player.dropItem(dropItem); + clickResult.setCancel(!dropResult); + if (dropResult) { int amount = clickedRule.getAmount(resultClicked); int newAmount = amount - 1; resultClicked = cursorRule.apply(resultClicked, newAmount); @@ -469,7 +475,9 @@ public class InventoryClickProcessor { // Ctrl + Drop key Q (drop all) int amount = cursorRule.getAmount(resultClicked); ItemStack dropItem = clickedRule.apply(resultClicked.clone(), amount); - if (player.dropItem(dropItem)) { + boolean dropResult = player.dropItem(dropItem); + clickResult.setCancel(!dropResult); + if (dropResult) { resultClicked = cursorRule.apply(resultClicked, 0); } }