Add slot sanity checks in container clicks

This commit is contained in:
Nassim Jahnke
2023-09-11 12:01:57 +10:00
parent a951373bae
commit 5688b5cf50
2 changed files with 73 additions and 53 deletions

View File

@@ -28,11 +28,10 @@
public abstract class AbstractContainerMenu {
private static final Logger LOGGER = LogUtils.getLogger();
@@ -66,6 +80,32 @@
@Nullable
@@ -67,6 +81,32 @@
private ContainerSynchronizer synchronizer;
private boolean suppressRemoteUpdates;
+
+ // CraftBukkit start
+ public boolean checkReachable = true;
+ public abstract InventoryView getBukkitView();
@@ -58,30 +57,30 @@
+ this.title = title;
+ }
+ // CraftBukkit end
+
protected AbstractContainerMenu(@Nullable MenuType<?> type, int syncId) {
this.carried = ItemStack.EMPTY;
@@ -188,10 +228,20 @@
this.remoteSlots = NonNullList.create();
@@ -188,9 +228,19 @@
if (this.synchronizer != null) {
this.synchronizer.sendInitialData(this, this.remoteSlots, this.remoteCarried, this.remoteDataSlots.toIntArray());
+ this.synchronizer.sendOffHandSlotChange(); // Paper - Sync offhand slot in menus; update player's offhand since the offhand slot is not added to the slots for menus but can be changed by swapping from a menu slot
}
}
+ }
+
+ // CraftBukkit start
+ public void broadcastCarriedItem() {
+ this.remoteCarried = this.getCarried().copy();
+ if (this.synchronizer != null) {
+ this.synchronizer.sendCarriedChange(this, this.remoteCarried);
+ }
+ }
}
+ // CraftBukkit end
+
public void removeSlotListener(ContainerListener listener) {
this.containerListeners.remove(listener);
}
@@ -281,7 +331,7 @@
while (iterator.hasNext()) {
ContainerListener icrafting = (ContainerListener) iterator.next();
@@ -91,7 +90,15 @@
}
}
@@ -417,7 +467,7 @@
@@ -410,6 +460,7 @@
this.resetQuickCraft();
}
} else if (this.quickcraftStatus == 1) {
+ if (slotIndex < 0) return; // Paper - Add slot sanity checks to container clicks
slot = (Slot) this.slots.get(slotIndex);
itemstack = this.getCarried();
if (AbstractContainerMenu.canItemQuickReplace(slot, itemstack, true) && slot.mayPlace(itemstack) && (this.quickcraftType == 2 || itemstack.getCount() > this.quickcraftSlots.size()) && this.canDragTo(slot)) {
@@ -417,7 +468,7 @@
}
} else if (this.quickcraftStatus == 2) {
if (!this.quickcraftSlots.isEmpty()) {
@@ -100,7 +107,7 @@
k = ((Slot) this.quickcraftSlots.iterator().next()).index;
this.resetQuickCraft();
this.doClick(k, this.quickcraftType, ClickType.PICKUP, player);
@@ -433,6 +483,7 @@
@@ -433,6 +484,7 @@
l = this.getCarried().getCount();
Iterator iterator = this.quickcraftSlots.iterator();
@@ -108,7 +115,7 @@
while (iterator.hasNext()) {
Slot slot1 = (Slot) iterator.next();
ItemStack itemstack2 = this.getCarried();
@@ -443,12 +494,48 @@
@@ -443,12 +495,48 @@
int l1 = Math.min(AbstractContainerMenu.getQuickCraftPlaceCount(this.quickcraftSlots, this.quickcraftType, itemstack1) + j1, k1);
l -= l1 - j1;
@@ -160,7 +167,7 @@
}
this.resetQuickCraft();
@@ -466,8 +553,11 @@
@@ -466,8 +554,11 @@
if (slotIndex == -999) {
if (!this.getCarried().isEmpty()) {
if (clickaction == ClickAction.PRIMARY) {
@@ -173,7 +180,7 @@
} else {
player.drop(this.getCarried().split(1), true);
}
@@ -530,6 +620,15 @@
@@ -530,11 +621,21 @@
}
slot.setChanged();
@@ -189,7 +196,13 @@
}
} else {
int j2;
@@ -662,8 +761,9 @@
if (actionType == ClickType.SWAP && (button >= 0 && button < 9 || button == 40)) {
+ if (slotIndex < 0) return; // Paper - Add slot sanity checks to container clicks
ItemStack itemstack4 = playerinventory.getItem(button);
slot = (Slot) this.slots.get(slotIndex);
@@ -662,8 +763,9 @@
ItemStack itemstack = this.getCarried();
if (!itemstack.isEmpty()) {
@@ -200,7 +213,7 @@
}
}
@@ -893,6 +993,11 @@
@@ -893,6 +995,11 @@
}
public ItemStack getCarried() {