Scissors/patches/server/0029-Prevent-invalid-container-events.patch
Luna 65d7993679
Backport 1.20.1 patches to 1.19.4 (#116)
* First pass

* Second and final pass

* Update Jenkinsfile
2023-07-04 16:10:53 -05:00

38 lines
1.9 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Allink <arclicious@vivaldi.net>
Date: Sun, 10 Jul 2022 02:55:01 +0100
Subject: [PATCH] Prevent invalid container events
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index e46febba49530c4c71a15bfc75d731c45fcb48f2..798ffda66ccbc98a073b276208e04d643b04e1b2 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -30,6 +30,7 @@ import java.util.function.UnaryOperator;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.Nullable;
+import net.kyori.adventure.text.format.NamedTextColor; // Scissors
import net.minecraft.ChatFormatting;
import net.minecraft.CrashReport;
import net.minecraft.CrashReportCategory;
@@ -2996,6 +2997,18 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
return;
}
+ // Scissors start - Do not call events when the slot/button number is invalid
+ final int sentSlotNum = packet.getSlotNum();
+ if((Mth.clamp(sentSlotNum, -1, this.player.containerMenu.slots.size() - 1) != sentSlotNum) && sentSlotNum != -999)
+ {
+ this.getCraftPlayer().kick(
+ net.kyori.adventure.text.Component.text("Invalid container click slot (Hacking?)")
+ .color(NamedTextColor.RED)
+ );
+ return;
+ }
+ // Scissors end
+
InventoryView inventory = this.player.containerMenu.getBukkitView();
SlotType type = inventory.getSlotType(packet.getSlotNum());