From 9d0331e1904bb725a68d1a11ad5bfb0305e8d9e7 Mon Sep 17 00:00:00 2001 From: KennyTV <28825609+KennyTV@users.noreply.github.com> Date: Mon, 4 Mar 2019 10:14:52 +0100 Subject: [PATCH] Add option to truncate edited books with more than 50 pages --- .../bukkit/platform/BukkitViaConfig.java | 5 ++++ .../bungee/platform/BungeeViaConfig.java | 5 ++++ .../ViaVersion/api/ViaVersionConfig.java | 8 +++++++ .../packets/PlayerPackets.java | 23 ++++++++++++++++++- .../resources/assets/viaversion/config.yml | 2 ++ .../sponge/platform/SpongeViaConfig.java | 5 ++++ .../velocity/platform/VelocityViaConfig.java | 5 ++++ 7 files changed, 52 insertions(+), 1 deletion(-) diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaConfig.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaConfig.java index 8a66a7c41..2206c9faf 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaConfig.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaConfig.java @@ -249,4 +249,9 @@ public class BukkitViaConfig extends Config implements ViaVersionConfig { public int get1_13TabCompleteDelay() { return getInt("1_13-tab-complete-delay", 0); } + + @Override + public boolean truncate1_14Books() { + return getBoolean("truncate-1_14-books", false); + } } diff --git a/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaConfig.java b/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaConfig.java index e58044525..c52bb9452 100644 --- a/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaConfig.java +++ b/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaConfig.java @@ -302,4 +302,9 @@ public class BungeeViaConfig extends Config implements ViaVersionConfig { public int get1_13TabCompleteDelay() { return getInt("1_13-tab-complete-delay", 0); } + + @Override + public boolean truncate1_14Books() { + return getBoolean("truncate-1_14-books", false); + } } diff --git a/common/src/main/java/us/myles/ViaVersion/api/ViaVersionConfig.java b/common/src/main/java/us/myles/ViaVersion/api/ViaVersionConfig.java index 1cc3ad3e2..57c98be74 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/ViaVersionConfig.java +++ b/common/src/main/java/us/myles/ViaVersion/api/ViaVersionConfig.java @@ -305,7 +305,15 @@ public interface ViaVersionConfig { /** * When greater than 0, enables tab complete request delaying by x ticks + * * @return the delay in ticks */ int get1_13TabCompleteDelay(); + + /** + * When activated, edited books with more than 50 pages will be shortened to 50. + * + * @return True if enabled + */ + boolean truncate1_14Books(); } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/PlayerPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/PlayerPackets.java index f3113ffa1..9989457b7 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/PlayerPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/PlayerPackets.java @@ -1,7 +1,12 @@ package us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets; +import com.github.steveice10.opennbt.tag.builtin.CompoundTag; +import com.github.steveice10.opennbt.tag.builtin.ListTag; +import com.github.steveice10.opennbt.tag.builtin.Tag; import us.myles.ViaVersion.api.PacketWrapper; +import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.minecraft.Position; +import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; @@ -36,7 +41,23 @@ public class PlayerPackets { handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { - InventoryPackets.toServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); + final Item item = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM); + InventoryPackets.toServer(item); + + // Client limit when editing a book was upped from 50 to 100 in 1.14, but some anti-exploit plugins ban with a size higher than the old client limit + if (Via.getConfig().truncate1_14Books()) { + if (item == null) return; + CompoundTag tag = item.getTag(); + + if (tag == null) return; + Tag pages = tag.get("pages"); + + if (!(pages instanceof ListTag)) return; + + ListTag listTag = (ListTag) pages; + if (listTag.size() <= 50) return; + listTag.setValue(listTag.getValue().subList(0, 50)); + } } }); } diff --git a/common/src/main/resources/assets/viaversion/config.yml b/common/src/main/resources/assets/viaversion/config.yml index 62cb0dc6f..ff8e32f47 100644 --- a/common/src/main/resources/assets/viaversion/config.yml +++ b/common/src/main/resources/assets/viaversion/config.yml @@ -118,6 +118,8 @@ disable-1_13-auto-complete: false 1_13-tab-complete-delay: 0 # For 1.13 clients the smallest (1 layer) snow doesn't have collision, this will send these as 2 snowlayers for 1.13+ clients to prevent them bugging through them fix-low-snow-collision: false +# In 1.14 the client page limit has been upped to 100 (from 50). Some anti-exploit plugins ban when clients go higher than 50. This option cuts edited books to 50 pages. +truncate-1_14-books: false # # Enable serverside block-connections for 1.13+ clients serverside-blockconnections: false diff --git a/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaConfig.java b/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaConfig.java index 8944f60ec..f0b0f86d1 100644 --- a/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaConfig.java +++ b/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaConfig.java @@ -255,4 +255,9 @@ public class SpongeViaConfig extends Config implements ViaVersionConfig { public int get1_13TabCompleteDelay() { return getInt("1_13-tab-complete-delay", 0); } + + @Override + public boolean truncate1_14Books() { + return getBoolean("truncate-1_14-books", false); + } } diff --git a/velocity/src/main/java/us/myles/ViaVersion/velocity/platform/VelocityViaConfig.java b/velocity/src/main/java/us/myles/ViaVersion/velocity/platform/VelocityViaConfig.java index 1a5144fb9..da3c00ece 100644 --- a/velocity/src/main/java/us/myles/ViaVersion/velocity/platform/VelocityViaConfig.java +++ b/velocity/src/main/java/us/myles/ViaVersion/velocity/platform/VelocityViaConfig.java @@ -307,4 +307,9 @@ public class VelocityViaConfig extends Config implements ViaVersionConfig { public int get1_13TabCompleteDelay() { return getInt("1_13-tab-complete-delay", 0); } + + @Override + public boolean truncate1_14Books() { + return getBoolean("truncate-1_14-books", false); + } }