mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-14 04:02:00 +01:00
An inventory can now have multiple InventoryCondition
This commit is contained in:
parent
1cb8166edd
commit
4b3e3e8e65
@ -155,16 +155,17 @@ public class PlayerInit {
|
|||||||
});
|
});
|
||||||
|
|
||||||
player.addEventCallback(PlayerSpawnEvent.class, event -> {
|
player.addEventCallback(PlayerSpawnEvent.class, event -> {
|
||||||
player.setGameMode(GameMode.SURVIVAL);
|
player.setGameMode(GameMode.CREATIVE);
|
||||||
player.teleport(new Position(0, 75, 0));
|
player.teleport(new Position(0, 75, 0));
|
||||||
|
|
||||||
ItemStack item = new ItemStack(Material.STONE, (byte) 43);
|
ItemStack item = new ItemStack(Material.STONE, (byte) 43);
|
||||||
item.setDisplayName("Item name");
|
item.setDisplayName("Item name");
|
||||||
item.getLore().add("a lore line");
|
item.getLore().add("a lore line");
|
||||||
|
//item.setEnchantment(Enchantment.SHARPNESS, 2);
|
||||||
player.getInventory().addItemStack(item);
|
player.getInventory().addItemStack(item);
|
||||||
|
|
||||||
Inventory inventory = new Inventory(InventoryType.CHEST_1_ROW, "Test inventory");
|
Inventory inventory = new Inventory(InventoryType.CHEST_1_ROW, "Test inventory");
|
||||||
inventory.setInventoryCondition((p, slot, clickType, inventoryConditionResult) -> {
|
inventory.addInventoryCondition((p, slot, clickType, inventoryConditionResult) -> {
|
||||||
player.sendMessage("click type: " + clickType);
|
player.sendMessage("click type: " + clickType);
|
||||||
inventoryConditionResult.setCancel(false);
|
inventoryConditionResult.setCancel(false);
|
||||||
});
|
});
|
||||||
|
@ -13,8 +13,10 @@ import net.minestom.server.network.packet.server.play.WindowPropertyPacket;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
import java.util.concurrent.CopyOnWriteArraySet;
|
import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
|
|
||||||
public class Inventory implements InventoryModifier, InventoryClickHandler, Viewable {
|
public class Inventory implements InventoryModifier, InventoryClickHandler, Viewable {
|
||||||
@ -33,7 +35,7 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
|||||||
private Set<Player> viewers = new CopyOnWriteArraySet<>();
|
private Set<Player> viewers = new CopyOnWriteArraySet<>();
|
||||||
private ConcurrentHashMap<Player, ItemStack> cursorPlayersItem = new ConcurrentHashMap<>();
|
private ConcurrentHashMap<Player, ItemStack> cursorPlayersItem = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private InventoryCondition inventoryCondition;
|
private List<InventoryCondition> inventoryConditions = new CopyOnWriteArrayList<>();
|
||||||
private InventoryClickProcessor clickProcessor = new InventoryClickProcessor();
|
private InventoryClickProcessor clickProcessor = new InventoryClickProcessor();
|
||||||
|
|
||||||
public Inventory(InventoryType inventoryType, String title) {
|
public Inventory(InventoryType inventoryType, String title) {
|
||||||
@ -95,13 +97,13 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InventoryCondition getInventoryCondition() {
|
public List<InventoryCondition> getInventoryConditions() {
|
||||||
return inventoryCondition;
|
return inventoryConditions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setInventoryCondition(InventoryCondition inventoryCondition) {
|
public void addInventoryCondition(InventoryCondition inventoryCondition) {
|
||||||
this.inventoryCondition = inventoryCondition;
|
this.inventoryConditions.add(inventoryCondition);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update() {
|
public void update() {
|
||||||
@ -174,7 +176,7 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
|||||||
ItemStack clicked = isInWindow ? getItemStack(slot) : playerInventory.getItemStack(slot, offset);
|
ItemStack clicked = isInWindow ? getItemStack(slot) : playerInventory.getItemStack(slot, offset);
|
||||||
|
|
||||||
|
|
||||||
InventoryClickResult clickResult = clickProcessor.leftClick(getInventoryCondition(), player, slot, clicked, cursor);
|
InventoryClickResult clickResult = clickProcessor.leftClick(getInventoryConditions(), player, slot, clicked, cursor);
|
||||||
|
|
||||||
if (clickResult.doRefresh())
|
if (clickResult.doRefresh())
|
||||||
player.getPlayerConnection().sendPacket(getWindowItemsPacket());
|
player.getPlayerConnection().sendPacket(getWindowItemsPacket());
|
||||||
@ -195,7 +197,7 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
|||||||
boolean isInWindow = isClickInWindow(slot);
|
boolean isInWindow = isClickInWindow(slot);
|
||||||
ItemStack clicked = isInWindow ? getItemStack(slot) : playerInventory.getItemStack(slot, offset);
|
ItemStack clicked = isInWindow ? getItemStack(slot) : playerInventory.getItemStack(slot, offset);
|
||||||
|
|
||||||
InventoryClickResult clickResult = clickProcessor.rightClick(getInventoryCondition(), player, slot, clicked, cursor);
|
InventoryClickResult clickResult = clickProcessor.rightClick(getInventoryConditions(), player, slot, clicked, cursor);
|
||||||
|
|
||||||
if (clickResult.doRefresh())
|
if (clickResult.doRefresh())
|
||||||
player.getPlayerConnection().sendPacket(getWindowItemsPacket());
|
player.getPlayerConnection().sendPacket(getWindowItemsPacket());
|
||||||
@ -220,7 +222,7 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
|||||||
InventoryClickResult clickResult;
|
InventoryClickResult clickResult;
|
||||||
|
|
||||||
if (isInWindow) {
|
if (isInWindow) {
|
||||||
clickResult = clickProcessor.shiftClick(getInventoryCondition(), player, slot, clicked, cursor,
|
clickResult = clickProcessor.shiftClick(getInventoryConditions(), player, slot, clicked, cursor,
|
||||||
// Player inventory loop
|
// Player inventory loop
|
||||||
new InventoryClickLoopHandler(0, PlayerInventory.INVENTORY_SIZE, 1,
|
new InventoryClickLoopHandler(0, PlayerInventory.INVENTORY_SIZE, 1,
|
||||||
i -> playerInventory.convertToPacketSlot(i),
|
i -> playerInventory.convertToPacketSlot(i),
|
||||||
@ -233,7 +235,7 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
} else {
|
} else {
|
||||||
clickResult = clickProcessor.shiftClick(getInventoryCondition(), player, slot, clicked, cursor,
|
clickResult = clickProcessor.shiftClick(getInventoryConditions(), player, slot, clicked, cursor,
|
||||||
// Window loop
|
// Window loop
|
||||||
new InventoryClickLoopHandler(0, itemStacks.length, 1,
|
new InventoryClickLoopHandler(0, itemStacks.length, 1,
|
||||||
i -> i,
|
i -> i,
|
||||||
@ -265,7 +267,7 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
|||||||
ItemStack clicked = isInWindow ? getItemStack(slot) : playerInventory.getItemStack(slot, offset);
|
ItemStack clicked = isInWindow ? getItemStack(slot) : playerInventory.getItemStack(slot, offset);
|
||||||
ItemStack heldItem = playerInventory.getItemStack(key);
|
ItemStack heldItem = playerInventory.getItemStack(key);
|
||||||
|
|
||||||
InventoryClickResult clickResult = clickProcessor.changeHeld(getInventoryCondition(), player, slot, clicked, heldItem);
|
InventoryClickResult clickResult = clickProcessor.changeHeld(getInventoryConditions(), player, slot, clicked, heldItem);
|
||||||
|
|
||||||
if (clickResult.doRefresh())
|
if (clickResult.doRefresh())
|
||||||
player.getPlayerConnection().sendPacket(getWindowItemsPacket());
|
player.getPlayerConnection().sendPacket(getWindowItemsPacket());
|
||||||
@ -291,7 +293,7 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
|||||||
null : (isInWindow ? getItemStack(slot) : playerInventory.getItemStack(slot, offset));
|
null : (isInWindow ? getItemStack(slot) : playerInventory.getItemStack(slot, offset));
|
||||||
ItemStack cursor = getCursorItem(player);
|
ItemStack cursor = getCursorItem(player);
|
||||||
|
|
||||||
InventoryClickResult clickResult = clickProcessor.drop(getInventoryCondition(), player,
|
InventoryClickResult clickResult = clickProcessor.drop(getInventoryConditions(), player,
|
||||||
mode, slot, button, clicked, cursor);
|
mode, slot, button, clicked, cursor);
|
||||||
|
|
||||||
if (clickResult.doRefresh())
|
if (clickResult.doRefresh())
|
||||||
@ -319,7 +321,7 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
|||||||
if (slot != -999)
|
if (slot != -999)
|
||||||
clicked = isInWindow ? getItemStack(slot) : playerInventory.getItemStack(slot, offset);
|
clicked = isInWindow ? getItemStack(slot) : playerInventory.getItemStack(slot, offset);
|
||||||
|
|
||||||
InventoryClickResult clickResult = clickProcessor.dragging(getInventoryCondition(), player,
|
InventoryClickResult clickResult = clickProcessor.dragging(getInventoryConditions(), player,
|
||||||
slot, button,
|
slot, button,
|
||||||
clicked, cursor,
|
clicked, cursor,
|
||||||
|
|
||||||
@ -349,7 +351,7 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
|||||||
ItemStack cursor = getCursorItem(player);
|
ItemStack cursor = getCursorItem(player);
|
||||||
|
|
||||||
|
|
||||||
InventoryClickResult clickResult = clickProcessor.doubleClick(getInventoryCondition(), player, slot, cursor,
|
InventoryClickResult clickResult = clickProcessor.doubleClick(getInventoryConditions(), player, slot, cursor,
|
||||||
// Start by looping through the opened inventory
|
// Start by looping through the opened inventory
|
||||||
new InventoryClickLoopHandler(0, itemStacks.length, 1,
|
new InventoryClickLoopHandler(0, itemStacks.length, 1,
|
||||||
i -> i,
|
i -> i,
|
||||||
|
@ -3,6 +3,8 @@ package net.minestom.server.inventory;
|
|||||||
import net.minestom.server.inventory.condition.InventoryCondition;
|
import net.minestom.server.inventory.condition.InventoryCondition;
|
||||||
import net.minestom.server.item.ItemStack;
|
import net.minestom.server.item.ItemStack;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface InventoryModifier {
|
public interface InventoryModifier {
|
||||||
|
|
||||||
void setItemStack(int slot, ItemStack itemStack);
|
void setItemStack(int slot, ItemStack itemStack);
|
||||||
@ -13,7 +15,7 @@ public interface InventoryModifier {
|
|||||||
|
|
||||||
ItemStack[] getItemStacks();
|
ItemStack[] getItemStacks();
|
||||||
|
|
||||||
InventoryCondition getInventoryCondition();
|
List<InventoryCondition> getInventoryConditions();
|
||||||
|
|
||||||
void setInventoryCondition(InventoryCondition inventoryCondition);
|
void addInventoryCondition(InventoryCondition inventoryCondition);
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,8 @@ import net.minestom.server.network.packet.server.play.WindowItemsPacket;
|
|||||||
import net.minestom.server.network.player.PlayerConnection;
|
import net.minestom.server.network.player.PlayerConnection;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
import static net.minestom.server.utils.inventory.PlayerInventoryUtils.*;
|
import static net.minestom.server.utils.inventory.PlayerInventoryUtils.*;
|
||||||
|
|
||||||
@ -25,7 +27,7 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
|
|||||||
private ItemStack[] items = new ItemStack[INVENTORY_SIZE];
|
private ItemStack[] items = new ItemStack[INVENTORY_SIZE];
|
||||||
private ItemStack cursorItem = ItemStack.getAirItem();
|
private ItemStack cursorItem = ItemStack.getAirItem();
|
||||||
|
|
||||||
private InventoryCondition inventoryCondition;
|
private List<InventoryCondition> inventoryConditions = new CopyOnWriteArrayList<>();
|
||||||
private InventoryClickProcessor clickProcessor = new InventoryClickProcessor();
|
private InventoryClickProcessor clickProcessor = new InventoryClickProcessor();
|
||||||
|
|
||||||
public PlayerInventory(Player player) {
|
public PlayerInventory(Player player) {
|
||||||
@ -47,13 +49,13 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InventoryCondition getInventoryCondition() {
|
public List<InventoryCondition> getInventoryConditions() {
|
||||||
return inventoryCondition;
|
return inventoryConditions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setInventoryCondition(InventoryCondition inventoryCondition) {
|
public void addInventoryCondition(InventoryCondition inventoryCondition) {
|
||||||
this.inventoryCondition = inventoryCondition;
|
this.inventoryConditions.add(inventoryCondition);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -278,7 +280,7 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
|
|||||||
ItemStack cursor = getCursorItem();
|
ItemStack cursor = getCursorItem();
|
||||||
ItemStack clicked = getItemStack(convertSlot(slot, OFFSET));
|
ItemStack clicked = getItemStack(convertSlot(slot, OFFSET));
|
||||||
|
|
||||||
InventoryClickResult clickResult = clickProcessor.leftClick(getInventoryCondition(), player, slot, clicked, cursor);
|
InventoryClickResult clickResult = clickProcessor.leftClick(getInventoryConditions(), player, slot, clicked, cursor);
|
||||||
|
|
||||||
if (clickResult.doRefresh())
|
if (clickResult.doRefresh())
|
||||||
sendSlotRefresh((short) slot, clicked);
|
sendSlotRefresh((short) slot, clicked);
|
||||||
@ -292,7 +294,7 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
|
|||||||
ItemStack cursor = getCursorItem();
|
ItemStack cursor = getCursorItem();
|
||||||
ItemStack clicked = getItemStack(slot, OFFSET);
|
ItemStack clicked = getItemStack(slot, OFFSET);
|
||||||
|
|
||||||
InventoryClickResult clickResult = clickProcessor.rightClick(getInventoryCondition(), player, slot, clicked, cursor);
|
InventoryClickResult clickResult = clickProcessor.rightClick(getInventoryConditions(), player, slot, clicked, cursor);
|
||||||
|
|
||||||
if (clickResult.doRefresh())
|
if (clickResult.doRefresh())
|
||||||
sendSlotRefresh((short) slot, clicked);
|
sendSlotRefresh((short) slot, clicked);
|
||||||
@ -311,7 +313,7 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
|
|||||||
ItemStack cursor = getCursorItem();
|
ItemStack cursor = getCursorItem();
|
||||||
ItemStack clicked = slot == -999 ? null : getItemStack(slot, OFFSET);
|
ItemStack clicked = slot == -999 ? null : getItemStack(slot, OFFSET);
|
||||||
|
|
||||||
InventoryClickResult clickResult = clickProcessor.drop(getInventoryCondition(), player,
|
InventoryClickResult clickResult = clickProcessor.drop(getInventoryConditions(), player,
|
||||||
mode, slot, button, clicked, cursor);
|
mode, slot, button, clicked, cursor);
|
||||||
|
|
||||||
if (clickResult.doRefresh())
|
if (clickResult.doRefresh())
|
||||||
@ -329,7 +331,7 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
|
|||||||
ItemStack clicked = getItemStack(slot, OFFSET);
|
ItemStack clicked = getItemStack(slot, OFFSET);
|
||||||
|
|
||||||
boolean hotbarClick = convertToPacketSlot(slot) < 9;
|
boolean hotbarClick = convertToPacketSlot(slot) < 9;
|
||||||
InventoryClickResult clickResult = clickProcessor.shiftClick(getInventoryCondition(), player, slot, clicked, cursor,
|
InventoryClickResult clickResult = clickProcessor.shiftClick(getInventoryConditions(), player, slot, clicked, cursor,
|
||||||
new InventoryClickLoopHandler(0, items.length, 1,
|
new InventoryClickLoopHandler(0, items.length, 1,
|
||||||
i -> {
|
i -> {
|
||||||
if (hotbarClick) {
|
if (hotbarClick) {
|
||||||
@ -358,7 +360,7 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
|
|||||||
ItemStack heldItem = getItemStack(key);
|
ItemStack heldItem = getItemStack(key);
|
||||||
ItemStack clicked = getItemStack(slot, OFFSET);
|
ItemStack clicked = getItemStack(slot, OFFSET);
|
||||||
|
|
||||||
InventoryClickResult clickResult = clickProcessor.changeHeld(getInventoryCondition(), player, slot, clicked, heldItem);
|
InventoryClickResult clickResult = clickProcessor.changeHeld(getInventoryConditions(), player, slot, clicked, heldItem);
|
||||||
|
|
||||||
if (clickResult.doRefresh())
|
if (clickResult.doRefresh())
|
||||||
sendSlotRefresh((short) slot, clicked);
|
sendSlotRefresh((short) slot, clicked);
|
||||||
@ -374,7 +376,7 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
|
|||||||
if (slot != -999)
|
if (slot != -999)
|
||||||
clicked = getItemStack(slot, OFFSET);
|
clicked = getItemStack(slot, OFFSET);
|
||||||
|
|
||||||
InventoryClickResult clickResult = clickProcessor.dragging(getInventoryCondition(), player,
|
InventoryClickResult clickResult = clickProcessor.dragging(getInventoryConditions(), player,
|
||||||
slot, button,
|
slot, button,
|
||||||
clicked, cursor, s -> getItemStack(s, OFFSET),
|
clicked, cursor, s -> getItemStack(s, OFFSET),
|
||||||
(s, item) -> setItemStack(s, OFFSET, item));
|
(s, item) -> setItemStack(s, OFFSET, item));
|
||||||
@ -392,7 +394,7 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
|
|||||||
public void doubleClick(Player player, int slot) {
|
public void doubleClick(Player player, int slot) {
|
||||||
ItemStack cursor = getCursorItem();
|
ItemStack cursor = getCursorItem();
|
||||||
|
|
||||||
InventoryClickResult clickResult = clickProcessor.doubleClick(getInventoryCondition(), player, slot, cursor,
|
InventoryClickResult clickResult = clickProcessor.doubleClick(getInventoryConditions(), player, slot, cursor,
|
||||||
new InventoryClickLoopHandler(0, items.length, 1,
|
new InventoryClickLoopHandler(0, items.length, 1,
|
||||||
i -> i < 9 ? i + 9 : i - 9,
|
i -> i < 9 ? i + 9 : i - 9,
|
||||||
index -> items[index],
|
index -> items[index],
|
||||||
|
@ -6,10 +6,7 @@ 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 java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
@ -19,8 +16,8 @@ public class InventoryClickProcessor {
|
|||||||
private Map<Player, Set<Integer>> leftDraggingMap = new HashMap<>();
|
private Map<Player, Set<Integer>> leftDraggingMap = new HashMap<>();
|
||||||
private Map<Player, Set<Integer>> rightDraggingMap = new HashMap<>();
|
private Map<Player, Set<Integer>> rightDraggingMap = new HashMap<>();
|
||||||
|
|
||||||
public InventoryClickResult leftClick(InventoryCondition inventoryCondition, Player player, int slot, ItemStack clicked, ItemStack cursor) {
|
public InventoryClickResult leftClick(List<InventoryCondition> inventoryConditions, Player player, int slot, ItemStack clicked, ItemStack cursor) {
|
||||||
InventoryClickResult clickResult = startCondition(inventoryCondition, player, slot, ClickType.LEFT_CLICK, clicked, cursor);
|
InventoryClickResult clickResult = startCondition(inventoryConditions, player, slot, ClickType.LEFT_CLICK, clicked, cursor);
|
||||||
|
|
||||||
if (clickResult.isCancel()) {
|
if (clickResult.isCancel()) {
|
||||||
return clickResult;
|
return clickResult;
|
||||||
@ -62,8 +59,8 @@ public class InventoryClickProcessor {
|
|||||||
return clickResult;
|
return clickResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
public InventoryClickResult rightClick(InventoryCondition inventoryCondition, Player player, int slot, ItemStack clicked, ItemStack cursor) {
|
public InventoryClickResult rightClick(List<InventoryCondition> inventoryConditions, Player player, int slot, ItemStack clicked, ItemStack cursor) {
|
||||||
InventoryClickResult clickResult = startCondition(inventoryCondition, player, slot, ClickType.RIGHT_CLICK, clicked, cursor);
|
InventoryClickResult clickResult = startCondition(inventoryConditions, player, slot, ClickType.RIGHT_CLICK, clicked, cursor);
|
||||||
|
|
||||||
if (clickResult.isCancel()) {
|
if (clickResult.isCancel()) {
|
||||||
return clickResult;
|
return clickResult;
|
||||||
@ -119,8 +116,8 @@ public class InventoryClickProcessor {
|
|||||||
return clickResult;
|
return clickResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
public InventoryClickResult changeHeld(InventoryCondition inventoryCondition, Player player, int slot, ItemStack clicked, ItemStack cursor) {
|
public InventoryClickResult changeHeld(List<InventoryCondition> inventoryConditions, Player player, int slot, ItemStack clicked, ItemStack cursor) {
|
||||||
InventoryClickResult clickResult = startCondition(inventoryCondition, player, slot, ClickType.CHANGE_HELD, clicked, cursor);
|
InventoryClickResult clickResult = startCondition(inventoryConditions, player, slot, ClickType.CHANGE_HELD, clicked, cursor);
|
||||||
|
|
||||||
if (clickResult.isCancel()) {
|
if (clickResult.isCancel()) {
|
||||||
return clickResult;
|
return clickResult;
|
||||||
@ -156,7 +153,7 @@ public class InventoryClickProcessor {
|
|||||||
return clickResult;
|
return clickResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
public InventoryClickResult shiftClick(InventoryCondition inventoryCondition, Player player, int slot,
|
public InventoryClickResult shiftClick(List<InventoryCondition> inventoryConditions, Player player, int slot,
|
||||||
ItemStack clicked, ItemStack cursor, InventoryClickLoopHandler... loopHandlers) {
|
ItemStack clicked, ItemStack cursor, InventoryClickLoopHandler... loopHandlers) {
|
||||||
InventoryClickResult clickResult = new InventoryClickResult(clicked, cursor);
|
InventoryClickResult clickResult = new InventoryClickResult(clicked, cursor);
|
||||||
|
|
||||||
@ -186,7 +183,7 @@ public class InventoryClickProcessor {
|
|||||||
StackingRule itemRule = item.getStackingRule();
|
StackingRule itemRule = item.getStackingRule();
|
||||||
if (itemRule.canBeStacked(item, clicked)) {
|
if (itemRule.canBeStacked(item, clicked)) {
|
||||||
|
|
||||||
clickResult = startCondition(clickResult, inventoryCondition, player, index, ClickType.SHIFT_CLICK, item, cursor);
|
clickResult = startCondition(clickResult, inventoryConditions, player, index, ClickType.SHIFT_CLICK, item, cursor);
|
||||||
if (clickResult.isCancel())
|
if (clickResult.isCancel())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -212,7 +209,7 @@ public class InventoryClickProcessor {
|
|||||||
}
|
}
|
||||||
} else if (item.isAir()) {
|
} else if (item.isAir()) {
|
||||||
|
|
||||||
clickResult = startCondition(clickResult, inventoryCondition, player, index, ClickType.SHIFT_CLICK, item, cursor);
|
clickResult = startCondition(clickResult, inventoryConditions, player, index, ClickType.SHIFT_CLICK, item, cursor);
|
||||||
if (clickResult.isCancel())
|
if (clickResult.isCancel())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -231,7 +228,7 @@ public class InventoryClickProcessor {
|
|||||||
return clickResult;
|
return clickResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
public InventoryClickResult dragging(InventoryCondition inventoryCondition, Player player,
|
public InventoryClickResult dragging(List<InventoryCondition> inventoryConditions, Player player,
|
||||||
int slot, int button,
|
int slot, int button,
|
||||||
ItemStack clicked, ItemStack cursor,
|
ItemStack clicked, ItemStack cursor,
|
||||||
Function<Integer, ItemStack> itemGetter,
|
Function<Integer, ItemStack> itemGetter,
|
||||||
@ -265,7 +262,7 @@ public class InventoryClickProcessor {
|
|||||||
ItemStack draggedItem = cursor.clone();
|
ItemStack draggedItem = cursor.clone();
|
||||||
ItemStack slotItem = itemGetter.apply(s);
|
ItemStack slotItem = itemGetter.apply(s);
|
||||||
|
|
||||||
clickResult = startCondition(clickResult, inventoryCondition, player, s, ClickType.DRAGGING, slotItem, cursor);
|
clickResult = startCondition(clickResult, inventoryConditions, player, s, ClickType.DRAGGING, slotItem, cursor);
|
||||||
if (clickResult.isCancel())
|
if (clickResult.isCancel())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -303,7 +300,7 @@ public class InventoryClickProcessor {
|
|||||||
ItemStack draggedItem = cursor.clone();
|
ItemStack draggedItem = cursor.clone();
|
||||||
ItemStack slotItem = itemGetter.apply(s);
|
ItemStack slotItem = itemGetter.apply(s);
|
||||||
|
|
||||||
clickResult = startCondition(clickResult, inventoryCondition, player, s, ClickType.DRAGGING, slotItem, cursor);
|
clickResult = startCondition(clickResult, inventoryConditions, player, s, ClickType.DRAGGING, slotItem, cursor);
|
||||||
if (clickResult.isCancel())
|
if (clickResult.isCancel())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -345,7 +342,7 @@ public class InventoryClickProcessor {
|
|||||||
return clickResult;
|
return clickResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
public InventoryClickResult doubleClick(InventoryCondition inventoryCondition, Player player, int slot,
|
public InventoryClickResult doubleClick(List<InventoryCondition> inventoryConditions, Player player, int slot,
|
||||||
ItemStack cursor, InventoryClickLoopHandler... loopHandlers) {
|
ItemStack cursor, InventoryClickLoopHandler... loopHandlers) {
|
||||||
InventoryClickResult clickResult = new InventoryClickResult(ItemStack.getAirItem(), cursor);
|
InventoryClickResult clickResult = new InventoryClickResult(ItemStack.getAirItem(), cursor);
|
||||||
|
|
||||||
@ -377,7 +374,7 @@ public class InventoryClickProcessor {
|
|||||||
if (!cursorRule.canApply(cursor, amount + 1))
|
if (!cursorRule.canApply(cursor, amount + 1))
|
||||||
break;
|
break;
|
||||||
if (cursorRule.canBeStacked(cursor, item)) {
|
if (cursorRule.canBeStacked(cursor, item)) {
|
||||||
clickResult = startCondition(clickResult, inventoryCondition, player, index, ClickType.DOUBLE_CLICK, item, cursor);
|
clickResult = startCondition(clickResult, inventoryConditions, player, index, ClickType.DOUBLE_CLICK, item, cursor);
|
||||||
if (clickResult.isCancel())
|
if (clickResult.isCancel())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -401,10 +398,10 @@ public class InventoryClickProcessor {
|
|||||||
return clickResult;
|
return clickResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
public InventoryClickResult drop(InventoryCondition inventoryCondition, Player player,
|
public InventoryClickResult drop(List<InventoryCondition> inventoryConditions, Player player,
|
||||||
int mode, int slot, int button,
|
int mode, int slot, int button,
|
||||||
ItemStack clicked, ItemStack cursor) {
|
ItemStack clicked, ItemStack cursor) {
|
||||||
InventoryClickResult clickResult = startCondition(inventoryCondition, player, slot, ClickType.DROP, clicked, cursor);
|
InventoryClickResult clickResult = startCondition(inventoryConditions, player, slot, ClickType.DROP, clicked, cursor);
|
||||||
|
|
||||||
if (clickResult.isCancel()) {
|
if (clickResult.isCancel()) {
|
||||||
return clickResult;
|
return clickResult;
|
||||||
@ -461,27 +458,29 @@ public class InventoryClickProcessor {
|
|||||||
return clickResult;
|
return clickResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
private InventoryClickResult startCondition(InventoryClickResult clickResult, InventoryCondition inventoryCondition, Player player, int slot, ClickType clickType, ItemStack clicked, ItemStack cursor) {
|
private InventoryClickResult startCondition(InventoryClickResult clickResult, List<InventoryCondition> inventoryConditions, Player player, int slot, ClickType clickType, ItemStack clicked, ItemStack cursor) {
|
||||||
if (inventoryCondition != null) {
|
if (!inventoryConditions.isEmpty()) {
|
||||||
InventoryConditionResult result = new InventoryConditionResult(clicked, cursor);
|
for (InventoryCondition inventoryCondition : inventoryConditions) {
|
||||||
inventoryCondition.accept(player, slot, clickType, result);
|
InventoryConditionResult result = new InventoryConditionResult(clicked, cursor);
|
||||||
|
inventoryCondition.accept(player, slot, clickType, result);
|
||||||
|
|
||||||
cursor = result.getCursorItem();
|
cursor = result.getCursorItem();
|
||||||
clicked = result.getClickedItem();
|
clicked = result.getClickedItem();
|
||||||
|
|
||||||
clickResult.setCancel(result.isCancel());
|
clickResult.setCancel(result.isCancel());
|
||||||
if (result.isCancel()) {
|
if (result.isCancel()) {
|
||||||
clickResult.setClicked(clicked);
|
clickResult.setClicked(clicked);
|
||||||
clickResult.setCursor(cursor);
|
clickResult.setCursor(cursor);
|
||||||
clickResult.setRefresh(true);
|
clickResult.setRefresh(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return clickResult;
|
return clickResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
private InventoryClickResult startCondition(InventoryCondition inventoryCondition, Player player, int slot, ClickType clickType, ItemStack clicked, ItemStack cursor) {
|
private InventoryClickResult startCondition(List<InventoryCondition> inventoryConditions, Player player, int slot, ClickType clickType, ItemStack clicked, ItemStack cursor) {
|
||||||
InventoryClickResult clickResult = new InventoryClickResult(clicked, cursor);
|
InventoryClickResult clickResult = new InventoryClickResult(clicked, cursor);
|
||||||
return startCondition(clickResult, inventoryCondition, player, slot, clickType, clicked, cursor);
|
return startCondition(clickResult, inventoryConditions, player, slot, clickType, clicked, cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -91,6 +91,7 @@ public class NbtReaderUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
reader.readByte();
|
reader.readByte();
|
||||||
|
readItemStackNBT(reader, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -138,10 +138,8 @@ public class Utils {
|
|||||||
|
|
||||||
// FIXME: Enchantment
|
// FIXME: Enchantment
|
||||||
{
|
{
|
||||||
System.out.println("ENCODAGE");
|
|
||||||
Map<Enchantment, Integer> enchantmentMap = itemStack.getEnchantmentMap();
|
Map<Enchantment, Integer> enchantmentMap = itemStack.getEnchantmentMap();
|
||||||
if (!enchantmentMap.isEmpty()) {
|
if (!enchantmentMap.isEmpty()) {
|
||||||
System.out.println("write enchant");
|
|
||||||
packet.writeByte((byte) 0x09); // list
|
packet.writeByte((byte) 0x09); // list
|
||||||
packet.writeShortSizedString("StoredEnchantments");
|
packet.writeShortSizedString("StoredEnchantments");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user