Bundle spark

This commit is contained in:
Riley Park
2024-07-16 14:55:23 -07:00
parent 29e03d0439
commit 855db272b1
6 changed files with 321 additions and 69 deletions

View File

@@ -308,7 +308,7 @@
if (profiledduration != null) {
profiledduration.finish(true);
}
@@ -387,23 +468,244 @@
@@ -387,23 +468,246 @@
protected void forceDifficulty() {}
@@ -547,6 +547,8 @@
+ // Paper end - Configurable player collision
+
+ this.server.enablePlugins(org.bukkit.plugin.PluginLoadOrder.POSTWORLD);
+ this.server.spark.registerCommandBeforePlugins(this.server); // Paper - spark
+ this.server.spark.enableAfterPlugins(this.server); // Paper - spark
+ if (io.papermc.paper.plugin.PluginInitializerManager.instance().pluginRemapper != null) io.papermc.paper.plugin.PluginInitializerManager.instance().pluginRemapper.pluginsEnabled(); // Paper - Remap plugins
+ io.papermc.paper.command.brigadier.PaperCommands.INSTANCE.setValid(); // Paper - reset invalid state for event fire below
+ io.papermc.paper.plugin.lifecycle.event.LifecycleEventRunner.INSTANCE.callReloadableRegistrarEvent(io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents.COMMANDS, io.papermc.paper.command.brigadier.PaperCommands.INSTANCE, org.bukkit.plugin.Plugin.class, io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause.INITIAL); // Paper - call commands event for regular plugins
@@ -567,7 +569,7 @@
if (!iworlddataserver.isInitialized()) {
try {
@@ -427,30 +729,8 @@
@@ -427,30 +731,8 @@
iworlddataserver.setInitialized(true);
}
@@ -599,7 +601,7 @@
private static void setInitialSpawn(ServerLevel world, ServerLevelData worldProperties, boolean bonusChest, boolean debugWorld) {
if (debugWorld) {
@@ -458,6 +738,21 @@
@@ -458,6 +740,21 @@
} else {
ServerChunkCache chunkproviderserver = world.getChunkSource();
ChunkPos chunkcoordintpair = new ChunkPos(chunkproviderserver.randomState().sampler().findSpawnPosition());
@@ -621,7 +623,7 @@
int i = chunkproviderserver.getGenerator().getSpawnHeight(world);
if (i < world.getMinY()) {
@@ -516,31 +811,36 @@
@@ -516,31 +813,36 @@
iworlddataserver.setGameType(GameType.SPECTATOR);
}
@@ -669,7 +671,7 @@
ForcedChunksSavedData forcedchunk = (ForcedChunksSavedData) worldserver1.getDataStorage().get(ForcedChunksSavedData.factory(), "chunks");
if (forcedchunk != null) {
@@ -555,10 +855,17 @@
@@ -555,10 +857,17 @@
}
}
@@ -691,7 +693,7 @@
}
public GameType getDefaultGameType() {
@@ -588,12 +895,16 @@
@@ -588,12 +897,16 @@
worldserver.save((ProgressListener) null, flush, worldserver.noSave && !force);
}
@@ -710,7 +712,7 @@
if (flush) {
Iterator iterator1 = this.getAllLevels().iterator();
@@ -628,18 +939,45 @@
@@ -628,18 +941,46 @@
this.stopServer();
}
@@ -741,6 +743,7 @@
+ Commands.COMMAND_SENDING_POOL.shutdownNow(); // Paper - Perf: Async command map building; Shutdown and don't bother finishing
+ // CraftBukkit start
+ if (this.server != null) {
+ this.server.spark.disable(); // Paper - spark
+ this.server.disablePlugins();
+ this.server.waitForAsyncTasksShutdown(); // Paper - Wait for Async Tasks during shutdown
+ }
@@ -757,7 +760,7 @@
}
MinecraftServer.LOGGER.info("Saving worlds");
@@ -693,6 +1031,15 @@
@@ -693,6 +1034,15 @@
} catch (IOException ioexception1) {
MinecraftServer.LOGGER.error("Failed to unlock level {}", this.storageSource.getLevelId(), ioexception1);
}
@@ -773,7 +776,7 @@
}
@@ -709,6 +1056,14 @@
@@ -709,6 +1059,14 @@
}
public void halt(boolean waitForShutdown) {
@@ -788,7 +791,7 @@
this.running = false;
if (waitForShutdown) {
try {
@@ -720,6 +1075,64 @@
@@ -720,6 +1078,64 @@
}
@@ -853,14 +856,15 @@
protected void runServer() {
try {
if (!this.initServer()) {
@@ -727,8 +1140,25 @@
@@ -727,9 +1143,27 @@
}
this.nextTickTimeNanos = Util.getNanos();
- this.statusIcon = (ServerStatus.Favicon) this.loadStatusIcon().orElse((Object) null);
+ this.statusIcon = (ServerStatus.Favicon) this.loadStatusIcon().orElse(null); // CraftBukkit - decompile error
this.status = this.buildServerStatus();
+
+ this.server.spark.enableBeforePlugins(); // Paper - spark
+ // Spigot start
+ org.spigotmc.WatchdogThread.hasStarted = true; // Paper
+ Arrays.fill( this.recentTps, 20 );
@@ -877,10 +881,11 @@
+ LOGGER.info("*************************************************************************************");
+ }
+ // Paper end - Add onboarding message for initial server start
+
while (this.running) {
long i;
@@ -744,11 +1174,30 @@
@@ -744,12 +1178,31 @@
if (j > MinecraftServer.OVERLOADED_THRESHOLD_NANOS + 20L * i && this.nextTickTimeNanos - this.lastOverloadWarningNanos >= MinecraftServer.OVERLOADED_WARNING_INTERVAL_NANOS + 100L * i) {
long k = j / i;
@@ -889,7 +894,7 @@
this.nextTickTimeNanos += k * i;
this.lastOverloadWarningNanos = this.nextTickTimeNanos;
}
+ }
}
+ // Spigot start
+ // Paper start - further improve server tick loop
+ currentTime = Util.getNanos();
@@ -899,19 +904,20 @@
+ tps1.add(currentTps, diff);
+ tps5.add(currentTps, diff);
+ tps15.add(currentTps, diff);
+
+ // Backwards compat with bad plugins
+ this.recentTps[0] = tps1.getAverage();
+ this.recentTps[1] = tps5.getAverage();
+ this.recentTps[2] = tps15.getAverage();
+ tickSection = currentTime;
}
+ }
+ // Paper end - further improve server tick loop
+ // Spigot end
+
boolean flag = i == 0L;
@@ -757,6 +1206,8 @@
if (this.debugCommandProfilerDelayStart) {
@@ -757,6 +1210,8 @@
this.debugCommandProfiler = new MinecraftServer.TimeProfiler(Util.getNanos(), this.tickCount);
}
@@ -920,7 +926,7 @@
this.nextTickTimeNanos += i;
try {
@@ -830,6 +1281,14 @@
@@ -830,6 +1285,14 @@
this.services.profileCache().clearExecutor();
}
@@ -935,7 +941,7 @@
this.onServerExit();
}
@@ -889,9 +1348,16 @@
@@ -889,9 +1352,16 @@
}
private boolean haveTime() {
@@ -953,7 +959,7 @@
public static boolean throwIfFatalException() {
RuntimeException runtimeexception = (RuntimeException) MinecraftServer.fatalException.get();
@@ -903,7 +1369,7 @@
@@ -903,7 +1373,7 @@
}
public static void setFatalException(RuntimeException exception) {
@@ -962,7 +968,7 @@
}
@Override
@@ -961,6 +1427,7 @@
@@ -961,6 +1431,7 @@
if (super.pollTask()) {
return true;
} else {
@@ -970,7 +976,7 @@
if (this.tickRateManager.isSprinting() || this.haveTime()) {
Iterator iterator = this.getAllLevels().iterator();
@@ -968,16 +1435,16 @@
@@ -968,16 +1439,16 @@
ServerLevel worldserver = (ServerLevel) iterator.next();
if (worldserver.getChunkSource().pollTask()) {
@@ -990,7 +996,7 @@
Profiler.get().incrementCounter("runTask");
super.doRunTask(ticktask);
}
@@ -1025,6 +1492,7 @@
@@ -1025,6 +1496,7 @@
}
public void tickServer(BooleanSupplier shouldKeepTicking) {
@@ -998,21 +1004,30 @@
long i = Util.getNanos();
int j = this.pauseWhileEmptySeconds() * 20;
@@ -1041,11 +1509,13 @@
@@ -1036,16 +1508,22 @@
}
if (this.emptyTicks >= j) {
+ this.server.spark.tickStart(); // Paper - spark
if (this.emptyTicks == j) {
MinecraftServer.LOGGER.info("Server empty for {} seconds, pausing", this.pauseWhileEmptySeconds());
this.autoSave();
}
+ this.server.getScheduler().mainThreadHeartbeat(); // CraftBukkit
+ this.server.spark.executeMainThreadTasks(); // Paper - spark
this.tickConnection();
+ this.server.spark.tickEnd(((double)(System.nanoTime() - lastTick) / 1000000D)); // Paper - spark
return;
}
}
+ this.server.spark.tickStart(); // Paper - spark
+ new com.destroystokyo.paper.event.server.ServerTickStartEvent(this.tickCount+1).callEvent(); // Paper - Server Tick Events
++this.tickCount;
this.tickRateManager.tick();
this.tickChildren(shouldKeepTicking);
@@ -1055,12 +1525,18 @@
@@ -1055,12 +1533,20 @@
}
--this.ticksUntilAutosave;
@@ -1024,15 +1039,17 @@
ProfilerFiller gameprofilerfiller = Profiler.get();
+ this.runAllTasks(); // Paper - move runAllTasks() into full server tick (previously for timings)
+ this.server.spark.executeMainThreadTasks(); // Paper - spark
+ // Paper start - Server Tick Events
+ 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();
+ // Paper end - Server Tick Events
+ this.server.spark.tickEnd(((double)(endTime - lastTick) / 1000000D)); // Paper - spark
gameprofilerfiller.push("tallying");
long k = Util.getNanos() - i;
int l = this.tickCount % 100;
@@ -1069,12 +1545,17 @@
@@ -1069,12 +1555,17 @@
this.aggregatedTickTimesNanos += k;
this.tickTimesNanos[l] = k;
this.smoothedTickTimeMillis = this.smoothedTickTimeMillis * 0.8F + (float) k / (float) TimeUtil.NANOSECONDS_PER_MILLISECOND * 0.19999999F;
@@ -1051,7 +1068,7 @@
MinecraftServer.LOGGER.debug("Autosave started");
ProfilerFiller gameprofilerfiller = Profiler.get();
@@ -1123,7 +1604,7 @@
@@ -1123,7 +1614,7 @@
private ServerStatus buildServerStatus() {
ServerStatus.Players serverping_serverpingplayersample = this.buildPlayerStatus();
@@ -1060,7 +1077,7 @@
}
private ServerStatus.Players buildPlayerStatus() {
@@ -1133,7 +1614,7 @@
@@ -1133,7 +1624,7 @@
if (this.hidesOnlinePlayers()) {
return new ServerStatus.Players(i, list.size(), List.of());
} else {
@@ -1069,7 +1086,7 @@
ObjectArrayList<GameProfile> objectarraylist = new ObjectArrayList(j);
int k = Mth.nextInt(this.random, 0, list.size() - j);
@@ -1154,24 +1635,72 @@
@@ -1154,24 +1645,72 @@
this.getPlayerList().getPlayers().forEach((entityplayer) -> {
entityplayer.connection.suspendFlushing();
});
@@ -1094,7 +1111,7 @@
gameprofilerfiller.popPush("levels");
- Iterator iterator = this.getAllLevels().iterator();
+ //Iterator iterator = this.getAllLevels().iterator(); // Paper - Throw exception on world create while being ticked; moved down
+
+ // CraftBukkit start
+ // Run tasks that are waiting on processing
+ while (!this.processQueue.isEmpty()) {
@@ -1120,7 +1137,7 @@
+ // Paper end - Perf: Optimize time updates
+ }
+ }
+
+ this.isIteratingOverLevels = true; // Paper - Throw exception on world create while being ticked
+ Iterator iterator = this.getAllLevels().iterator(); // Paper - Throw exception on world create while being ticked; move down
while (iterator.hasNext()) {
@@ -1143,7 +1160,7 @@
gameprofilerfiller.push("tick");
@@ -1186,7 +1715,9 @@
@@ -1186,7 +1725,9 @@
gameprofilerfiller.pop();
gameprofilerfiller.pop();
@@ -1153,7 +1170,7 @@
gameprofilerfiller.popPush("connection");
this.tickConnection();
@@ -1267,6 +1798,22 @@
@@ -1267,6 +1808,22 @@
return (ServerLevel) this.levels.get(key);
}
@@ -1176,7 +1193,7 @@
public Set<ResourceKey<Level>> levelKeys() {
return this.levels.keySet();
}
@@ -1296,7 +1843,7 @@
@@ -1296,7 +1853,7 @@
@DontObfuscate
public String getServerModName() {
@@ -1185,7 +1202,7 @@
}
public SystemReport fillSystemReport(SystemReport details) {
@@ -1347,7 +1894,7 @@
@@ -1347,7 +1904,7 @@
@Override
public void sendSystemMessage(Component message) {
@@ -1194,7 +1211,7 @@
}
public KeyPair getKeyPair() {
@@ -1385,11 +1932,14 @@
@@ -1385,11 +1942,14 @@
}
}
@@ -1214,7 +1231,7 @@
}
}
@@ -1403,7 +1953,7 @@
@@ -1403,7 +1963,7 @@
while (iterator.hasNext()) {
ServerLevel worldserver = (ServerLevel) iterator.next();
@@ -1223,7 +1240,7 @@
}
}
@@ -1481,10 +2031,20 @@
@@ -1481,10 +2041,20 @@
@Override
public String getMotd() {
@@ -1245,7 +1262,7 @@
this.motd = motd;
}
@@ -1507,7 +2067,7 @@
@@ -1507,7 +2077,7 @@
}
public ServerConnectionListener getConnection() {
@@ -1254,7 +1271,7 @@
}
public boolean isReady() {
@@ -1593,7 +2153,7 @@
@@ -1593,7 +2163,7 @@
@Override
public void executeIfPossible(Runnable runnable) {
if (this.isStopped()) {
@@ -1263,7 +1280,7 @@
} else {
super.executeIfPossible(runnable);
}
@@ -1632,13 +2192,19 @@
@@ -1632,13 +2202,19 @@
return this.functionManager;
}
@@ -1285,7 +1302,7 @@
}, this).thenCompose((immutablelist) -> {
MultiPackResourceManager resourcemanager = new MultiPackResourceManager(PackType.SERVER_DATA, immutablelist);
List<Registry.PendingTags<?>> list = TagLoader.loadTagsForExistingRegistries(resourcemanager, this.registries.compositeAccess());
@@ -1652,6 +2218,7 @@
@@ -1652,6 +2228,7 @@
return new MinecraftServer.ReloadableResources(resourcemanager, datapackresources);
});
}).thenAcceptAsync((minecraftserver_reloadableresources) -> {
@@ -1293,7 +1310,7 @@
this.resources.close();
this.resources = minecraftserver_reloadableresources;
this.packRepository.setSelected(dataPacks);
@@ -1660,11 +2227,23 @@
@@ -1660,11 +2237,23 @@
this.worldData.setDataConfiguration(worlddataconfiguration);
this.resources.managers.updateStaticRegistryTags();
this.resources.managers.getRecipeManager().finalizeRecipeLoading(this.worldData.enabledFeatures());
@@ -1317,7 +1334,7 @@
}, this);
if (this.isSameThread()) {
@@ -1789,14 +2368,15 @@
@@ -1789,14 +2378,15 @@
if (this.isEnforceWhitelist()) {
PlayerList playerlist = source.getServer().getPlayerList();
UserWhiteList whitelist = playerlist.getWhiteList();
@@ -1335,7 +1352,7 @@
}
}
@@ -1952,7 +2532,7 @@
@@ -1952,7 +2542,7 @@
final List<String> list = Lists.newArrayList();
final GameRules gamerules = this.getGameRules();
@@ -1344,7 +1361,7 @@
@Override
public <T extends GameRules.Value<T>> void visit(GameRules.Key<T> key, GameRules.Type<T> type) {
list.add(String.format(Locale.ROOT, "%s=%s\n", key.getId(), gamerules.getRule(key)));
@@ -2058,7 +2638,7 @@
@@ -2058,7 +2648,7 @@
try {
label51:
{
@@ -1353,19 +1370,22 @@
try {
arraylist = Lists.newArrayList(NativeModuleLister.listModules());
@@ -2108,6 +2688,21 @@
}
@@ -2105,9 +2695,24 @@
if (bufferedwriter != null) {
bufferedwriter.close();
}
+
+ }
+
+ // CraftBukkit start
+ public boolean isDebugging() {
+ return false;
+ }
+
+ public static MinecraftServer getServer() {
+ return SERVER; // Paper
+ }
+
}
+ @Deprecated
+ public static RegistryAccess getDefaultRegistryAccess() {
+ return CraftRegistry.getMinecraftRegistry();
@@ -1375,7 +1395,7 @@
private ProfilerFiller createProfiler() {
if (this.willStartRecordingMetrics) {
this.metricsRecorder = ActiveMetricsRecorder.createStarted(new ServerMetricsSamplersProvider(Util.timeSource, this.isDedicatedServer()), Util.timeSource, Util.ioPool(), new MetricsPersister("server"), this.onMetricsRecordingStopped, (path) -> {
@@ -2225,18 +2820,24 @@
@@ -2225,18 +2830,24 @@
}
public void logChatMessage(Component message, ChatType.Bound params, @Nullable String prefix) {
@@ -1404,7 +1424,7 @@
}
public boolean logIPs() {
@@ -2379,4 +2980,30 @@
@@ -2379,4 +2990,30 @@
public static record ServerResourcePackInfo(UUID id, String url, String hash, boolean isRequired, @Nullable Component prompt) {
}