Add auto-save plugin redundancy detection.

This change will print a warning when a plugin induces a forced save. A
player or console forcing a save (via a command) is ignored for purposes
of printing a warning.
This commit is contained in:
Wesley Wolfe 2013-09-23 16:43:21 -05:00 committed by EvilSeph
parent de16ba6eec
commit bd1389895b
3 changed files with 26 additions and 1 deletions

View File

@ -831,7 +831,16 @@ public class PlayerConnection extends Connection {
return;
}
this.chat(s, packet3chat.a_());
if (!packet3chat.a_()) {
try {
this.minecraftServer.server.playerCommandState = true;
this.chat(s, packet3chat.a_());
} finally {
this.minecraftServer.server.playerCommandState = false;
}
} else {
this.chat(s, packet3chat.a_());
}
// This section stays because it is only applicable to packets
if (chatSpamField.addAndGet(this, 20) > 200 && !this.minecraftServer.getPlayerList().isOp(this.player.getName())) { // CraftBukkit use thread-safe spam

View File

@ -162,6 +162,8 @@ public final class CraftServer implements Server {
private WarningState warningState = WarningState.DEFAULT;
private final BooleanWrapper online = new BooleanWrapper();
public CraftScoreboardManager scoreboardManager;
public boolean playerCommandState;
private boolean printSaveWarning;
private final class BooleanWrapper {
private boolean value = true;
@ -509,10 +511,13 @@ public final class CraftServer implements Server {
}
}
try {
this.playerCommandState = true;
return dispatchCommand(sender, serverCommand.command);
} catch (Exception ex) {
getLogger().log(Level.WARNING, "Unexpected exception while parsing console command \"" + serverCommand.command + '"', ex);
return false;
} finally {
this.playerCommandState = false;
}
}
@ -553,6 +558,7 @@ public final class CraftServer implements Server {
waterAnimalSpawn = configuration.getInt("spawn-limits.water-animals");
ambientSpawn = configuration.getInt("spawn-limits.ambient");
warningState = WarningState.value(configuration.getString("settings.deprecated-verbose"));
printSaveWarning = false;
console.autosavePeriod = configuration.getInt("ticks-per.autosave");
chunkGCPeriod = configuration.getInt("chunk-gc.period-in-ticks");
chunkGCLoadThresh = configuration.getInt("chunk-gc.load-threshold");
@ -862,6 +868,7 @@ public final class CraftServer implements Server {
}
public void savePlayers() {
checkSaveState();
playerList.savePlayers();
}
@ -1374,4 +1381,12 @@ public final class CraftServer implements Server {
public CraftScoreboardManager getScoreboardManager() {
return scoreboardManager;
}
public void checkSaveState() {
if (this.playerCommandState || this.printSaveWarning || this.console.autosavePeriod <= 0) {
return;
}
this.printSaveWarning = true;
getLogger().log(Level.WARNING, "A manual (plugin-induced) save has been detected while server is configured to auto-save. This may affect performance.", warningState == WarningState.ON ? new Throwable() : null);
}
}

View File

@ -641,6 +641,7 @@ public class CraftWorld implements World {
}
public void save() {
this.server.checkSaveState();
try {
boolean oldSave = world.savingDisabled;