diff --git a/patches/api/Timings-v2.patch b/patches/api/Timings-v2.patch index a6d09b21ed..e0e6abea59 100644 --- a/patches/api/Timings-v2.patch +++ b/patches/api/Timings-v2.patch @@ -1426,23 +1426,17 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + + 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/Bundle-spark.patch b/patches/server/Bundle-spark.patch new file mode 100644 index 0000000000..706d8d7236 --- /dev/null +++ b/patches/server/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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/build.gradle.kts ++++ b/build.gradle.kts +@@ -0,0 +0,0 @@ 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..0000000000000000000000000000000000000000 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/SparksFly.java +@@ -0,0 +0,0 @@ ++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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 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 +@@ -0,0 +0,0 @@ + 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; +@@ -0,0 +0,0 @@ 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; + +@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/server/MinecraftServer.java ++++ b/src/main/java/net/minecraft/server/MinecraftServer.java +@@ -0,0 +0,0 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop