From 681c01336bb20952f9cb278c27423cfc7360bba2 Mon Sep 17 00:00:00 2001 From: Riley Park Date: Sat, 20 Jul 2024 09:35:39 -0700 Subject: [PATCH] Bundle spark (#11093) --- patches/api/0011-Timings-v2.patch | 18 +- patches/server/0005-Paper-config-files.patch | 12 +- .../0745-Configurable-chat-thread-limit.patch | 4 +- .../0988-Moonrise-optimisation-patches.patch | 6 +- patches/server/1043-Bundle-spark.patch | 347 ++++++++++++++++++ 5 files changed, 368 insertions(+), 19 deletions(-) create mode 100644 patches/server/1043-Bundle-spark.patch diff --git a/patches/api/0011-Timings-v2.patch b/patches/api/0011-Timings-v2.patch index a7c06e2704..88d4b7afed 100644 --- a/patches/api/0011-Timings-v2.patch +++ b/patches/api/0011-Timings-v2.patch @@ -1261,10 +1261,10 @@ index 0000000000000000000000000000000000000000..df142a89b8c43acb81eb383eac0ef048 +} diff --git a/src/main/java/co/aikar/timings/Timings.java b/src/main/java/co/aikar/timings/Timings.java new file mode 100644 -index 0000000000000000000000000000000000000000..9812d668ad945aba486fbf6d5bf83c4292cb5d03 +index 0000000000000000000000000000000000000000..445b5d3b61f31cf263475d0155a7b0252c54a3f8 --- /dev/null +++ b/src/main/java/co/aikar/timings/Timings.java -@@ -0,0 +1,337 @@ +@@ -0,0 +1,331 @@ +/* + * This file is licensed under the MIT License (MIT). + * @@ -1426,23 +1426,17 @@ index 0000000000000000000000000000000000000000..9812d668ad945aba486fbf6d5bf83c42 + + public static Component deprecationMessage() { + return Component.text() -+ .color(TextColor.color(0xf3ef91)) ++ .color(TextColor.color(0xffc93a)) + .append(Component.text("[!] The timings profiler has been enabled but has been scheduled for removal from Paper in the future.")) + .append(Component.newline()) -+ .append( -+ Component.text(" We recommend installing the spark profiler as a replacement: ") -+ .append( -+ Component.text() -+ .content("https://spark.lucko.me/") -+ .clickEvent(ClickEvent.openUrl("https://spark.lucko.me/"))) -+ ) ++ .append(Component.text(" We recommend migrating to the spark profiler.")) + .append(Component.newline()) + .append( + Component.text(" For more information please visit: ") + .append( + Component.text() -+ .content("https://github.com/PaperMC/Paper/issues/8948") -+ .clickEvent(ClickEvent.openUrl("https://github.com/PaperMC/Paper/issues/8948"))) ++ .content("https://github.com/PaperMC/Paper/discussions/10565") ++ .clickEvent(ClickEvent.openUrl("https://github.com/PaperMC/Paper/discussions/10565"))) + ) + .build(); + } diff --git a/patches/server/0005-Paper-config-files.patch b/patches/server/0005-Paper-config-files.patch index 431e2eccc6..3b0eecc80f 100644 --- a/patches/server/0005-Paper-config-files.patch +++ b/patches/server/0005-Paper-config-files.patch @@ -487,10 +487,10 @@ index 0000000000000000000000000000000000000000..d9502ba028a96f9cc846f9ed428bd806 +} diff --git a/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java b/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java new file mode 100644 -index 0000000000000000000000000000000000000000..a4f91ef8d5c4a8263961c4f00c0ce8cc937497d9 +index 0000000000000000000000000000000000000000..9bf81a47b03769a46c995019c3d8016cd161c15d --- /dev/null +++ b/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java -@@ -0,0 +1,313 @@ +@@ -0,0 +1,321 @@ +package io.papermc.paper.configuration; + +import co.aikar.timings.MinecraftTimings; @@ -544,6 +544,14 @@ index 0000000000000000000000000000000000000000..a4f91ef8d5c4a8263961c4f00c0ce8cc + public boolean useDisplayNameInQuitMessage = false; + } + ++ public Spark spark; ++ ++ public class Spark extends ConfigurationPart { ++ public boolean enabled = true; ++ public boolean enableImmediately = false; ++ public boolean preferSparkPlugin = false; ++ } ++ + @Deprecated(forRemoval = true) + public Timings timings; + diff --git a/patches/server/0745-Configurable-chat-thread-limit.patch b/patches/server/0745-Configurable-chat-thread-limit.patch index 764335837b..0575f5cb26 100644 --- a/patches/server/0745-Configurable-chat-thread-limit.patch +++ b/patches/server/0745-Configurable-chat-thread-limit.patch @@ -22,10 +22,10 @@ is actually processed, this is honestly really just exposed for the misnomers or who just wanna ensure that this won't grow over a specific size if chat gets stupidly active diff --git a/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java b/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java -index a4f91ef8d5c4a8263961c4f00c0ce8cc937497d9..701196635f9c08d62d785fa1b448313937259c76 100644 +index 9bf81a47b03769a46c995019c3d8016cd161c15d..0ab240d1b1d872dffb78f424b388b2b802326832 100644 --- a/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java +++ b/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java -@@ -287,7 +287,18 @@ public class GlobalConfiguration extends ConfigurationPart { +@@ -295,7 +295,18 @@ public class GlobalConfiguration extends ConfigurationPart { @PostProcess private void postProcess() { diff --git a/patches/server/0988-Moonrise-optimisation-patches.patch b/patches/server/0988-Moonrise-optimisation-patches.patch index 9412139853..f60451dec1 100644 --- a/patches/server/0988-Moonrise-optimisation-patches.patch +++ b/patches/server/0988-Moonrise-optimisation-patches.patch @@ -22226,7 +22226,7 @@ index 0000000000000000000000000000000000000000..85950a1aa732ab8c01ad28bec9e0de14 + } +} diff --git a/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java b/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java -index 5160dc617cc5037cd3f10479454159f2a9984169..379452394679c466a09441d4c12882d0d00d9ef3 100644 +index ae6089f34e2420c0d745165ea0f754f4a9f1880f..c01fda50d9faba2ec373ac14b4a5992f516fac3a 100644 --- a/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java +++ b/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java @@ -29,6 +29,45 @@ public class GlobalConfiguration extends ConfigurationPart { @@ -22275,7 +22275,7 @@ index 5160dc617cc5037cd3f10479454159f2a9984169..379452394679c466a09441d4c12882d0 static void set(GlobalConfiguration instance) { GlobalConfiguration.instance = instance; } -@@ -130,21 +169,6 @@ public class GlobalConfiguration extends ConfigurationPart { +@@ -138,21 +177,6 @@ public class GlobalConfiguration extends ConfigurationPart { public int incomingPacketThreshold = 300; } @@ -22297,7 +22297,7 @@ index 5160dc617cc5037cd3f10479454159f2a9984169..379452394679c466a09441d4c12882d0 public UnsupportedSettings unsupportedSettings; public class UnsupportedSettings extends ConfigurationPart { -@@ -203,7 +227,7 @@ public class GlobalConfiguration extends ConfigurationPart { +@@ -211,7 +235,7 @@ public class GlobalConfiguration extends ConfigurationPart { @PostProcess private void postProcess() { diff --git a/patches/server/1043-Bundle-spark.patch b/patches/server/1043-Bundle-spark.patch new file mode 100644 index 0000000000..da1f230e8d --- /dev/null +++ b/patches/server/1043-Bundle-spark.patch @@ -0,0 +1,347 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Riley Park +Date: Tue, 16 Jul 2024 14:55:23 -0700 +Subject: [PATCH] Bundle spark + + +diff --git a/build.gradle.kts b/build.gradle.kts +index 1a734293c9416f13324bb0edf8f950c9029f8bc4..568d0b65bb5010e0ab365cb47b624720807a1f63 100644 +--- a/build.gradle.kts ++++ b/build.gradle.kts +@@ -61,6 +61,10 @@ dependencies { + implementation("io.papermc:reflection-rewriter-runtime:$reflectionRewriterVersion") + implementation("io.papermc:reflection-rewriter-proxy-generator:$reflectionRewriterVersion") + // Paper end - Remap reflection ++ // Paper start - spark ++ implementation("me.lucko:spark-api:0.1-SNAPSHOT") ++ implementation("me.lucko:spark-paper:1.10.83-SNAPSHOT") ++ // Paper end - spark + } + + paperweight { +diff --git a/src/main/java/io/papermc/paper/SparksFly.java b/src/main/java/io/papermc/paper/SparksFly.java +new file mode 100644 +index 0000000000000000000000000000000000000000..e4cb01a1a50311eae503b568f6e3e599d48302c8 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/SparksFly.java +@@ -0,0 +1,177 @@ ++package io.papermc.paper; ++ ++import io.papermc.paper.configuration.GlobalConfiguration; ++import io.papermc.paper.util.MCUtil; ++import java.util.List; ++import java.util.logging.Level; ++import java.util.logging.Logger; ++import me.lucko.spark.paper.api.Compatibility; ++import me.lucko.spark.paper.api.PaperClassLookup; ++import me.lucko.spark.paper.api.PaperScheduler; ++import me.lucko.spark.paper.api.PaperSparkModule; ++import net.kyori.adventure.text.Component; ++import net.kyori.adventure.text.format.TextColor; ++import org.bukkit.Server; ++import org.bukkit.command.Command; ++import org.bukkit.command.CommandSender; ++import org.bukkit.craftbukkit.CraftServer; ++ ++// It's like electricity. ++public final class SparksFly { ++ public static final String ID = "spark"; ++ public static final String COMMAND_NAME = "spark"; ++ ++ private static final int SPARK_YELLOW = 0xffc93a; ++ ++ private final Logger logger; ++ private final PaperSparkModule spark; ++ ++ private boolean enabled; ++ private boolean disabledInConfigurationWarningLogged; ++ ++ public SparksFly(final Server server) { ++ this.logger = Logger.getLogger(ID); ++ this.logger.log(Level.INFO, "This server bundles the spark profiler. For more information please visit https://docs.papermc.io/paper/profiling"); ++ this.spark = PaperSparkModule.create(Compatibility.VERSION_1_0, server, this.logger, new PaperScheduler() { ++ @Override ++ public void executeAsync(final Runnable runnable) { ++ MCUtil.scheduleAsyncTask(this.catching(runnable, "asynchronous")); ++ } ++ ++ @Override ++ public void executeSync(final Runnable runnable) { ++ MCUtil.ensureMain(this.catching(runnable, "synchronous")); ++ } ++ ++ private Runnable catching(final Runnable runnable, final String type) { ++ return () -> { ++ try { ++ runnable.run(); ++ } catch (final Throwable t) { ++ SparksFly.this.logger.log(Level.SEVERE, "An exception was encountered while executing a " + type + " spark task", t); ++ } ++ }; ++ } ++ }, new PaperClassLookup() { ++ @Override ++ public Class lookup(final String className) throws Exception { ++ return Class.forName(className); ++ } ++ }); ++ } ++ ++ public void enableEarlyIfRequested() { ++ if (!isPluginPreferred() && shouldEnableImmediately()) { ++ this.enable(); ++ } ++ } ++ ++ public void enableBeforePlugins() { ++ if (!isPluginPreferred()) { ++ this.enable(); ++ } ++ } ++ ++ public void enableAfterPlugins(final Server server) { ++ final boolean isPluginPreferred = isPluginPreferred(); ++ final boolean isPluginEnabled = isPluginEnabled(server); ++ if (!isPluginPreferred || !isPluginEnabled) { ++ if (isPluginPreferred && !this.enabled) { ++ this.logger.log(Level.INFO, "The spark plugin has been preferred but was not loaded. The bundled spark profiler will enabled instead."); ++ } ++ this.enable(); ++ } ++ } ++ ++ private void enable() { ++ if (!this.enabled) { ++ if (GlobalConfiguration.get().spark.enabled) { ++ this.enabled = true; ++ this.spark.enable(); ++ } else { ++ if (!this.disabledInConfigurationWarningLogged) { ++ this.logger.log(Level.INFO, "The spark profiler will not be enabled because it is currently disabled in the configuration."); ++ this.disabledInConfigurationWarningLogged = true; ++ } ++ } ++ } ++ } ++ ++ public void disable() { ++ if (this.enabled) { ++ this.spark.disable(); ++ this.enabled = false; ++ } ++ } ++ ++ public void registerCommandBeforePlugins(final Server server) { ++ if (!isPluginPreferred()) { ++ this.registerCommand(server); ++ } ++ } ++ ++ public void registerCommandAfterPlugins(final Server server) { ++ if ((!isPluginPreferred() || !isPluginEnabled(server)) && server.getCommandMap().getCommand(COMMAND_NAME) == null) { ++ this.registerCommand(server); ++ } ++ } ++ ++ private void registerCommand(final Server server) { ++ server.getCommandMap().register(COMMAND_NAME, "paper", new CommandImpl(COMMAND_NAME)); ++ } ++ ++ public void tickStart() { ++ this.spark.onServerTickStart(); ++ } ++ ++ public void tickEnd(final double duration) { ++ this.spark.onServerTickEnd(duration); ++ } ++ ++ void executeCommand(final CommandSender sender, final String[] args) { ++ this.spark.executeCommand(sender, args); ++ } ++ ++ List tabComplete(final CommandSender sender, final String[] args) { ++ return this.spark.tabComplete(sender, args); ++ } ++ ++ public static boolean isPluginPreferred() { ++ return GlobalConfiguration.get().spark.preferSparkPlugin; ++ } ++ ++ private static boolean isPluginEnabled(final Server server) { ++ return server.getPluginManager().isPluginEnabled(ID); ++ } ++ ++ private static boolean shouldEnableImmediately() { ++ return GlobalConfiguration.get().spark.enableImmediately; ++ } ++ ++ public static final class CommandImpl extends Command { ++ CommandImpl(final String name) { ++ super(name); ++ this.setPermission("spark"); ++ } ++ ++ @Override ++ public boolean execute(final CommandSender sender, final String commandLabel, final String[] args) { ++ final SparksFly spark = ((CraftServer) sender.getServer()).spark; ++ if (spark.enabled) { ++ spark.executeCommand(sender, args); ++ } else { ++ sender.sendMessage(Component.text("The spark profiler is currently disabled.", TextColor.color(SPARK_YELLOW))); ++ } ++ return true; ++ } ++ ++ @Override ++ public List tabComplete(final CommandSender sender, final String alias, final String[] args) throws IllegalArgumentException { ++ final SparksFly spark = ((CraftServer) sender.getServer()).spark; ++ if (spark.enabled) { ++ return spark.tabComplete(sender, args); ++ } ++ return List.of(); ++ } ++ } ++} +diff --git a/src/main/java/io/papermc/paper/plugin/provider/source/FileProviderSource.java b/src/main/java/io/papermc/paper/plugin/provider/source/FileProviderSource.java +index 6b8ed8a0baaf4a57d20e57cec3400af5561ddd79..48604e7f96adc9e226e034054c5e2bad0b024eb5 100644 +--- a/src/main/java/io/papermc/paper/plugin/provider/source/FileProviderSource.java ++++ b/src/main/java/io/papermc/paper/plugin/provider/source/FileProviderSource.java +@@ -1,6 +1,9 @@ + package io.papermc.paper.plugin.provider.source; + ++import com.mojang.logging.LogUtils; ++import io.papermc.paper.SparksFly; + import io.papermc.paper.plugin.PluginInitializerManager; ++import io.papermc.paper.plugin.configuration.PluginMeta; + import io.papermc.paper.plugin.entrypoint.EntrypointHandler; + import io.papermc.paper.plugin.provider.type.PluginFileType; + import org.bukkit.plugin.InvalidPluginException; +@@ -17,12 +20,14 @@ import java.nio.file.attribute.BasicFileAttributes; + import java.util.Set; + import java.util.function.Function; + import java.util.jar.JarFile; ++import org.slf4j.Logger; + + /** + * Loads a plugin provider at the given plugin jar file path. + */ + public class FileProviderSource implements ProviderSource { + ++ private static final Logger LOGGER = LogUtils.getClassLogger(); + private final Function contextChecker; + private final boolean applyRemap; + +@@ -82,6 +87,12 @@ public class FileProviderSource implements ProviderSource { + ); + } + ++ final PluginMeta config = type.getConfig(file); ++ if ((config.getName().equals("spark") && config.getMainClass().equals("me.lucko.spark.bukkit.BukkitSparkPlugin")) && !SparksFly.isPluginPreferred()) { ++ LOGGER.info("The spark plugin will not be loaded as this server bundles the spark profiler."); ++ return; ++ } ++ + type.register(entrypointHandler, file, context); + } + +diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java +index 8160c35368fc2c52d6f4a42df27adb2ef6eb87f3..9325d6f95165a7cee00d7de736af723681cc16b4 100644 +--- a/src/main/java/net/minecraft/server/MinecraftServer.java ++++ b/src/main/java/net/minecraft/server/MinecraftServer.java +@@ -751,6 +751,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop