mirror of
https://github.com/Minestom/Minestom.git
synced 2024-11-05 18:32:28 +01:00
Properly call click events for shift & double clicks
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
13c05626e2
commit
ba8da0647e
@ -5,6 +5,7 @@ import net.minestom.server.event.EventDispatcher;
|
||||
import net.minestom.server.event.inventory.InventoryClickEvent;
|
||||
import net.minestom.server.inventory.click.ClickType;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@ -13,6 +14,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
* <p>
|
||||
* See https://wiki.vg/Protocol#Click_Window for more information.
|
||||
*/
|
||||
@ApiStatus.NonExtendable
|
||||
public interface InventoryClickHandler {
|
||||
|
||||
/**
|
||||
@ -78,8 +80,6 @@ public interface InventoryClickHandler {
|
||||
|
||||
default void callClickEvent(@NotNull Player player, Inventory inventory, int slot,
|
||||
@NotNull ClickType clickType, @NotNull ItemStack clicked, @NotNull ItemStack cursor) {
|
||||
InventoryClickEvent inventoryClickEvent = new InventoryClickEvent(inventory, player, slot, clickType, clicked, cursor);
|
||||
EventDispatcher.call(inventoryClickEvent);
|
||||
EventDispatcher.call(new InventoryClickEvent(inventory, player, slot, clickType, clicked, cursor));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,7 +5,10 @@ import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.event.EventDispatcher;
|
||||
import net.minestom.server.event.inventory.InventoryClickEvent;
|
||||
import net.minestom.server.event.inventory.InventoryPreClickEvent;
|
||||
import net.minestom.server.inventory.*;
|
||||
import net.minestom.server.inventory.AbstractInventory;
|
||||
import net.minestom.server.inventory.Inventory;
|
||||
import net.minestom.server.inventory.PlayerInventory;
|
||||
import net.minestom.server.inventory.TransactionType;
|
||||
import net.minestom.server.inventory.condition.InventoryCondition;
|
||||
import net.minestom.server.inventory.condition.InventoryConditionResult;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
@ -154,7 +157,12 @@ public final class InventoryClickProcessor {
|
||||
return true;
|
||||
}, start, end, step);
|
||||
|
||||
ItemStack itemResult = TransactionOption.ALL.fill(targetInventory, pair.left(), pair.right());
|
||||
final ItemStack itemResult = pair.left();
|
||||
final Map<Integer, ItemStack> itemChangesMap = pair.right();
|
||||
itemChangesMap.forEach((Integer s, ItemStack itemStack) -> {
|
||||
targetInventory.setItemStack(s, itemStack);
|
||||
callClickEvent(player, targetInventory, s, ClickType.SHIFT_CLICK, itemStack, cursor);
|
||||
});
|
||||
clickResult.setClicked(itemResult);
|
||||
return clickResult;
|
||||
}
|
||||
@ -306,9 +314,13 @@ public final class InventoryClickProcessor {
|
||||
final InventoryClickResult result = startCondition(player, inv, index, ClickType.DOUBLE_CLICK, itemStack, cursor);
|
||||
return !result.isCancel();
|
||||
});
|
||||
var itemResult = pair.left();
|
||||
var map = pair.right();
|
||||
return TransactionOption.ALL.fill(inv, itemResult, map);
|
||||
final ItemStack itemResult = pair.left();
|
||||
var itemChangesMap = pair.right();
|
||||
itemChangesMap.forEach((Integer s, ItemStack itemStack) -> {
|
||||
inv.setItemStack(s, itemStack);
|
||||
callClickEvent(player, inv, s, ClickType.DOUBLE_CLICK, itemStack, cursor);
|
||||
});
|
||||
return itemResult;
|
||||
};
|
||||
|
||||
ItemStack remain = cursorRule.apply(cursor, remainingAmount);
|
||||
|
Loading…
Reference in New Issue
Block a user