and some more
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
--- a/net/minecraft/server/Main.java
|
||||
+++ b/net/minecraft/server/Main.java
|
||||
@@ -67,8 +_,9 @@
|
||||
@@ -67,8 +_,10 @@
|
||||
reason = "System.out needed before bootstrap"
|
||||
)
|
||||
@DontObfuscate
|
||||
- public static void main(String[] args) {
|
||||
+ public static void main(final OptionSet optionSet) { // CraftBukkit - replaces main(String[] args)
|
||||
+ io.papermc.paper.util.LogManagerShutdownThread.hook(); // Paper - Improved watchdog support
|
||||
SharedConstants.tryDetectVersion();
|
||||
+ /* CraftBukkit start - Replace everything
|
||||
OptionParser optionParser = new OptionParser();
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
@Nullable
|
||||
private KeyPair keyPair;
|
||||
@Nullable
|
||||
@@ -271,10 +_,35 @@
|
||||
@@ -271,10 +_,37 @@
|
||||
private final SuppressedExceptionCollector suppressedExceptions = new SuppressedExceptionCollector();
|
||||
private final DiscontinuousFrame tickFrame;
|
||||
|
||||
@@ -65,9 +65,11 @@
|
||||
+ // Spigot end
|
||||
+ public volatile boolean hasFullyShutdown; // Paper - Improved watchdog support
|
||||
+ public volatile boolean abnormalExit; // Paper - Improved watchdog support
|
||||
+ public volatile Thread shutdownThread; // Paper - Improved watchdog support
|
||||
+ public final io.papermc.paper.configuration.PaperConfigurations paperConfigurations; // Paper - add paper configuration files
|
||||
+ public boolean isIteratingOverLevels = false; // Paper - Throw exception on world create while being ticked
|
||||
+ private final Set<String> pluginsBlockingSleep = new java.util.HashSet<>(); // Paper - API to allow/disallow tick sleeping
|
||||
+ public static final long SERVER_INIT = System.nanoTime(); // Paper - Lag compensation
|
||||
+
|
||||
public static <S extends MinecraftServer> S spin(Function<Thread, S> threadFunction) {
|
||||
AtomicReference<S> atomicReference = new AtomicReference<>();
|
||||
@@ -110,7 +112,7 @@
|
||||
this.tickRateManager = new ServerTickRateManager(this);
|
||||
this.progressListenerFactory = progressListenerFactory;
|
||||
this.storageSource = storageSource;
|
||||
@@ -328,6 +_,37 @@
|
||||
@@ -328,6 +_,38 @@
|
||||
this.fuelValues = FuelValues.vanillaBurnTimes(this.registries.compositeAccess(), this.worldData.enabledFeatures());
|
||||
this.tickFrame = TracyClient.createDiscontinuousFrame("Server Tick");
|
||||
}
|
||||
@@ -142,6 +144,7 @@
|
||||
+ }
|
||||
+ */
|
||||
+ // Paper end
|
||||
+ io.papermc.paper.util.LogManagerShutdownThread.unhook(); // Paper - Improved watchdog support
|
||||
+ Runtime.getRuntime().addShutdownHook(new org.bukkit.craftbukkit.util.ServerShutdownThread(this));
|
||||
+ // CraftBukkit end
|
||||
+ this.paperConfigurations = services.paperConfigurations(); // Paper - add paper configuration files
|
||||
@@ -595,7 +598,7 @@
|
||||
if (flush) {
|
||||
for (ServerLevel serverLevel2 : this.getAllLevels()) {
|
||||
LOGGER.info("ThreadedAnvilChunkStorage ({}): All chunks are saved", serverLevel2.getChunkSource().chunkMap.getStorageName());
|
||||
@@ -593,18 +_,46 @@
|
||||
@@ -593,18 +_,48 @@
|
||||
this.stopServer();
|
||||
}
|
||||
|
||||
@@ -617,6 +620,8 @@
|
||||
+ this.hasStopped = true;
|
||||
+ }
|
||||
+ if (!hasLoggedStop && isDebugging()) io.papermc.paper.util.TraceUtil.dumpTraceForThread("Server stopped"); // Paper - Debugging
|
||||
+ shutdownThread = Thread.currentThread(); // Paper - Improved watchdog support
|
||||
+ org.spigotmc.WatchdogThread.doStop(); // Paper - Improved watchdog support
|
||||
+ // CraftBukkit end
|
||||
if (this.metricsRecorder.isRecording()) {
|
||||
this.cancelRecordingMetrics();
|
||||
@@ -643,7 +648,7 @@
|
||||
}
|
||||
|
||||
LOGGER.info("Saving worlds");
|
||||
@@ -646,6 +_,16 @@
|
||||
@@ -646,6 +_,25 @@
|
||||
} catch (IOException var4) {
|
||||
LOGGER.error("Failed to unlock level {}", this.storageSource.getLevelId(), var4);
|
||||
}
|
||||
@@ -657,6 +662,15 @@
|
||||
+ this.getProfileCache().save(false); // Paper - Perf: Async GameProfileCache saving
|
||||
+ }
|
||||
+ // Spigot end
|
||||
+ // Paper start - Improved watchdog support - move final shutdown items here
|
||||
+ Util.shutdownExecutors();
|
||||
+ try {
|
||||
+ net.minecrell.terminalconsole.TerminalConsoleAppender.close(); // Paper - Use TerminalConsoleAppender
|
||||
+ } catch (final Exception ignored) {
|
||||
+ }
|
||||
+ io.papermc.paper.log.CustomLogManager.forceReset(); // Paper - Reset loggers after shutdown
|
||||
+ this.onServerExit();
|
||||
+ // Paper end - Improved watchdog support - move final shutdown items here
|
||||
}
|
||||
|
||||
public String getLocalIp() {
|
||||
@@ -733,12 +747,23 @@
|
||||
protected void runServer() {
|
||||
try {
|
||||
if (!this.initServer()) {
|
||||
@@ -681,6 +_,24 @@
|
||||
@@ -681,6 +_,35 @@
|
||||
this.statusIcon = this.loadStatusIcon().orElse(null);
|
||||
this.status = this.buildServerStatus();
|
||||
|
||||
+ this.server.spark.enableBeforePlugins(); // Paper - spark
|
||||
+ // Spigot start
|
||||
+ // Paper start
|
||||
+ LOGGER.info("Running delayed init tasks");
|
||||
+ this.server.getScheduler().mainThreadHeartbeat(); // run all 1 tick delay tasks during init,
|
||||
+ // this is going to be the first thing the tick process does anyways, so move done and run it after
|
||||
+ // everything is init before watchdog tick.
|
||||
+ // anything at 3+ won't be caught here but also will trip watchdog....
|
||||
+ // tasks are default scheduled at -1 + delay, and first tick will tick at 1
|
||||
+ final long actualDoneTimeMs = System.currentTimeMillis() - org.bukkit.craftbukkit.Main.BOOT_TIME.toEpochMilli(); // Paper - Improve startup message
|
||||
+ LOGGER.info("Done ({})! For help, type \"help\"", String.format(java.util.Locale.ROOT, "%.3fs", actualDoneTimeMs / 1000.00D)); // Paper - Improve startup message
|
||||
+ org.spigotmc.WatchdogThread.tick();
|
||||
+ // Paper end
|
||||
+ org.spigotmc.WatchdogThread.hasStarted = true; // Paper
|
||||
+ Arrays.fill(this.recentTps, 20);
|
||||
+ // Paper start - further improve server tick loop
|
||||
@@ -798,21 +823,15 @@
|
||||
this.nextTickTimeNanos += l;
|
||||
|
||||
try (Profiler.Scope scope = Profiler.use(this.createProfiler())) {
|
||||
@@ -755,6 +_,14 @@
|
||||
@@ -755,7 +_,7 @@
|
||||
this.services.profileCache().clearExecutor();
|
||||
}
|
||||
|
||||
+ org.spigotmc.WatchdogThread.doStop(); // Spigot
|
||||
+ // CraftBukkit start - Restore terminal to original settings
|
||||
+ try {
|
||||
+ net.minecrell.terminalconsole.TerminalConsoleAppender.close(); // Paper - Use TerminalConsoleAppender
|
||||
+ } catch (Exception ignored) {
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
+ io.papermc.paper.log.CustomLogManager.forceReset(); // Paper - Reset loggers after shutdown
|
||||
this.onServerExit();
|
||||
- this.onServerExit();
|
||||
+ //this.onServerExit(); // Paper - Improved watchdog support; moved into stop
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -807,7 +_,14 @@
|
||||
}
|
||||
|
||||
@@ -829,6 +848,19 @@
|
||||
}
|
||||
|
||||
public static boolean throwIfFatalException() {
|
||||
@@ -852,6 +_,12 @@
|
||||
|
||||
@Override
|
||||
public TickTask wrapRunnable(Runnable runnable) {
|
||||
+ // Paper start - anything that does try to post to main during watchdog crash, run on watchdog
|
||||
+ if (this.hasStopped && Thread.currentThread().equals(shutdownThread)) {
|
||||
+ runnable.run();
|
||||
+ runnable = () -> {};
|
||||
+ }
|
||||
+ // Paper end
|
||||
return new TickTask(this.tickCount, runnable);
|
||||
}
|
||||
|
||||
@@ -871,15 +_,16 @@
|
||||
if (super.pollTask()) {
|
||||
return true;
|
||||
@@ -952,7 +984,7 @@
|
||||
ObjectArrayList<GameProfile> list = new ObjectArrayList<>(min);
|
||||
int randomInt = Mth.nextInt(this.random, 0, players.size() - min);
|
||||
|
||||
@@ -1046,17 +_,64 @@
|
||||
@@ -1046,17 +_,65 @@
|
||||
protected void tickChildren(BooleanSupplier hasTimeLeft) {
|
||||
ProfilerFiller profilerFiller = Profiler.get();
|
||||
this.getPlayerList().getPlayers().forEach(serverPlayer1 -> serverPlayer1.connection.suspendFlushing());
|
||||
@@ -1006,6 +1038,7 @@
|
||||
for (ServerLevel serverLevel : this.getAllLevels()) {
|
||||
+ serverLevel.hasPhysicsEvent = org.bukkit.event.block.BlockPhysicsEvent.getHandlerList().getRegisteredListeners().length > 0; // Paper - BlockPhysicsEvent
|
||||
+ serverLevel.hasEntityMoveEvent = io.papermc.paper.event.entity.EntityMoveEvent.getHandlerList().getRegisteredListeners().length > 0; // Paper - Add EntityMoveEvent
|
||||
+ serverLevel.updateLagCompensationTick(); // Paper - lag compensation
|
||||
profilerFiller.push(() -> serverLevel + " " + serverLevel.dimension().location());
|
||||
+ /* Drop global time updates
|
||||
if (this.tickCount % 20 == 0) {
|
||||
@@ -1168,12 +1201,19 @@
|
||||
this.resources.close();
|
||||
this.resources = reloadableResources;
|
||||
this.packRepository.setSelected(selectedIds);
|
||||
@@ -1529,11 +_,23 @@
|
||||
@@ -1529,11 +_,29 @@
|
||||
this.worldData.setDataConfiguration(worldDataConfiguration);
|
||||
this.resources.managers.updateStaticRegistryTags();
|
||||
this.resources.managers.getRecipeManager().finalizeRecipeLoading(this.worldData.enabledFeatures());
|
||||
- this.getPlayerList().saveAll();
|
||||
+ this.potionBrewing = this.potionBrewing.reload(this.worldData.enabledFeatures()); // Paper - Custom Potion Mixes
|
||||
this.getPlayerList().saveAll();
|
||||
+ if (Thread.currentThread() != this.serverThread) return; // Paper
|
||||
+ // Paper start - we don't need to save everything, just advancements
|
||||
+ // this.getPlayerList().saveAll();
|
||||
+ for (final ServerPlayer player : this.getPlayerList().getPlayers()) {
|
||||
+ player.getAdvancements().save();
|
||||
+ }
|
||||
+ // Paper end - we don't need to save everything, just advancements
|
||||
this.getPlayerList().reloadResources();
|
||||
this.functionManager.replaceLibrary(this.resources.managers.getFunctionLibrary());
|
||||
this.structureTemplateManager.onResourceManagerReload(this.resources.resourceManager);
|
||||
|
||||
@@ -263,7 +263,8 @@
|
||||
+ this.loadLevel(this.storageSource.getLevelId()); // CraftBukkit
|
||||
long l = Util.getNanos() - nanos;
|
||||
String string = String.format(Locale.ROOT, "%.3fs", l / 1.0E9);
|
||||
LOGGER.info("Done ({})! For help, type \"help\"", string);
|
||||
- LOGGER.info("Done ({})! For help, type \"help\"", string);
|
||||
+ LOGGER.info("Done preparing level \"{}\" ({})", this.getLevelIdName(), string); // Paper - Improve startup message, add total time
|
||||
if (properties.announcePlayerAchievements != null) {
|
||||
- this.getGameRules().getRule(GameRules.RULE_ANNOUNCE_ADVANCEMENTS).set(properties.announcePlayerAchievements, this);
|
||||
+ this.getGameRules().getRule(GameRules.RULE_ANNOUNCE_ADVANCEMENTS).set(properties.announcePlayerAchievements, this.overworld()); // CraftBukkit - per-world
|
||||
@@ -315,7 +316,7 @@
|
||||
}
|
||||
+
|
||||
+ this.hasFullyShutdown = true; // Paper - Improved watchdog support
|
||||
+ System.exit(0); // CraftBukkit
|
||||
+ System.exit(this.abnormalExit ? 70 : 0); // CraftBukkit // Paper - Improved watchdog support
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -417,6 +418,15 @@
|
||||
}
|
||||
|
||||
public void storeUsingWhiteList(boolean isStoreUsingWhiteList) {
|
||||
@@ -532,7 +_,7 @@
|
||||
@Override
|
||||
public void stopServer() {
|
||||
super.stopServer();
|
||||
- Util.shutdownExecutors();
|
||||
+ //Util.shutdownExecutors(); // Paper - Improved watchdog support; moved into super
|
||||
SkullBlockEntity.clear();
|
||||
}
|
||||
|
||||
@@ -626,4 +_,15 @@
|
||||
}
|
||||
}
|
||||
|
||||
@@ -456,7 +456,33 @@
|
||||
}
|
||||
|
||||
public void resetEmptyTime() {
|
||||
@@ -753,6 +_,7 @@
|
||||
@@ -746,18 +_,45 @@
|
||||
}
|
||||
}
|
||||
|
||||
+ // Paper start - log detailed entity tick information
|
||||
+ // TODO replace with varhandle
|
||||
+ static final java.util.concurrent.atomic.AtomicReference<Entity> currentlyTickingEntity = new java.util.concurrent.atomic.AtomicReference<>();
|
||||
+
|
||||
+ public static List<Entity> getCurrentlyTickingEntities() {
|
||||
+ Entity ticking = currentlyTickingEntity.get();
|
||||
+ List<Entity> ret = java.util.Arrays.asList(ticking == null ? new Entity[0] : new Entity[] { ticking });
|
||||
+
|
||||
+ return ret;
|
||||
+ }
|
||||
+ // Paper end - log detailed entity tick information
|
||||
+
|
||||
public void tickNonPassenger(Entity entity) {
|
||||
+ // Paper start - log detailed entity tick information
|
||||
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread("Cannot tick an entity off-main");
|
||||
+ try {
|
||||
+ if (currentlyTickingEntity.get() == null) {
|
||||
+ currentlyTickingEntity.lazySet(entity);
|
||||
+ }
|
||||
+ // Paper end - log detailed entity tick information
|
||||
entity.setOldPosAndRot();
|
||||
ProfilerFiller profilerFiller = Profiler.get();
|
||||
entity.tickCount++;
|
||||
profilerFiller.push(() -> BuiltInRegistries.ENTITY_TYPE.getKey(entity.getType()).toString());
|
||||
profilerFiller.incrementCounter("tickNonPassenger");
|
||||
entity.tick();
|
||||
@@ -464,6 +490,18 @@
|
||||
profilerFiller.pop();
|
||||
|
||||
for (Entity entity1 : entity.getPassengers()) {
|
||||
this.tickPassenger(entity, entity1);
|
||||
}
|
||||
+ // Paper start - log detailed entity tick information
|
||||
+ } finally {
|
||||
+ if (currentlyTickingEntity.get() == entity) {
|
||||
+ currentlyTickingEntity.lazySet(null);
|
||||
+ }
|
||||
+ }
|
||||
+ // Paper end - log detailed entity tick information
|
||||
}
|
||||
|
||||
private void tickPassenger(Entity ridingEntity, Entity passengerEntity) {
|
||||
@@ -770,6 +_,7 @@
|
||||
profilerFiller.push(() -> BuiltInRegistries.ENTITY_TYPE.getKey(passengerEntity.getType()).toString());
|
||||
profilerFiller.incrementCounter("tickPassenger");
|
||||
@@ -1137,7 +1175,7 @@
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1792,4 +_,12 @@
|
||||
@@ -1792,4 +_,24 @@
|
||||
entity.updateDynamicGameEventListener(DynamicGameEventListener::move);
|
||||
}
|
||||
}
|
||||
@@ -1149,4 +1187,16 @@
|
||||
+ return this.server.getPlayerList().getPlayer(uuid);
|
||||
+ }
|
||||
+ // Paper end - check global player list where appropriate
|
||||
+
|
||||
+ // Paper start - lag compensation
|
||||
+ private long lagCompensationTick = MinecraftServer.SERVER_INIT;
|
||||
+
|
||||
+ public long getLagCompensationTick() {
|
||||
+ return this.lagCompensationTick;
|
||||
+ }
|
||||
+
|
||||
+ public void updateLagCompensationTick() {
|
||||
+ this.lagCompensationTick = (System.nanoTime() - MinecraftServer.SERVER_INIT) / (java.util.concurrent.TimeUnit.MILLISECONDS.toNanos(50L));
|
||||
+ }
|
||||
+ // Paper end - lag compensation
|
||||
}
|
||||
|
||||
@@ -54,12 +54,13 @@
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,10 +_,10 @@
|
||||
@@ -90,10 +_,11 @@
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
- this.gameTicks++;
|
||||
+ this.gameTicks = net.minecraft.server.MinecraftServer.currentTick; // CraftBukkit
|
||||
+ // this.gameTicks = net.minecraft.server.MinecraftServer.currentTick; // CraftBukkit
|
||||
+ this.gameTicks = (int) this.level.getLagCompensationTick(); // Paper - lag compensate eating
|
||||
if (this.hasDelayedDestroy) {
|
||||
- BlockState blockState = this.level.getBlockState(this.delayedDestroyPos);
|
||||
- if (blockState.isAir()) {
|
||||
|
||||
@@ -371,7 +371,7 @@
|
||||
+ this.cserver.getPluginManager().callEvent(playerQuitEvent);
|
||||
+ player.getBukkitEntity().disconnect(playerQuitEvent.getQuitMessage());
|
||||
+
|
||||
+ player.doTick(); // SPIGOT-924
|
||||
+ if (this.server.isSameThread()) player.doTick(); // SPIGOT-924 // Paper - Improved watchdog support; don't tick during emergency shutdowns
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
+ // Paper start - Configurable player collision; Remove from collideRule team if needed
|
||||
|
||||
Reference in New Issue
Block a user