Scissors/patches/server/0033-Prevent-invalid-container-events.patch
2022-09-13 01:41:21 -05:00

47 lines
2.5 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 8ad540867e1f7942170f24faa4f42a84c0c63690..a7eb51e6b695cdb9dc20698b774da33ec4035544 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -29,6 +29,8 @@ 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;
import net.minecraft.ChatFormatting;
import net.minecraft.CrashReport;
import net.minecraft.CrashReportCategory;
@@ -3095,6 +3097,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
public void handleContainerClick(ServerboundContainerClickPacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.getLevel());
if (this.player.isImmobile()) return; // CraftBukkit
+
this.player.resetLastActionTime();
if (this.player.containerMenu.containerId == packet.getContainerId() && this.player.containerMenu.stillValid(this.player)) { // CraftBukkit
boolean cancelled = this.player.isSpectator(); // CraftBukkit - see below if
@@ -3116,6 +3119,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());