Allow server administrators to disable book size checks (#10457)

This commit is contained in:
Anthony J. Halliday 2024-08-19 05:46:39 -04:00
parent 9921a197e7
commit 3ab4933ea3
2 changed files with 5 additions and 3 deletions

View file

@ -30,10 +30,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
@Override
public void handleEditBook(ServerboundEditBookPacket packet) {
+ // Paper start - Book size limits
+ if (!this.cserver.isPrimaryThread()) {
+ final io.papermc.paper.configuration.type.number.IntOr.Disabled pageMax = io.papermc.paper.configuration.GlobalConfiguration.get().itemValidation.bookSize.pageMax;
+ if (!this.cserver.isPrimaryThread() && pageMax.enabled()) {
+ final List<String> pageList = packet.pages();
+ long byteTotal = 0;
+ final int maxBookPageSize = io.papermc.paper.configuration.GlobalConfiguration.get().itemValidation.bookSize.pageMax;
+ final int maxBookPageSize = pageMax.intValue();
+ final double multiplier = Math.clamp(io.papermc.paper.configuration.GlobalConfiguration.get().itemValidation.bookSize.totalMultiplier, 0.3D, 1D);
+ long byteAllowed = maxBookPageSize;
+ for (final String page : pageList) {

View file

@ -513,6 +513,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.OptionalInt;
+
+@SuppressWarnings({"CanBeFinal", "FieldCanBeLocal", "FieldMayBeFinal", "NotNullFieldNotInitialized", "InnerClassMayBeStatic"})
+public class GlobalConfiguration extends ConfigurationPart {
@ -723,7 +724,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ public BookSize bookSize;
+
+ public class BookSize extends ConfigurationPart {
+ public int pageMax = 2560; // TODO this appears to be a duplicate setting with one above
+ public IntOr.Disabled pageMax = new IntOr.Disabled(OptionalInt.of(2560)); // TODO this appears to be a duplicate setting with one above
+ public double totalMultiplier = 0.98D; // TODO this should probably be merged into the above inner class
+ }
+ public boolean resolveSelectorsInBooks = false;