From c99e77d53479102e4149dbbd1b5788a15e3ecf94 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Mon, 23 Sep 2013 16:43:21 -0500 Subject: [PATCH] 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. By: Wesley Wolfe --- .../java/org/bukkit/craftbukkit/CraftServer.java | 15 +++++++++++++++ .../java/org/bukkit/craftbukkit/CraftWorld.java | 1 + 2 files changed, 16 insertions(+) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java index df2efe2c3e..85be77ebec 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -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); + } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 8c9504af19..9f75d8e682 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -641,6 +641,7 @@ public class CraftWorld implements World { } public void save() { + this.server.checkSaveState(); try { boolean oldSave = world.savingDisabled;