Fix plugin loggers on server shutdown

This commit is contained in:
José Miguel Moreno 2021-06-05 13:45:15 +02:00
parent ebdde69c39
commit a72acfb245
3 changed files with 68 additions and 33 deletions

View file

@ -565,10 +565,12 @@
if (!iworlddataserver.isInitialized()) { if (!iworlddataserver.isInitialized()) {
try { try {
@@ -427,30 +727,8 @@ @@ -425,32 +725,10 @@
iworlddataserver.setInitialized(true);
} }
iworlddataserver.setInitialized(true);
- }
-
- this.getPlayerList().addWorldborderListener(worldserver); - this.getPlayerList().addWorldborderListener(worldserver);
- if (this.worldData.getCustomBossEvents() != null) { - if (this.worldData.getCustomBossEvents() != null) {
- this.getCustomBossEvents().load(this.worldData.getCustomBossEvents(), this.registryAccess()); - this.getCustomBossEvents().load(this.worldData.getCustomBossEvents(), this.registryAccess());
@ -589,8 +591,8 @@
- worldborder.addListener(new BorderChangeListener.DelegateBorderChangeListener(worldserver1.getWorldBorder())); - worldborder.addListener(new BorderChangeListener.DelegateBorderChangeListener(worldserver1.getWorldBorder()));
- this.levels.put(resourcekey1, worldserver1); - this.levels.put(resourcekey1, worldserver1);
- } - }
- } }
-
- worldborder.applySettings(iworlddataserver.getWorldBorder()); - worldborder.applySettings(iworlddataserver.getWorldBorder());
} }
+ // CraftBukkit end + // CraftBukkit end
@ -910,7 +912,7 @@
this.nextTickTimeNanos += i; this.nextTickTimeNanos += i;
try { try {
@@ -830,6 +1269,13 @@ @@ -830,6 +1269,14 @@
this.services.profileCache().clearExecutor(); this.services.profileCache().clearExecutor();
} }
@ -921,10 +923,11 @@
+ } catch (Exception ignored) { + } catch (Exception ignored) {
+ } + }
+ // CraftBukkit end + // CraftBukkit end
+ io.papermc.paper.log.CustomLogManager.forceReset(); // Paper - Reset loggers after shutdown
this.onServerExit(); this.onServerExit();
} }
@@ -889,9 +1335,16 @@ @@ -889,9 +1336,16 @@
} }
private boolean haveTime() { private boolean haveTime() {
@ -942,7 +945,7 @@
public static boolean throwIfFatalException() { public static boolean throwIfFatalException() {
RuntimeException runtimeexception = (RuntimeException) MinecraftServer.fatalException.get(); RuntimeException runtimeexception = (RuntimeException) MinecraftServer.fatalException.get();
@@ -903,7 +1356,7 @@ @@ -903,7 +1357,7 @@
} }
public static void setFatalException(RuntimeException exception) { public static void setFatalException(RuntimeException exception) {
@ -951,7 +954,7 @@
} }
@Override @Override
@@ -961,6 +1414,7 @@ @@ -961,6 +1415,7 @@
if (super.pollTask()) { if (super.pollTask()) {
return true; return true;
} else { } else {
@ -959,7 +962,7 @@
if (this.tickRateManager.isSprinting() || this.haveTime()) { if (this.tickRateManager.isSprinting() || this.haveTime()) {
Iterator iterator = this.getAllLevels().iterator(); Iterator iterator = this.getAllLevels().iterator();
@@ -968,16 +1422,16 @@ @@ -968,16 +1423,16 @@
ServerLevel worldserver = (ServerLevel) iterator.next(); ServerLevel worldserver = (ServerLevel) iterator.next();
if (worldserver.getChunkSource().pollTask()) { if (worldserver.getChunkSource().pollTask()) {
@ -979,7 +982,7 @@
Profiler.get().incrementCounter("runTask"); Profiler.get().incrementCounter("runTask");
super.doRunTask(ticktask); super.doRunTask(ticktask);
} }
@@ -1025,6 +1479,7 @@ @@ -1025,6 +1480,7 @@
} }
public void tickServer(BooleanSupplier shouldKeepTicking) { public void tickServer(BooleanSupplier shouldKeepTicking) {
@ -987,7 +990,7 @@
long i = Util.getNanos(); long i = Util.getNanos();
int j = this.pauseWhileEmptySeconds() * 20; int j = this.pauseWhileEmptySeconds() * 20;
@@ -1041,11 +1496,13 @@ @@ -1041,11 +1497,13 @@
this.autoSave(); this.autoSave();
} }
@ -1001,7 +1004,7 @@
++this.tickCount; ++this.tickCount;
this.tickRateManager.tick(); this.tickRateManager.tick();
this.tickChildren(shouldKeepTicking); this.tickChildren(shouldKeepTicking);
@@ -1055,12 +1512,18 @@ @@ -1055,12 +1513,18 @@
} }
--this.ticksUntilAutosave; --this.ticksUntilAutosave;
@ -1021,7 +1024,7 @@
gameprofilerfiller.push("tallying"); gameprofilerfiller.push("tallying");
long k = Util.getNanos() - i; long k = Util.getNanos() - i;
int l = this.tickCount % 100; int l = this.tickCount % 100;
@@ -1069,12 +1532,17 @@ @@ -1069,12 +1533,17 @@
this.aggregatedTickTimesNanos += k; this.aggregatedTickTimesNanos += k;
this.tickTimesNanos[l] = k; this.tickTimesNanos[l] = k;
this.smoothedTickTimeMillis = this.smoothedTickTimeMillis * 0.8F + (float) k / (float) TimeUtil.NANOSECONDS_PER_MILLISECOND * 0.19999999F; this.smoothedTickTimeMillis = this.smoothedTickTimeMillis * 0.8F + (float) k / (float) TimeUtil.NANOSECONDS_PER_MILLISECOND * 0.19999999F;
@ -1040,7 +1043,7 @@
MinecraftServer.LOGGER.debug("Autosave started"); MinecraftServer.LOGGER.debug("Autosave started");
ProfilerFiller gameprofilerfiller = Profiler.get(); ProfilerFiller gameprofilerfiller = Profiler.get();
@@ -1123,7 +1591,7 @@ @@ -1123,7 +1592,7 @@
private ServerStatus buildServerStatus() { private ServerStatus buildServerStatus() {
ServerStatus.Players serverping_serverpingplayersample = this.buildPlayerStatus(); ServerStatus.Players serverping_serverpingplayersample = this.buildPlayerStatus();
@ -1049,7 +1052,7 @@
} }
private ServerStatus.Players buildPlayerStatus() { private ServerStatus.Players buildPlayerStatus() {
@@ -1133,7 +1601,7 @@ @@ -1133,7 +1602,7 @@
if (this.hidesOnlinePlayers()) { if (this.hidesOnlinePlayers()) {
return new ServerStatus.Players(i, list.size(), List.of()); return new ServerStatus.Players(i, list.size(), List.of());
} else { } else {
@ -1058,7 +1061,7 @@
ObjectArrayList<GameProfile> objectarraylist = new ObjectArrayList(j); ObjectArrayList<GameProfile> objectarraylist = new ObjectArrayList(j);
int k = Mth.nextInt(this.random, 0, list.size() - j); int k = Mth.nextInt(this.random, 0, list.size() - j);
@@ -1154,24 +1622,58 @@ @@ -1154,24 +1623,58 @@
this.getPlayerList().getPlayers().forEach((entityplayer) -> { this.getPlayerList().getPlayers().forEach((entityplayer) -> {
entityplayer.connection.suspendFlushing(); entityplayer.connection.suspendFlushing();
}); });
@ -1118,7 +1121,7 @@
gameprofilerfiller.push("tick"); gameprofilerfiller.push("tick");
@@ -1186,7 +1688,9 @@ @@ -1186,7 +1689,9 @@
gameprofilerfiller.pop(); gameprofilerfiller.pop();
gameprofilerfiller.pop(); gameprofilerfiller.pop();
@ -1128,7 +1131,7 @@
gameprofilerfiller.popPush("connection"); gameprofilerfiller.popPush("connection");
this.tickConnection(); this.tickConnection();
@@ -1267,6 +1771,22 @@ @@ -1267,6 +1772,22 @@
return (ServerLevel) this.levels.get(key); return (ServerLevel) this.levels.get(key);
} }
@ -1151,7 +1154,7 @@
public Set<ResourceKey<Level>> levelKeys() { public Set<ResourceKey<Level>> levelKeys() {
return this.levels.keySet(); return this.levels.keySet();
} }
@@ -1296,7 +1816,7 @@ @@ -1296,7 +1817,7 @@
@DontObfuscate @DontObfuscate
public String getServerModName() { public String getServerModName() {
@ -1160,7 +1163,7 @@
} }
public SystemReport fillSystemReport(SystemReport details) { public SystemReport fillSystemReport(SystemReport details) {
@@ -1347,7 +1867,7 @@ @@ -1347,7 +1868,7 @@
@Override @Override
public void sendSystemMessage(Component message) { public void sendSystemMessage(Component message) {
@ -1169,7 +1172,7 @@
} }
public KeyPair getKeyPair() { public KeyPair getKeyPair() {
@@ -1385,11 +1905,14 @@ @@ -1385,11 +1906,14 @@
} }
} }
@ -1189,7 +1192,7 @@
} }
} }
@@ -1403,7 +1926,7 @@ @@ -1403,7 +1927,7 @@
while (iterator.hasNext()) { while (iterator.hasNext()) {
ServerLevel worldserver = (ServerLevel) iterator.next(); ServerLevel worldserver = (ServerLevel) iterator.next();
@ -1198,7 +1201,7 @@
} }
} }
@@ -1481,10 +2004,20 @@ @@ -1481,10 +2005,20 @@
@Override @Override
public String getMotd() { public String getMotd() {
@ -1220,7 +1223,7 @@
this.motd = motd; this.motd = motd;
} }
@@ -1507,7 +2040,7 @@ @@ -1507,7 +2041,7 @@
} }
public ServerConnectionListener getConnection() { public ServerConnectionListener getConnection() {
@ -1229,7 +1232,7 @@
} }
public boolean isReady() { public boolean isReady() {
@@ -1632,13 +2165,19 @@ @@ -1632,13 +2166,19 @@
return this.functionManager; return this.functionManager;
} }
@ -1251,7 +1254,7 @@
}, this).thenCompose((immutablelist) -> { }, this).thenCompose((immutablelist) -> {
MultiPackResourceManager resourcemanager = new MultiPackResourceManager(PackType.SERVER_DATA, immutablelist); MultiPackResourceManager resourcemanager = new MultiPackResourceManager(PackType.SERVER_DATA, immutablelist);
List<Registry.PendingTags<?>> list = TagLoader.loadTagsForExistingRegistries(resourcemanager, this.registries.compositeAccess()); List<Registry.PendingTags<?>> list = TagLoader.loadTagsForExistingRegistries(resourcemanager, this.registries.compositeAccess());
@@ -1654,17 +2193,21 @@ @@ -1654,17 +2194,21 @@
}).thenAcceptAsync((minecraftserver_reloadableresources) -> { }).thenAcceptAsync((minecraftserver_reloadableresources) -> {
this.resources.close(); this.resources.close();
this.resources = minecraftserver_reloadableresources; this.resources = minecraftserver_reloadableresources;
@ -1273,7 +1276,7 @@
}, this); }, this);
if (this.isSameThread()) { if (this.isSameThread()) {
@@ -1789,14 +2332,15 @@ @@ -1789,14 +2333,15 @@
if (this.isEnforceWhitelist()) { if (this.isEnforceWhitelist()) {
PlayerList playerlist = source.getServer().getPlayerList(); PlayerList playerlist = source.getServer().getPlayerList();
UserWhiteList whitelist = playerlist.getWhiteList(); UserWhiteList whitelist = playerlist.getWhiteList();
@ -1291,7 +1294,7 @@
} }
} }
@@ -1952,7 +2496,7 @@ @@ -1952,7 +2497,7 @@
final List<String> list = Lists.newArrayList(); final List<String> list = Lists.newArrayList();
final GameRules gamerules = this.getGameRules(); final GameRules gamerules = this.getGameRules();
@ -1300,7 +1303,7 @@
@Override @Override
public <T extends GameRules.Value<T>> void visit(GameRules.Key<T> key, GameRules.Type<T> type) { 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))); list.add(String.format(Locale.ROOT, "%s=%s\n", key.getId(), gamerules.getRule(key)));
@@ -2058,7 +2602,7 @@ @@ -2058,7 +2603,7 @@
try { try {
label51: label51:
{ {
@ -1309,7 +1312,7 @@
try { try {
arraylist = Lists.newArrayList(NativeModuleLister.listModules()); arraylist = Lists.newArrayList(NativeModuleLister.listModules());
@@ -2105,9 +2649,24 @@ @@ -2105,9 +2650,24 @@
if (bufferedwriter != null) { if (bufferedwriter != null) {
bufferedwriter.close(); bufferedwriter.close();
} }
@ -1334,7 +1337,7 @@
private ProfilerFiller createProfiler() { private ProfilerFiller createProfiler() {
if (this.willStartRecordingMetrics) { if (this.willStartRecordingMetrics) {
this.metricsRecorder = ActiveMetricsRecorder.createStarted(new ServerMetricsSamplersProvider(Util.timeSource, this.isDedicatedServer()), Util.timeSource, Util.ioPool(), new MetricsPersister("server"), this.onMetricsRecordingStopped, (path) -> { this.metricsRecorder = ActiveMetricsRecorder.createStarted(new ServerMetricsSamplersProvider(Util.timeSource, this.isDedicatedServer()), Util.timeSource, Util.ioPool(), new MetricsPersister("server"), this.onMetricsRecordingStopped, (path) -> {
@@ -2225,18 +2784,24 @@ @@ -2225,18 +2785,24 @@
} }
public void logChatMessage(Component message, ChatType.Bound params, @Nullable String prefix) { public void logChatMessage(Component message, ChatType.Bound params, @Nullable String prefix) {
@ -1363,7 +1366,7 @@
} }
public boolean logIPs() { public boolean logIPs() {
@@ -2379,4 +2944,30 @@ @@ -2379,4 +2945,30 @@
public static record ServerResourcePackInfo(UUID id, String url, String hash, boolean isRequired, @Nullable Component prompt) { public static record ServerResourcePackInfo(UUID id, String url, String hash, boolean isRequired, @Nullable Component prompt) {
} }

View file

@ -0,0 +1,26 @@
package io.papermc.paper.log;
import java.util.logging.LogManager;
public class CustomLogManager extends LogManager {
private static CustomLogManager instance;
public CustomLogManager() {
instance = this;
}
@Override
public void reset() {
// Ignore calls to this method
}
private void superReset() {
super.reset();
}
public static void forceReset() {
if (instance != null) {
instance.superReset();
}
}
}

View file

@ -19,6 +19,12 @@ public class Main {
public static boolean useJline = true; public static boolean useJline = true;
public static boolean useConsole = true; public static boolean useConsole = true;
// Paper start - Reset loggers after shutdown
static {
System.setProperty("java.util.logging.manager", "io.papermc.paper.log.CustomLogManager");
}
// Paper end - Reset loggers after shutdown
public static void main(String[] args) { public static void main(String[] args) {
// Paper start // Paper start
final String warnWhenLegacyFormattingDetected = String.join(".", "net", "kyori", "adventure", "text", "warnWhenLegacyFormattingDetected"); final String warnWhenLegacyFormattingDetected = String.join(".", "net", "kyori", "adventure", "text", "warnWhenLegacyFormattingDetected");