From 54033bb593a7b68a38d47d5330bd02be48ec224b Mon Sep 17 00:00:00 2001 From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com> Date: Mon, 7 Jul 2025 04:23:37 +0300 Subject: [PATCH] optimize LinearPalette; remove useless log4shell patch --- .../0049-Block-Log4Shell-exploit.patch | 34 ---------- ...9-Option-to-disable-disconnect.spam.patch} | 6 +- ...ble-saving-of-snowball-and-firework.patch} | 0 ... => 0051-Snowball-and-Egg-knockback.patch} | 0 ....patch => 0052-Optimize-suffocation.patch} | 0 ...> 0053-Reduce-chunk-loading-lookups.patch} | 0 ...gurable-movement-speed-for-entities.patch} | 0 ...t-dirty-flag-when-loading-maps-from.patch} | 0 ...BlockEntity-ticking-isRemoved-check.patch} | 0 ...eird-movement-and-disable-teleporti.patch} | 2 +- ...-Raids.patch => 0058-Optimize-Raids.patch} | 0 ...SparklyPaper-Optimize-canSee-checks.patch} | 0 ...-Small-optimization-to-LinearPalette.patch | 63 +++++++++++++++++++ 13 files changed, 67 insertions(+), 38 deletions(-) delete mode 100644 divinemc-server/minecraft-patches/features/0049-Block-Log4Shell-exploit.patch rename divinemc-server/minecraft-patches/features/{0050-Option-to-disable-disconnect.spam.patch => 0049-Option-to-disable-disconnect.spam.patch} (95%) rename divinemc-server/minecraft-patches/features/{0051-Option-to-disable-saving-of-snowball-and-firework.patch => 0050-Option-to-disable-saving-of-snowball-and-firework.patch} (100%) rename divinemc-server/minecraft-patches/features/{0052-Snowball-and-Egg-knockback.patch => 0051-Snowball-and-Egg-knockback.patch} (100%) rename divinemc-server/minecraft-patches/features/{0053-Optimize-suffocation.patch => 0052-Optimize-suffocation.patch} (100%) rename divinemc-server/minecraft-patches/features/{0054-Reduce-chunk-loading-lookups.patch => 0053-Reduce-chunk-loading-lookups.patch} (100%) rename divinemc-server/minecraft-patches/features/{0055-Configurable-movement-speed-for-entities.patch => 0054-Configurable-movement-speed-for-entities.patch} (100%) rename divinemc-server/minecraft-patches/features/{0056-SparklyPaper-Reset-dirty-flag-when-loading-maps-from.patch => 0055-SparklyPaper-Reset-dirty-flag-when-loading-maps-from.patch} (100%) rename divinemc-server/minecraft-patches/features/{0057-Leaf-Improve-BlockEntity-ticking-isRemoved-check.patch => 0056-Leaf-Improve-BlockEntity-ticking-isRemoved-check.patch} (100%) rename divinemc-server/minecraft-patches/features/{0058-Option-to-allow-weird-movement-and-disable-teleporti.patch => 0057-Option-to-allow-weird-movement-and-disable-teleporti.patch} (98%) rename divinemc-server/minecraft-patches/features/{0059-Optimize-Raids.patch => 0058-Optimize-Raids.patch} (100%) rename divinemc-server/minecraft-patches/features/{0060-SparklyPaper-Optimize-canSee-checks.patch => 0059-SparklyPaper-Optimize-canSee-checks.patch} (100%) create mode 100644 divinemc-server/minecraft-patches/features/0060-Small-optimization-to-LinearPalette.patch diff --git a/divinemc-server/minecraft-patches/features/0049-Block-Log4Shell-exploit.patch b/divinemc-server/minecraft-patches/features/0049-Block-Log4Shell-exploit.patch deleted file mode 100644 index 439bf2c..0000000 --- a/divinemc-server/minecraft-patches/features/0049-Block-Log4Shell-exploit.patch +++ /dev/null @@ -1,34 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com> -Date: Sat, 1 Feb 2025 19:28:34 +0300 -Subject: [PATCH] Block Log4Shell exploit - - -diff --git a/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/net/minecraft/server/network/ServerGamePacketListenerImpl.java -index a8b2c19cc9803058b421b07c739166afdf291e47..3a27b544da8227511b546c55963e7112df0a9f63 100644 ---- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java -+++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java -@@ -2515,6 +2515,7 @@ public class ServerGamePacketListenerImpl - } - - private void tryHandleChat(String message, Runnable handler, boolean sync) { // CraftBukkit -+ if (ServerGamePacketListenerImpl.isLog4ShellExploit(message)) return; // DivineMC - Block Log4Shell exploit - if (isChatMessageIllegal(message)) { - this.disconnectAsync(Component.translatable("multiplayer.disconnect.illegal_characters"), org.bukkit.event.player.PlayerKickEvent.Cause.ILLEGAL_CHARACTERS); // Paper - add proper async disconnect - } else if (this.player.isRemoved() || this.player.getChatVisibility() == ChatVisiblity.HIDDEN) { // CraftBukkit - dead men tell no tales -@@ -2547,6 +2548,15 @@ public class ServerGamePacketListenerImpl - } - } - -+ // DivineMC start - Block Log4Shell exploit -+ public static boolean isLog4ShellExploit(String message) { -+ java.util.regex.Pattern pattern = java.util.regex.Pattern.compile(".*\\$\\{[^}]*}.*"); -+ java.util.regex.Matcher matcher = pattern.matcher(message); -+ -+ return matcher.find(); -+ } -+ // DivineMC end - Block Log4Shell exploit -+ - public static boolean isChatMessageIllegal(String message) { - for (int i = 0; i < message.length(); i++) { - if (!StringUtil.isAllowedChatCharacter(message.charAt(i))) { diff --git a/divinemc-server/minecraft-patches/features/0050-Option-to-disable-disconnect.spam.patch b/divinemc-server/minecraft-patches/features/0049-Option-to-disable-disconnect.spam.patch similarity index 95% rename from divinemc-server/minecraft-patches/features/0050-Option-to-disable-disconnect.spam.patch rename to divinemc-server/minecraft-patches/features/0049-Option-to-disable-disconnect.spam.patch index 1982ee1..b962f45 100644 --- a/divinemc-server/minecraft-patches/features/0050-Option-to-disable-disconnect.spam.patch +++ b/divinemc-server/minecraft-patches/features/0049-Option-to-disable-disconnect.spam.patch @@ -5,7 +5,7 @@ Subject: [PATCH] Option to disable disconnect.spam diff --git a/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/net/minecraft/server/network/ServerGamePacketListenerImpl.java -index 3a27b544da8227511b546c55963e7112df0a9f63..d5ed595bce6846590230634f8887e1f8e9b0a062 100644 +index a8b2c19cc9803058b421b07c739166afdf291e47..8f4bca6a99b35e869e34f0fa216c13189cd7b384 100644 --- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java +++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java @@ -844,7 +844,7 @@ public class ServerGamePacketListenerImpl @@ -34,7 +34,7 @@ index 3a27b544da8227511b546c55963e7112df0a9f63..d5ed595bce6846590230634f8887e1f8 && parseResults.getExceptions().values().stream().anyMatch(e -> e instanceof io.papermc.paper.brigadier.TagParseCommandSyntaxException)) { this.disconnect(Component.translatable("disconnect.spam"), org.bukkit.event.player.PlayerKickEvent.Cause.SPAM); return; -@@ -2639,6 +2640,7 @@ public class ServerGamePacketListenerImpl +@@ -2629,6 +2630,7 @@ public class ServerGamePacketListenerImpl // this.chatSpamThrottler.increment(); if (!this.chatSpamThrottler.isIncrementAndUnderThreshold() // CraftBukkit end @@ -42,7 +42,7 @@ index 3a27b544da8227511b546c55963e7112df0a9f63..d5ed595bce6846590230634f8887e1f8 && !this.server.getPlayerList().isOp(this.player.getGameProfile()) && !this.server.isSingleplayerOwner(this.player.getGameProfile())) { this.disconnectAsync(Component.translatable("disconnect.spam"), org.bukkit.event.player.PlayerKickEvent.Cause.SPAM); // Paper - kick event cause & add proper async disconnect -@@ -3396,7 +3398,7 @@ public class ServerGamePacketListenerImpl +@@ -3386,7 +3388,7 @@ public class ServerGamePacketListenerImpl public void handlePlaceRecipe(ServerboundPlaceRecipePacket packet) { // Paper start - auto recipe limit if (!org.bukkit.Bukkit.isPrimaryThread()) { diff --git a/divinemc-server/minecraft-patches/features/0051-Option-to-disable-saving-of-snowball-and-firework.patch b/divinemc-server/minecraft-patches/features/0050-Option-to-disable-saving-of-snowball-and-firework.patch similarity index 100% rename from divinemc-server/minecraft-patches/features/0051-Option-to-disable-saving-of-snowball-and-firework.patch rename to divinemc-server/minecraft-patches/features/0050-Option-to-disable-saving-of-snowball-and-firework.patch diff --git a/divinemc-server/minecraft-patches/features/0052-Snowball-and-Egg-knockback.patch b/divinemc-server/minecraft-patches/features/0051-Snowball-and-Egg-knockback.patch similarity index 100% rename from divinemc-server/minecraft-patches/features/0052-Snowball-and-Egg-knockback.patch rename to divinemc-server/minecraft-patches/features/0051-Snowball-and-Egg-knockback.patch diff --git a/divinemc-server/minecraft-patches/features/0053-Optimize-suffocation.patch b/divinemc-server/minecraft-patches/features/0052-Optimize-suffocation.patch similarity index 100% rename from divinemc-server/minecraft-patches/features/0053-Optimize-suffocation.patch rename to divinemc-server/minecraft-patches/features/0052-Optimize-suffocation.patch diff --git a/divinemc-server/minecraft-patches/features/0054-Reduce-chunk-loading-lookups.patch b/divinemc-server/minecraft-patches/features/0053-Reduce-chunk-loading-lookups.patch similarity index 100% rename from divinemc-server/minecraft-patches/features/0054-Reduce-chunk-loading-lookups.patch rename to divinemc-server/minecraft-patches/features/0053-Reduce-chunk-loading-lookups.patch diff --git a/divinemc-server/minecraft-patches/features/0055-Configurable-movement-speed-for-entities.patch b/divinemc-server/minecraft-patches/features/0054-Configurable-movement-speed-for-entities.patch similarity index 100% rename from divinemc-server/minecraft-patches/features/0055-Configurable-movement-speed-for-entities.patch rename to divinemc-server/minecraft-patches/features/0054-Configurable-movement-speed-for-entities.patch diff --git a/divinemc-server/minecraft-patches/features/0056-SparklyPaper-Reset-dirty-flag-when-loading-maps-from.patch b/divinemc-server/minecraft-patches/features/0055-SparklyPaper-Reset-dirty-flag-when-loading-maps-from.patch similarity index 100% rename from divinemc-server/minecraft-patches/features/0056-SparklyPaper-Reset-dirty-flag-when-loading-maps-from.patch rename to divinemc-server/minecraft-patches/features/0055-SparklyPaper-Reset-dirty-flag-when-loading-maps-from.patch diff --git a/divinemc-server/minecraft-patches/features/0057-Leaf-Improve-BlockEntity-ticking-isRemoved-check.patch b/divinemc-server/minecraft-patches/features/0056-Leaf-Improve-BlockEntity-ticking-isRemoved-check.patch similarity index 100% rename from divinemc-server/minecraft-patches/features/0057-Leaf-Improve-BlockEntity-ticking-isRemoved-check.patch rename to divinemc-server/minecraft-patches/features/0056-Leaf-Improve-BlockEntity-ticking-isRemoved-check.patch diff --git a/divinemc-server/minecraft-patches/features/0058-Option-to-allow-weird-movement-and-disable-teleporti.patch b/divinemc-server/minecraft-patches/features/0057-Option-to-allow-weird-movement-and-disable-teleporti.patch similarity index 98% rename from divinemc-server/minecraft-patches/features/0058-Option-to-allow-weird-movement-and-disable-teleporti.patch rename to divinemc-server/minecraft-patches/features/0057-Option-to-allow-weird-movement-and-disable-teleporti.patch index 3d91505..b73178f 100644 --- a/divinemc-server/minecraft-patches/features/0058-Option-to-allow-weird-movement-and-disable-teleporti.patch +++ b/divinemc-server/minecraft-patches/features/0057-Option-to-allow-weird-movement-and-disable-teleporti.patch @@ -6,7 +6,7 @@ Subject: [PATCH] Option to allow weird movement and disable teleporting diff --git a/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/net/minecraft/server/network/ServerGamePacketListenerImpl.java -index d5ed595bce6846590230634f8887e1f8e9b0a062..798482a332c4be045d5c409a20cd120c12b3460e 100644 +index 8f4bca6a99b35e869e34f0fa216c13189cd7b384..3ba558634558b4524245a2b29786237f5e38ef42 100644 --- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java +++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java @@ -607,7 +607,7 @@ public class ServerGamePacketListenerImpl diff --git a/divinemc-server/minecraft-patches/features/0059-Optimize-Raids.patch b/divinemc-server/minecraft-patches/features/0058-Optimize-Raids.patch similarity index 100% rename from divinemc-server/minecraft-patches/features/0059-Optimize-Raids.patch rename to divinemc-server/minecraft-patches/features/0058-Optimize-Raids.patch diff --git a/divinemc-server/minecraft-patches/features/0060-SparklyPaper-Optimize-canSee-checks.patch b/divinemc-server/minecraft-patches/features/0059-SparklyPaper-Optimize-canSee-checks.patch similarity index 100% rename from divinemc-server/minecraft-patches/features/0060-SparklyPaper-Optimize-canSee-checks.patch rename to divinemc-server/minecraft-patches/features/0059-SparklyPaper-Optimize-canSee-checks.patch diff --git a/divinemc-server/minecraft-patches/features/0060-Small-optimization-to-LinearPalette.patch b/divinemc-server/minecraft-patches/features/0060-Small-optimization-to-LinearPalette.patch new file mode 100644 index 0000000..b876143 --- /dev/null +++ b/divinemc-server/minecraft-patches/features/0060-Small-optimization-to-LinearPalette.patch @@ -0,0 +1,63 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com> +Date: Mon, 7 Jul 2025 04:21:38 +0300 +Subject: [PATCH] Small optimization to LinearPalette + + +diff --git a/net/minecraft/world/level/chunk/LinearPalette.java b/net/minecraft/world/level/chunk/LinearPalette.java +index 2073f6ff41aa570102621d183ee890b076267d54..93cb815032fada7b8abc7301a7005114eea8384d 100644 +--- a/net/minecraft/world/level/chunk/LinearPalette.java ++++ b/net/minecraft/world/level/chunk/LinearPalette.java +@@ -12,7 +12,7 @@ public class LinearPalette implements Palette, ca.spottedleaf.moonrise.pat + private final T[] values; + private final PaletteResize resizeHandler; + private final int bits; +- private int size; ++ private volatile int size; // DivineMC - Small optimization to LinearPalette + + // Paper start - optimise palette reads + @Override +@@ -49,11 +49,14 @@ public class LinearPalette implements Palette, ca.spottedleaf.moonrise.pat + + @Override + public int idFor(T state) { +- for (int i = 0; i < this.size; i++) { +- if (this.values[i] == state) { ++ // DivineMC start - Small optimization to LinearPalette ++ final T[] values = this.values; ++ for (int i = 0; i < values.length; i++) { ++ if (values[i] == state) { + return i; + } + } ++ // DivineMC end - Small optimization to LinearPalette + + int ix = this.size; + if (ix < this.values.length) { +@@ -67,17 +70,23 @@ public class LinearPalette implements Palette, ca.spottedleaf.moonrise.pat + + @Override + public boolean maybeHas(Predicate filter) { +- for (int i = 0; i < this.size; i++) { +- if (filter.test(this.values[i])) { ++ // DivineMC start - Small optimization to LinearPalette ++ final T[] values = this.values; ++ final int currentSize = this.size; ++ ++ for (int i = 0; i < currentSize; i++) { ++ T value = values[i]; ++ if (value != null && filter.test(value)) { + return true; + } + } ++ // DivineMC end - Small optimization to LinearPalette + + return false; + } + + @Override +- public T valueFor(int id) { ++ public synchronized T valueFor(int id) { // DivineMC - Small optimization to LinearPalette + if (id >= 0 && id < this.size) { + return this.values[id]; + } else {