From 9466e0d55a2d670d2d9bae7beacc0b4922301924 Mon Sep 17 00:00:00 2001
From: leguan <59799222+Leguan16@users.noreply.github.com>
Date: Thu, 14 Sep 2023 13:11:19 +0200
Subject: [PATCH] compression level change with config option (#9711)

---
 patches/server/Paper-config-files.patch                    | 7 ++++++-
 .../Use-Velocity-compression-and-cipher-natives.patch      | 2 +-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/patches/server/Paper-config-files.patch b/patches/server/Paper-config-files.patch
index fc61cd0d03..3b7126b2c0 100644
--- a/patches/server/Paper-config-files.patch
+++ b/patches/server/Paper-config-files.patch
@@ -449,6 +449,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +import co.aikar.timings.MinecraftTimings;
 +import io.papermc.paper.configuration.constraint.Constraint;
 +import io.papermc.paper.configuration.constraint.Constraints;
++import io.papermc.paper.configuration.type.IntOr;
 +import net.kyori.adventure.text.Component;
 +import net.kyori.adventure.text.format.NamedTextColor;
 +import net.minecraft.network.protocol.Packet;
@@ -725,6 +726,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +        public boolean useAlternativeLuckFormula = false;
 +        public boolean useDimensionTypeForCustomSpawners = false;
 +        public boolean strictAdvancementDimensionCheck = false;
++        public IntOr.Default compressionLevel = IntOr.Default.USE_DEFAULT;
 +    }
 +
 +    public BlockUpdates blockUpdates;
@@ -1129,7 +1131,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +    private static ConfigurationOptions defaultGlobalOptions(ConfigurationOptions options) {
 +        return options
 +            .header(GLOBAL_HEADER)
-+            .serializers(builder -> builder.register(new PacketClassSerializer()));
++            .serializers(builder -> builder
++                .register(new PacketClassSerializer())
++                .register(IntOr.Default.SERIALIZER)
++            );
 +    }
 +
 +    @Override
diff --git a/patches/server/Use-Velocity-compression-and-cipher-natives.patch b/patches/server/Use-Velocity-compression-and-cipher-natives.patch
index 833ee71203..0dc605c80f 100644
--- a/patches/server/Use-Velocity-compression-and-cipher-natives.patch
+++ b/patches/server/Use-Velocity-compression-and-cipher-natives.patch
@@ -308,7 +308,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
  
      public void setupCompression(int compressionThreshold, boolean rejectsBadPackets) {
          if (compressionThreshold >= 0) {
-+            com.velocitypowered.natives.compression.VelocityCompressor compressor = com.velocitypowered.natives.util.Natives.compress.get().create(-1); // Paper
++            com.velocitypowered.natives.compression.VelocityCompressor compressor = com.velocitypowered.natives.util.Natives.compress.get().create(io.papermc.paper.configuration.GlobalConfiguration.get().misc.compressionLevel.or(-1)); // Paper
              if (this.channel.pipeline().get("decompress") instanceof CompressionDecoder) {
                  ((CompressionDecoder) this.channel.pipeline().get("decompress")).setThreshold(compressionThreshold, rejectsBadPackets);
              } else {