mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 16:37:43 +01:00
141 lines
9.1 KiB
Diff
141 lines
9.1 KiB
Diff
From fdaa40d397c78dc3305420f9e42eead78bea1982 Mon Sep 17 00:00:00 2001
|
|
From: File <noreply+automated@papermc.io>
|
|
Date: Sun, 20 Apr 1997 06:37:42 -0700
|
|
Subject: [PATCH] purpur File Patches
|
|
|
|
|
|
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
|
|
index 52fa5112cd90ba766c94512a02401dd3aee82cc9..ef5c6a760eb6e72beab186a315bd02e804c9ae53 100644
|
|
--- a/net/minecraft/server/MinecraftServer.java
|
|
+++ b/net/minecraft/server/MinecraftServer.java
|
|
@@ -284,6 +284,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
public joptsimple.OptionSet options;
|
|
public org.bukkit.command.ConsoleCommandSender console;
|
|
public static int currentTick; // Paper - improve tick loop
|
|
+ public static final long startTimeMillis = System.currentTimeMillis(); // Purpur - Add uptime command
|
|
public java.util.Queue<Runnable> processQueue = new java.util.concurrent.ConcurrentLinkedQueue<Runnable>();
|
|
public int autosavePeriod;
|
|
// Paper - don't store the vanilla dispatcher
|
|
@@ -294,7 +295,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
public static final int TICK_TIME = 1000000000 / MinecraftServer.TPS;
|
|
private static final int SAMPLE_INTERVAL = 20; // Paper - improve server tick loop
|
|
@Deprecated(forRemoval = true) // Paper
|
|
- public final double[] recentTps = new double[3];
|
|
+ public final double[] recentTps = new double[4]; // Purpur - Add 5 second tps average in /tps
|
|
// Spigot end
|
|
public volatile boolean hasFullyShutdown; // Paper - Improved watchdog support
|
|
public volatile boolean abnormalExit; // Paper - Improved watchdog support
|
|
@@ -303,6 +304,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
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 boolean lagging = false; // Purpur - Lagging threshold
|
|
+ protected boolean upnp = false; // Purpur - UPnP Port Forwarding
|
|
|
|
public static <S extends MinecraftServer> S spin(Function<Thread, S> threadFunction) {
|
|
ca.spottedleaf.dataconverter.minecraft.datatypes.MCTypeRegistry.init(); // Paper - rewrite data converter system
|
|
@@ -996,6 +999,15 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
|
|
LOGGER.info("Stopping server");
|
|
Commands.COMMAND_SENDING_POOL.shutdownNow(); // Paper - Perf: Async command map building; Shutdown and don't bother finishing
|
|
+ // Purpur start - UPnP Port Forwarding
|
|
+ if (upnp) {
|
|
+ if (dev.omega24.upnp4j.UPnP4J.close(this.getPort(), dev.omega24.upnp4j.util.Protocol.TCP)) {
|
|
+ LOGGER.info("[UPnP] Port {} closed", this.getPort());
|
|
+ } else {
|
|
+ LOGGER.error("[UPnP] Failed to close port {}", this.getPort());
|
|
+ }
|
|
+ }
|
|
+ // Purpur end - UPnP Port Forwarding
|
|
// CraftBukkit start
|
|
if (this.server != null) {
|
|
this.server.spark.disable(); // Paper - spark
|
|
@@ -1094,6 +1106,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
this.safeShutdown(waitForServer, false);
|
|
}
|
|
public void safeShutdown(boolean waitForServer, boolean isRestarting) {
|
|
+ org.purpurmc.purpur.task.BossBarTask.stopAll(); // Purpur - Implement TPSBar
|
|
+ org.purpurmc.purpur.task.BeehiveTask.instance().unregister(); // Purpur - Give bee counts in beehives to Purpur clients
|
|
this.isRestarting = isRestarting;
|
|
this.hasLoggedStop = true; // Paper - Debugging
|
|
if (isDebugging()) io.papermc.paper.util.TraceUtil.dumpTraceForThread("Server stopped"); // Paper - Debugging
|
|
@@ -1113,6 +1127,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
private static final long MAX_CATCHUP_BUFFER = TICK_TIME * TPS * 60L;
|
|
private long lastTick = 0;
|
|
private long catchupTime = 0;
|
|
+ public final RollingAverage tps5s = new RollingAverage(5); // Purpur - Add 5 second tps average in /tps
|
|
public final RollingAverage tps1 = new RollingAverage(60);
|
|
public final RollingAverage tps5 = new RollingAverage(60 * 5);
|
|
public final RollingAverage tps15 = new RollingAverage(60 * 15);
|
|
@@ -1198,6 +1213,16 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
}
|
|
// Paper end - Add onboarding message for initial server start
|
|
|
|
+ // Purpur start - config for startup commands
|
|
+ if (!Boolean.getBoolean("Purpur.IReallyDontWantStartupCommands") && !org.purpurmc.purpur.PurpurConfig.startupCommands.isEmpty()) {
|
|
+ LOGGER.info("Purpur: Running startup commands specified in purpur.yml.");
|
|
+ for (final String startupCommand : org.purpurmc.purpur.PurpurConfig.startupCommands) {
|
|
+ LOGGER.info("Purpur: Running the following command: \"{}\"", startupCommand);
|
|
+ ((net.minecraft.server.dedicated.DedicatedServer) this).handleConsoleInput(startupCommand, this.createCommandSourceStack());
|
|
+ }
|
|
+ }
|
|
+ // Purpur end - config for startup commands
|
|
+
|
|
while (this.running) {
|
|
long l;
|
|
if (!this.isPaused() && this.tickRateManager.isSprinting() && this.tickRateManager.checkShouldSprintThisTick()) {
|
|
@@ -1222,14 +1247,19 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
if (++MinecraftServer.currentTick % MinecraftServer.SAMPLE_INTERVAL == 0) {
|
|
final long diff = currentTime - tickSection;
|
|
final java.math.BigDecimal currentTps = TPS_BASE.divide(new java.math.BigDecimal(diff), 30, java.math.RoundingMode.HALF_UP);
|
|
+ tps5s.add(currentTps, diff); // Purpur - Add 5 second tps average in /tps
|
|
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();
|
|
+ // Purpur start - Add 5 second tps average in /tps
|
|
+ this.recentTps[0] = tps5s.getAverage();
|
|
+ this.recentTps[1] = tps1.getAverage();
|
|
+ this.recentTps[2] = tps5.getAverage();
|
|
+ this.recentTps[3] = tps15.getAverage();
|
|
+ // Purpur end - Add 5 second tps average in /tps
|
|
+ lagging = recentTps[0] < org.purpurmc.purpur.PurpurConfig.laggingThreshold; // Purpur - Lagging threshold
|
|
tickSection = currentTime;
|
|
}
|
|
// Paper end - further improve server tick loop
|
|
@@ -1261,6 +1291,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
profilerFiller.popPush("nextTickWait");
|
|
this.mayHaveDelayedTasks = true;
|
|
this.delayedTasksMaxNextTickTimeNanos = Math.max(Util.getNanos() + l, this.nextTickTimeNanos);
|
|
+ // Purpur start - Configurable TPS Catchup
|
|
+ if (!org.purpurmc.purpur.PurpurConfig.tpsCatchup /*|| !gg.pufferfish.pufferfish.PufferfishConfig.tpsCatchup*/) { // Purpur - Configurable TPS Catchup
|
|
+ this.nextTickTimeNanos = currentTime + l;
|
|
+ this.delayedTasksMaxNextTickTimeNanos = nextTickTimeNanos;
|
|
+ }
|
|
+ // Purpur end - Configurable TPS Catchup
|
|
this.startMeasuringTaskExecutionTime();
|
|
this.waitUntilNextTick();
|
|
this.finishMeasuringTaskExecutionTime();
|
|
@@ -1689,7 +1725,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
long worldTime = level.getGameTime();
|
|
final ClientboundSetTimePacket worldPacket = new ClientboundSetTimePacket(worldTime, dayTime, doDaylight);
|
|
for (Player entityhuman : level.players()) {
|
|
- if (!(entityhuman instanceof ServerPlayer) || (tickCount + entityhuman.getId()) % 20 != 0) {
|
|
+ if (!(entityhuman instanceof ServerPlayer) || (!level.isForceTime() && (tickCount + entityhuman.getId()) % 20 != 0)) { // Purpur - Configurable daylight cycle
|
|
continue;
|
|
}
|
|
ServerPlayer entityplayer = (ServerPlayer) entityhuman;
|
|
@@ -1854,7 +1890,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
|
|
@DontObfuscate
|
|
public String getServerModName() {
|
|
- return io.papermc.paper.ServerBuildInfo.buildInfo().brandName(); // Paper
|
|
+ return org.purpurmc.purpur.PurpurConfig.serverModName; // Paper // Purpur - Configurable server mod name
|
|
}
|
|
|
|
public SystemReport fillSystemReport(SystemReport systemReport) {
|