Skip to content

Commit 42a9e63

Browse files
Check containerId of incoming packets
The container id seems kind of useless (some container-related packets don't even include it), but it can't hurt to check it.
1 parent 722d55d commit 42a9e63

3 files changed

Lines changed: 7 additions & 10 deletions

File tree

invui/src/main/java/xyz/xenondevs/invui/internal/menu/CustomContainerMenu.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -444,10 +444,10 @@ public UpdateType processIncoming() {
444444
*/
445445
protected UpdateType processPacket(Packet<? super ServerGamePacketListener> packet) {
446446
return switch (packet) {
447-
case ServerboundContainerButtonClickPacket p -> handleButtonClick(p.buttonId());
448-
case ServerboundContainerClickPacket p -> handleClick(p);
447+
case ServerboundContainerButtonClickPacket p when p.containerId() == containerId -> handleButtonClick(p.buttonId());
448+
case ServerboundContainerClickPacket p when p.containerId() == containerId -> handleClick(p);
449449
case ServerboundSelectBundleItemPacket p -> handleBundleSelect(p);
450-
case ServerboundContainerClosePacket p -> {
450+
case ServerboundContainerClosePacket p when p.getContainerId() == containerId -> {
451451
handleClose(p);
452452
yield UpdateType.NONE;
453453
}
@@ -476,9 +476,6 @@ private void handlePong(ServerboundPongPacket packet) {
476476
* @param packet The packet that was received
477477
*/
478478
private void handleClose(ServerboundContainerClosePacket packet) {
479-
if (packet.getContainerId() != containerId)
480-
return;
481-
482479
if (getWindow().isCloseable()) {
483480
getWindowEvents().handleClose(InventoryCloseEvent.Reason.PLAYER);
484481
serverPlayer.containerMenu = serverPlayer.inventoryMenu;

invui/src/main/java/xyz/xenondevs/invui/internal/menu/CustomCrafterMenu.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ public void handleClosed() {
4646

4747
@Override
4848
protected UpdateType processPacket(Packet<? super ServerGamePacketListener> packet) {
49-
if (packet instanceof ServerboundContainerSlotStateChangedPacket slotStateChangedPacket) {
50-
handleSlotStateChange(slotStateChangedPacket);
49+
if (packet instanceof ServerboundContainerSlotStateChangedPacket p && p.containerId() == containerId) {
50+
handleSlotStateChange(p);
5151
return UpdateType.NONE;
5252
} else {
5353
return super.processPacket(packet);

invui/src/main/java/xyz/xenondevs/invui/internal/menu/CustomRecipeBookPoweredMenu.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ public void handleClosed() {
5252

5353
@Override
5454
protected UpdateType processPacket(Packet<? super ServerGamePacketListener> packet) {
55-
if (packet instanceof ServerboundPlaceRecipePacket) {
56-
handleRecipePlace((ServerboundPlaceRecipePacket) packet);
55+
if (packet instanceof ServerboundPlaceRecipePacket p && p.containerId() == containerId) {
56+
handleRecipePlace(p);
5757
return UpdateType.NONE;
5858
} else {
5959
return super.processPacket(packet);

0 commit comments

Comments
 (0)