-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
187 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: Riley Park <rileysebastianpark@gmail.com> | ||
Date: Tue, 16 Jul 2024 14:55:23 -0700 | ||
Subject: [PATCH] spark | ||
|
||
|
||
diff --git a/build.gradle.kts b/build.gradle.kts | ||
index 1a734293c9416f13324bb0edf8f950c9029f8bc4..e505a521e6ff58fcd566ae23f714a7a1da17a1a9 100644 | ||
--- a/build.gradle.kts | ||
+++ b/build.gradle.kts | ||
@@ -61,6 +61,11 @@ 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-common:1.10-SNAPSHOT") | ||
+ implementation("me.lucko:spark-paper:1.10-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..c57341ca5feeb1e1ebd9ce525affdf16e57b7ee9 | ||
--- /dev/null | ||
+++ b/src/main/java/io/papermc/paper/SparksFly.java | ||
@@ -0,0 +1,91 @@ | ||
+package io.papermc.paper; | ||
+ | ||
+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.PaperClassLookup; | ||
+import me.lucko.spark.paper.PaperScheduler; | ||
+import me.lucko.spark.paper.PaperSparkPlugin; | ||
+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 String PROPERTY_NAME = "paper.startSparkBackgroundProfilerImmediately"; | ||
+ private final PaperSparkPlugin spark; | ||
+ private boolean backgroundProfilerEnabled; | ||
+ | ||
+ public SparksFly(final Server server) { | ||
+ final Logger logger = Logger.getLogger(ID); | ||
+ logger.log(Level.INFO, "This server bundles the spark profiler."); | ||
+ this.spark = new PaperSparkPlugin(server, logger, new PaperScheduler() { | ||
+ @Override | ||
+ public void executeAsync(final Runnable runnable) { | ||
+ MCUtil.scheduleAsyncTask(runnable); | ||
+ } | ||
+ | ||
+ @Override | ||
+ public void executeSync(final Runnable runnable) { | ||
+ MCUtil.scheduleTask(0, runnable); | ||
+ } | ||
+ }, new PaperClassLookup() { | ||
+ @Override | ||
+ public Class<?> lookup(final String className) throws Exception { | ||
+ return Class.forName(className); | ||
+ } | ||
+ }); | ||
+ if (Boolean.getBoolean(PROPERTY_NAME)) { | ||
+ this.enableBackgroundProfiler(); | ||
+ } | ||
+ } | ||
+ | ||
+ boolean onCommand(final CommandSender sender, final String[] args) { | ||
+ return this.spark.onCommand(sender, args); | ||
+ } | ||
+ | ||
+ List<String> onTabComplete(final CommandSender sender, final String[] args) { | ||
+ return this.spark.onTabComplete(sender, args); | ||
+ } | ||
+ | ||
+ public void enableBackgroundProfiler() { | ||
+ if (!this.backgroundProfilerEnabled) { | ||
+ final String jvmName = System.getProperty("java.vm.name"); | ||
+ if (jvmName.contains("OpenJ9")) { | ||
+ this.spark.log(Level.WARNING, String.format("The background profiler is incompatible with %s and could not be enabled.", jvmName)); | ||
+ return; | ||
+ } | ||
+ this.spark.initBackgroundProfiler(); | ||
+ this.backgroundProfilerEnabled = true; | ||
+ } | ||
+ } | ||
+ | ||
+ public void tickStart() { | ||
+ this.spark.onServerTickStart(); | ||
+ } | ||
+ | ||
+ public void tickEnd(final double duration) { | ||
+ this.spark.onServerTickEnd(duration); | ||
+ } | ||
+ | ||
+ public static final class CommandImpl extends Command { | ||
+ public CommandImpl(final String name) { | ||
+ super(name); | ||
+ this.setPermission("spark"); | ||
+ } | ||
+ | ||
+ @Override | ||
+ public boolean execute(final CommandSender sender, final String commandLabel, final String[] args) { | ||
+ return ((CraftServer) sender.getServer()).spark.onCommand(sender, args); | ||
+ } | ||
+ | ||
+ @Override | ||
+ public List<String> tabComplete(final CommandSender sender, final String alias, final String[] args) throws IllegalArgumentException { | ||
+ return ((CraftServer) sender.getServer()).spark.onTabComplete(sender, args); | ||
+ } | ||
+ } | ||
+} | ||
diff --git a/src/main/java/io/papermc/paper/command/PaperCommands.java b/src/main/java/io/papermc/paper/command/PaperCommands.java | ||
index 7b58b2d6297800c2dcdbf7539e5ab8e7703f39f1..4b7d7f77e1d4b882180f4f1abfd7590a11869905 100644 | ||
--- a/src/main/java/io/papermc/paper/command/PaperCommands.java | ||
+++ b/src/main/java/io/papermc/paper/command/PaperCommands.java | ||
@@ -1,5 +1,6 @@ | ||
package io.papermc.paper.command; | ||
|
||
+import io.papermc.paper.SparksFly; | ||
import net.minecraft.server.MinecraftServer; | ||
import org.bukkit.command.Command; | ||
|
||
@@ -19,6 +20,7 @@ public final class PaperCommands { | ||
COMMANDS.put("paper", new PaperCommand("paper")); | ||
COMMANDS.put("callback", new CallbackCommand("callback")); | ||
COMMANDS.put("mspt", new MSPTCommand("mspt")); | ||
+ COMMANDS.put(SparksFly.COMMAND_NAME, new SparksFly.CommandImpl(SparksFly.COMMAND_NAME)); | ||
} | ||
|
||
public static void registerCommands(final MinecraftServer server) { | ||
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java | ||
index aeae4f8d4ead24db315631c3d2c0b930d0d51e02..adc789f7241b347ca239601f04f9494c33563e94 100644 | ||
--- a/src/main/java/net/minecraft/server/MinecraftServer.java | ||
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java | ||
@@ -1228,6 +1228,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa | ||
LOGGER.info("Done ({})! For help, type \"help\"", doneTime); | ||
// Paper end | ||
|
||
+ this.server.spark.enableBackgroundProfiler(); // Paper - spark | ||
+ | ||
org.spigotmc.WatchdogThread.tick(); // Paper | ||
org.spigotmc.WatchdogThread.hasStarted = true; // Paper | ||
Arrays.fill( this.recentTps, 20 ); | ||
@@ -1586,6 +1588,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa | ||
}); | ||
isOversleep = false;MinecraftTimings.serverOversleep.stopTiming(); | ||
// Paper end | ||
+ this.server.spark.tickStart(); // Paper - spark | ||
new com.destroystokyo.paper.event.server.ServerTickStartEvent(this.tickCount+1).callEvent(); // Paper - Server Tick Events | ||
|
||
++this.tickCount; | ||
@@ -1629,6 +1632,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa | ||
long endTime = System.nanoTime(); | ||
long remaining = (TICK_TIME - (endTime - lastTick)) - catchupTime; | ||
new com.destroystokyo.paper.event.server.ServerTickEndEvent(this.tickCount, ((double)(endTime - lastTick) / 1000000D), remaining).callEvent(); | ||
+ this.server.spark.tickEnd(((double)(endTime - lastTick) / 1000000D)); // Paper - spark | ||
// Paper end - Server Tick Events | ||
this.profiler.push("tallying"); | ||
long j = Util.getNanos() - i; | ||
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java | ||
index caf6ff33b42472d30f28629470e12889f50490cc..8fe5c120fc54651badc46ec02f15679b47933097 100644 | ||
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java | ||
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java | ||
@@ -309,6 +309,7 @@ public final class CraftServer implements Server { | ||
public static Exception excessiveVelEx; // Paper - Velocity warnings | ||
private final io.papermc.paper.logging.SysoutCatcher sysoutCatcher = new io.papermc.paper.logging.SysoutCatcher(); // Paper | ||
private final io.papermc.paper.potion.PaperPotionBrewer potionBrewer; // Paper - Custom Potion Mixes | ||
+ public final io.papermc.paper.SparksFly spark; // Paper - spark | ||
|
||
// Paper start - Folia region threading API | ||
private final io.papermc.paper.threadedregions.scheduler.FallbackRegionScheduler regionizedScheduler = new io.papermc.paper.threadedregions.scheduler.FallbackRegionScheduler(); | ||
@@ -474,6 +475,7 @@ public final class CraftServer implements Server { | ||
} | ||
this.potionBrewer = new io.papermc.paper.potion.PaperPotionBrewer(console); // Paper - custom potion mixes | ||
datapackManager = new io.papermc.paper.datapack.PaperDatapackManager(console.getPackRepository()); // Paper | ||
+ this.spark = new io.papermc.paper.SparksFly(this); // Paper - spark | ||
} | ||
|
||
public boolean getCommandBlockOverride(String command) { |