From edbdefb7bdea8934d8f726cd2493c4311a60a9ca Mon Sep 17 00:00:00 2001 From: xGinko Date: Tue, 10 Sep 2024 23:08:49 +0200 Subject: [PATCH] add 1.20.6-1.21 bookdupe prevention --- .../dupepreventions/BookTitleDupe.java | 41 +++++++++++++++++++ .../dupepreventions/BookTitleDupe.java | 41 +++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100755 AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/dupepreventions/BookTitleDupe.java create mode 100755 AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/dupepreventions/BookTitleDupe.java diff --git a/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/dupepreventions/BookTitleDupe.java b/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/dupepreventions/BookTitleDupe.java new file mode 100755 index 00000000..8dfbc52a --- /dev/null +++ b/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/dupepreventions/BookTitleDupe.java @@ -0,0 +1,41 @@ +package me.xginko.aef.modules.dupepreventions; + +import com.github.retrooper.packetevents.event.PacketListenerPriority; +import com.github.retrooper.packetevents.event.PacketReceiveEvent; +import com.github.retrooper.packetevents.protocol.packettype.PacketType; +import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientEditBook; +import me.xginko.aef.modules.packets.PacketModule; +import me.xginko.aef.utils.PlatformUtil; + +public class BookTitleDupe extends PacketModule { + + private final int maxTitleChars; + + public BookTitleDupe() { + super("dupe-preventions.book-title-dupe", PacketListenerPriority.HIGHEST); + config.addComment(configPath + ".enable", """ + Relevant for 1.20.6 - 1.21: + Will prevent players from sending book packets with a too large title, + to get disconnected and their inventories restored."""); + this.maxTitleChars = config.getInt(configPath + ".max-title-charlength", 20, """ + Normal ascii like charlimit in vanilla is 15, you could need a bit more + if you want to support languages with special characters."""); + } + + @Override + public boolean shouldEnable() { + return config.getBoolean(configPath + ".enable", PlatformUtil.getMinecraftPatchVersion() > 19); + } + + @Override + public void onPacketReceive(PacketReceiveEvent event) { + if (event.getPacketType() != PacketType.Play.Client.EDIT_BOOK) return; + + WrapperPlayClientEditBook packet = new WrapperPlayClientEditBook(event); + if (packet.getTitle() == null) return; + + if (packet.getTitle().length() > maxTitleChars) { + event.setCancelled(true); + } + } +} diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/dupepreventions/BookTitleDupe.java b/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/dupepreventions/BookTitleDupe.java new file mode 100755 index 00000000..2bfd90ac --- /dev/null +++ b/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/dupepreventions/BookTitleDupe.java @@ -0,0 +1,41 @@ +package me.xginko.aef.modules.dupepreventions; + +import com.github.retrooper.packetevents.event.PacketListenerPriority; +import com.github.retrooper.packetevents.event.PacketReceiveEvent; +import com.github.retrooper.packetevents.protocol.packettype.PacketType; +import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientEditBook; +import me.xginko.aef.modules.packets.PacketModule; +import me.xginko.aef.utils.PlatformUtil; + +public class BookTitleDupe extends PacketModule { + + private final int maxTitleChars; + + public BookTitleDupe() { + super("dupe-preventions.book-title-dupe", PacketListenerPriority.HIGHEST); + config.addComment(configPath + ".enable", + "Relevant for 1.20.6 - 1.21:\n" + + "Will prevent players from sending book packets with a too large title,\n" + + "to get disconnected and their inventories restored."); + this.maxTitleChars = config.getInt(configPath + ".max-title-charlength", 20, + "Normal ascii like charlimit in vanilla is 15, you could need a bit more\n" + + "if you want to support languages with special characters."); + } + + @Override + public boolean shouldEnable() { + return config.getBoolean(configPath + ".enable", PlatformUtil.getMinecraftPatchVersion() > 19); + } + + @Override + public void onPacketReceive(PacketReceiveEvent event) { + if (event.getPacketType() != PacketType.Play.Client.EDIT_BOOK) return; + + WrapperPlayClientEditBook packet = new WrapperPlayClientEditBook(event); + if (packet.getTitle() == null) return; + + if (packet.getTitle().length() > maxTitleChars) { + event.setCancelled(true); + } + } +}