mirror of
https://github.com/Minestom/Minestom.git
synced 2025-03-11 14:23:10 +01:00
Merge branch 'master' into event-api
This commit is contained in:
commit
78cc392007
@ -9,8 +9,14 @@ public enum ClickType {
|
||||
START_SHIFT_CLICK,
|
||||
SHIFT_CLICK,
|
||||
|
||||
START_DRAGGING,
|
||||
DRAGGING,
|
||||
START_LEFT_DRAGGING,
|
||||
START_RIGHT_DRAGGING,
|
||||
|
||||
LEFT_DRAGGING,
|
||||
RIGHT_DRAGGING,
|
||||
|
||||
END_LEFT_DRAGGING,
|
||||
END_RIGHT_DRAGGING,
|
||||
|
||||
START_DOUBLE_CLICK,
|
||||
DOUBLE_CLICK,
|
||||
|
@ -233,7 +233,7 @@ public class InventoryClickProcessor {
|
||||
@NotNull ItemStack clicked, @NotNull ItemStack cursor,
|
||||
@NotNull Int2ObjectFunction<ItemStack> itemGetter,
|
||||
@NotNull BiConsumer<Integer, ItemStack> itemSetter) {
|
||||
InventoryClickResult clickResult = startCondition(inventory, player, slot, ClickType.START_DRAGGING, clicked, cursor);
|
||||
InventoryClickResult clickResult = null;
|
||||
|
||||
final StackingRule stackingRule = cursor.getStackingRule();
|
||||
|
||||
@ -241,10 +241,16 @@ public class InventoryClickProcessor {
|
||||
// Start or end left/right drag
|
||||
if (button == 0) {
|
||||
// Start left
|
||||
this.leftDraggingMap.put(player, new IntOpenHashSet());
|
||||
clickResult = startCondition(inventory, player, slot, ClickType.START_LEFT_DRAGGING, clicked, cursor);
|
||||
|
||||
if (!clickResult.isCancel())
|
||||
this.leftDraggingMap.put(player, new IntOpenHashSet());
|
||||
} else if (button == 4) {
|
||||
// Start right
|
||||
this.rightDraggingMap.put(player, new IntOpenHashSet());
|
||||
clickResult = startCondition(inventory, player, slot, ClickType.START_RIGHT_DRAGGING, clicked, cursor);
|
||||
|
||||
if (!clickResult.isCancel())
|
||||
this.rightDraggingMap.put(player, new IntOpenHashSet());
|
||||
} else if (button == 2) {
|
||||
// End left
|
||||
if (!leftDraggingMap.containsKey(player))
|
||||
@ -254,39 +260,58 @@ public class InventoryClickProcessor {
|
||||
final int cursorAmount = stackingRule.getAmount(cursor);
|
||||
if (slotCount > cursorAmount)
|
||||
return null;
|
||||
// Should be size of each defined slot (if not full)
|
||||
final int slotSize = (int) ((float) cursorAmount / (float) slotCount);
|
||||
int finalCursorAmount = cursorAmount;
|
||||
|
||||
boolean cancel = false;
|
||||
|
||||
for (int s : slots) {
|
||||
ItemStack slotItem = itemGetter.apply(s);
|
||||
|
||||
clickResult = startCondition(inventory, player, s, ClickType.DRAGGING, slotItem, cursor);
|
||||
if (clickResult.isCancel())
|
||||
clickResult = startCondition(inventory, player, s, ClickType.LEFT_DRAGGING, slotItem, cursor);
|
||||
|
||||
if (clickResult.isCancel()) {
|
||||
cancel = true;
|
||||
|
||||
break;
|
||||
StackingRule slotItemRule = slotItem.getStackingRule();
|
||||
|
||||
final int maxSize = stackingRule.getMaxSize(cursor);
|
||||
if (stackingRule.canBeStacked(cursor, slotItem)) {
|
||||
final int amount = slotItemRule.getAmount(slotItem);
|
||||
if (stackingRule.canApply(slotItem, amount + slotSize)) {
|
||||
slotItem = stackingRule.apply(slotItem, a -> a + slotSize);
|
||||
finalCursorAmount -= slotSize;
|
||||
} else {
|
||||
final int removedAmount = maxSize - amount;
|
||||
slotItem = stackingRule.apply(slotItem, maxSize);
|
||||
finalCursorAmount -= removedAmount;
|
||||
}
|
||||
} else if (slotItem.isAir()) {
|
||||
slotItem = stackingRule.apply(cursor, slotSize);
|
||||
finalCursorAmount -= slotSize;
|
||||
}
|
||||
itemSetter.accept(s, slotItem);
|
||||
|
||||
callClickEvent(player, inventory, s, ClickType.DRAGGING, slotItem, cursor);
|
||||
}
|
||||
cursor = stackingRule.apply(cursor, finalCursorAmount);
|
||||
clickResult.setCursor(cursor);
|
||||
|
||||
cancel |= startCondition(inventory, player, slot, ClickType.END_LEFT_DRAGGING, clicked, cursor).isCancel();
|
||||
|
||||
// Should be size of each defined slot (if not full)
|
||||
final int slotSize = (int) ((float) cursorAmount / (float) slotCount);
|
||||
int finalCursorAmount = cursorAmount;
|
||||
|
||||
if (!cancel) {
|
||||
for (int s : slots) {
|
||||
ItemStack slotItem = itemGetter.apply(s);
|
||||
StackingRule slotItemRule = slotItem.getStackingRule();
|
||||
|
||||
final int maxSize = stackingRule.getMaxSize(cursor);
|
||||
if (stackingRule.canBeStacked(cursor, slotItem)) {
|
||||
final int amount = slotItemRule.getAmount(slotItem);
|
||||
if (stackingRule.canApply(slotItem, amount + slotSize)) {
|
||||
slotItem = stackingRule.apply(slotItem, a -> a + slotSize);
|
||||
finalCursorAmount -= slotSize;
|
||||
} else {
|
||||
final int removedAmount = maxSize - amount;
|
||||
slotItem = stackingRule.apply(slotItem, maxSize);
|
||||
finalCursorAmount -= removedAmount;
|
||||
}
|
||||
} else if (slotItem.isAir()) {
|
||||
slotItem = stackingRule.apply(cursor, slotSize);
|
||||
finalCursorAmount -= slotSize;
|
||||
}
|
||||
itemSetter.accept(s, slotItem);
|
||||
|
||||
callClickEvent(player, inventory, s, ClickType.LEFT_DRAGGING, slotItem, 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);
|
||||
}
|
||||
}
|
||||
|
||||
leftDraggingMap.remove(player);
|
||||
} else if (button == 6) {
|
||||
@ -298,32 +323,51 @@ public class InventoryClickProcessor {
|
||||
int cursorAmount = stackingRule.getAmount(cursor);
|
||||
if (size > cursorAmount)
|
||||
return null;
|
||||
|
||||
boolean cancel = false;
|
||||
|
||||
for (int s : slots) {
|
||||
ItemStack draggedItem = cursor;
|
||||
ItemStack slotItem = itemGetter.apply(s);
|
||||
|
||||
clickResult = startCondition(inventory, player, s, ClickType.DRAGGING, slotItem, cursor);
|
||||
if (clickResult.isCancel())
|
||||
break;
|
||||
clickResult = startCondition(inventory, player, s, ClickType.RIGHT_DRAGGING, slotItem, cursor);
|
||||
|
||||
StackingRule slotItemRule = slotItem.getStackingRule();
|
||||
if (stackingRule.canBeStacked(draggedItem, slotItem)) {
|
||||
final int amount = slotItemRule.getAmount(slotItem) + 1;
|
||||
if (stackingRule.canApply(slotItem, amount)) {
|
||||
slotItem = stackingRule.apply(slotItem, amount);
|
||||
itemSetter.accept(s, slotItem);
|
||||
if (clickResult.isCancel()) {
|
||||
cancel = true;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
cancel |= startCondition(inventory, player, slot, ClickType.END_RIGHT_DRAGGING, clicked, cursor).isCancel();
|
||||
|
||||
if (!cancel) {
|
||||
for (int s : slots) {
|
||||
ItemStack draggedItem = cursor;
|
||||
ItemStack slotItem = itemGetter.apply(s);
|
||||
|
||||
StackingRule slotItemRule = slotItem.getStackingRule();
|
||||
if (stackingRule.canBeStacked(draggedItem, slotItem)) {
|
||||
final int amount = slotItemRule.getAmount(slotItem) + 1;
|
||||
if (stackingRule.canApply(slotItem, amount)) {
|
||||
slotItem = stackingRule.apply(slotItem, amount);
|
||||
itemSetter.accept(s, slotItem);
|
||||
cursorAmount -= 1;
|
||||
}
|
||||
} else if (slotItem.isAir()) {
|
||||
draggedItem = stackingRule.apply(draggedItem, 1);
|
||||
itemSetter.accept(s, draggedItem);
|
||||
cursorAmount -= 1;
|
||||
}
|
||||
} else if (slotItem.isAir()) {
|
||||
draggedItem = stackingRule.apply(draggedItem, 1);
|
||||
itemSetter.accept(s, draggedItem);
|
||||
cursorAmount -= 1;
|
||||
|
||||
callClickEvent(player, inventory, s, ClickType.RIGHT_DRAGGING, draggedItem, cursor);
|
||||
}
|
||||
|
||||
callClickEvent(player, inventory, s, ClickType.DRAGGING, draggedItem, 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);
|
||||
}
|
||||
}
|
||||
cursor = stackingRule.apply(cursor, cursorAmount);
|
||||
clickResult.setCursor(cursor);
|
||||
|
||||
rightDraggingMap.remove(player);
|
||||
|
||||
|
@ -21,6 +21,7 @@ import net.minestom.server.network.PacketProcessor;
|
||||
import net.minestom.server.network.netty.channel.ClientChannel;
|
||||
import net.minestom.server.network.netty.codec.*;
|
||||
import net.minestom.server.utils.validate.Check;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
@ -28,6 +29,7 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public final class NettyServer {
|
||||
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger(NettyServer.class);
|
||||
@ -172,6 +174,10 @@ public final class NettyServer {
|
||||
}
|
||||
}
|
||||
|
||||
public ServerSocketChannel getServerChannel() {
|
||||
return serverChannel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the address of the server.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user