From bd1389895b2959eec6f0509c265dbecbfb549b64 Mon Sep 17 00:00:00 2001 From: Wesley Wolfe 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. --- .../net/minecraft/server/PlayerConnection.java | 11 ++++++++++- .../java/org/bukkit/craftbukkit/CraftServer.java | 15 +++++++++++++++ .../java/org/bukkit/craftbukkit/CraftWorld.java | 1 + 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java index a5d7500a07..e4cb5c7667 100644 --- a/src/main/java/net/minecraft/server/PlayerConnection.java +++ b/src/main/java/net/minecraft/server/PlayerConnection.java @@ -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 diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index df2efe2c3e..85be77ebec 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/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/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 8c9504af19..9f75d8e682 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/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;