mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-11 18:02:08 +01:00
Added more click types + fix inventory click cancel
This commit is contained in:
parent
0337fff50f
commit
a7d23bfa50
@ -5,9 +5,16 @@ public enum ClickType {
|
|||||||
LEFT_CLICK,
|
LEFT_CLICK,
|
||||||
RIGHT_CLICK,
|
RIGHT_CLICK,
|
||||||
CHANGE_HELD,
|
CHANGE_HELD,
|
||||||
|
|
||||||
|
START_SHIFT_CLICK,
|
||||||
SHIFT_CLICK,
|
SHIFT_CLICK,
|
||||||
|
|
||||||
|
START_DRAGGING,
|
||||||
DRAGGING,
|
DRAGGING,
|
||||||
|
|
||||||
|
START_DOUBLE_CLICK,
|
||||||
DOUBLE_CLICK,
|
DOUBLE_CLICK,
|
||||||
|
|
||||||
DROP
|
DROP
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,8 @@ import net.minestom.server.inventory.condition.InventoryConditionResult;
|
|||||||
import net.minestom.server.item.ItemStack;
|
import net.minestom.server.item.ItemStack;
|
||||||
import net.minestom.server.item.StackingRule;
|
import net.minestom.server.item.StackingRule;
|
||||||
import net.minestom.server.utils.inventory.PlayerInventoryUtils;
|
import net.minestom.server.utils.inventory.PlayerInventoryUtils;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -167,7 +169,7 @@ public class InventoryClickProcessor {
|
|||||||
|
|
||||||
public InventoryClickResult shiftClick(Inventory inventory, Player player, int slot,
|
public InventoryClickResult shiftClick(Inventory inventory, Player player, int slot,
|
||||||
ItemStack clicked, ItemStack cursor, InventoryClickLoopHandler... loopHandlers) {
|
ItemStack clicked, ItemStack cursor, InventoryClickLoopHandler... loopHandlers) {
|
||||||
InventoryClickResult clickResult = startCondition(inventory, player, slot, ClickType.SHIFT_CLICK, clicked, cursor);
|
InventoryClickResult clickResult = startCondition(inventory, player, slot, ClickType.START_SHIFT_CLICK, clicked, cursor);
|
||||||
|
|
||||||
if (clickResult.isCancel()) {
|
if (clickResult.isCancel()) {
|
||||||
return clickResult;
|
return clickResult;
|
||||||
@ -250,7 +252,7 @@ public class InventoryClickProcessor {
|
|||||||
ItemStack clicked, ItemStack cursor,
|
ItemStack clicked, ItemStack cursor,
|
||||||
Int2ObjectFunction<ItemStack> itemGetter,
|
Int2ObjectFunction<ItemStack> itemGetter,
|
||||||
BiConsumer<Integer, ItemStack> itemSetter) {
|
BiConsumer<Integer, ItemStack> itemSetter) {
|
||||||
InventoryClickResult clickResult = new InventoryClickResult(clicked, cursor);
|
InventoryClickResult clickResult = startCondition(inventory, player, slot, ClickType.START_DRAGGING, clicked, cursor);
|
||||||
|
|
||||||
final StackingRule stackingRule = cursor.getStackingRule();
|
final StackingRule stackingRule = cursor.getStackingRule();
|
||||||
|
|
||||||
@ -365,7 +367,7 @@ public class InventoryClickProcessor {
|
|||||||
|
|
||||||
public InventoryClickResult doubleClick(Inventory inventory, Player player, int slot,
|
public InventoryClickResult doubleClick(Inventory inventory, Player player, int slot,
|
||||||
ItemStack cursor, InventoryClickLoopHandler... loopHandlers) {
|
ItemStack cursor, InventoryClickLoopHandler... loopHandlers) {
|
||||||
InventoryClickResult clickResult = new InventoryClickResult(ItemStack.getAirItem(), cursor);
|
InventoryClickResult clickResult = startCondition(inventory, player, slot, ClickType.START_DOUBLE_CLICK, ItemStack.getAirItem(), cursor);
|
||||||
|
|
||||||
if (clickResult.isCancel()) {
|
if (clickResult.isCancel()) {
|
||||||
return clickResult;
|
return clickResult;
|
||||||
@ -489,8 +491,8 @@ public class InventoryClickProcessor {
|
|||||||
return clickResult;
|
return clickResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
private InventoryClickResult startCondition(InventoryClickResult clickResult, Inventory inventory,
|
private InventoryClickResult startCondition(@NotNull InventoryClickResult clickResult, @Nullable Inventory inventory,
|
||||||
Player player, int slot, ClickType clickType,
|
@NotNull Player player, int slot, @NotNull ClickType clickType,
|
||||||
ItemStack clicked, ItemStack cursor) {
|
ItemStack clicked, ItemStack cursor) {
|
||||||
boolean isPlayerInventory = inventory == null;
|
boolean isPlayerInventory = inventory == null;
|
||||||
final int inventorySlot = isPlayerInventory ? 0 : inventory.getSize();
|
final int inventorySlot = isPlayerInventory ? 0 : inventory.getSize();
|
||||||
@ -557,18 +559,19 @@ public class InventoryClickProcessor {
|
|||||||
return clickResult;
|
return clickResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
private InventoryClickResult startCondition(Inventory inventory, Player player, int slot, ClickType clickType, ItemStack clicked, ItemStack cursor) {
|
private InventoryClickResult startCondition(@Nullable Inventory inventory, @NotNull Player player, int slot,
|
||||||
|
@NotNull ClickType clickType, ItemStack clicked, ItemStack cursor) {
|
||||||
final InventoryClickResult clickResult = new InventoryClickResult(clicked, cursor);
|
final InventoryClickResult clickResult = new InventoryClickResult(clicked, cursor);
|
||||||
return startCondition(clickResult, inventory, player, slot, clickType, clicked, cursor);
|
return startCondition(clickResult, inventory, player, slot, clickType, clicked, cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void callClickEvent(Player player, Inventory inventory, int slot,
|
private void callClickEvent(@NotNull Player player, @Nullable Inventory inventory, int slot,
|
||||||
ClickType clickType, ItemStack clicked, ItemStack cursor) {
|
@NotNull ClickType clickType, ItemStack clicked, ItemStack cursor) {
|
||||||
InventoryClickEvent inventoryClickEvent = new InventoryClickEvent(player, inventory, slot, clickType, clicked, cursor);
|
InventoryClickEvent inventoryClickEvent = new InventoryClickEvent(player, inventory, slot, clickType, clicked, cursor);
|
||||||
player.callEvent(InventoryClickEvent.class, inventoryClickEvent);
|
player.callEvent(InventoryClickEvent.class, inventoryClickEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearCache(Player player) {
|
public void clearCache(@NotNull Player player) {
|
||||||
this.leftDraggingMap.remove(player);
|
this.leftDraggingMap.remove(player);
|
||||||
this.rightDraggingMap.remove(player);
|
this.rightDraggingMap.remove(player);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user