From f5dce019dff5523ef8e1e424df9ba8f3bddd9c1c Mon Sep 17 00:00:00 2001 From: "Kristian S. Stangeland" Date: Sun, 4 Nov 2012 02:30:47 +0100 Subject: [PATCH] Save the last update check, even if it was initiated from a command. --- .../comphenix/protocol/CommandProtocol.java | 22 +++++++++++++++---- .../comphenix/protocol/ProtocolLibrary.java | 12 +++++----- .../comphenix/protocol/metrics/Updater.java | 11 ++++++---- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/CommandProtocol.java b/ProtocolLib/src/main/java/com/comphenix/protocol/CommandProtocol.java index 9f5a0eb0..7039907a 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/CommandProtocol.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/CommandProtocol.java @@ -21,11 +21,13 @@ class CommandProtocol extends CommandBase { private Plugin plugin; private Updater updater; + private ProtocolConfig config; - public CommandProtocol(Plugin plugin, Updater updater) { + public CommandProtocol(Plugin plugin, Updater updater, ProtocolConfig config) { super(CommandBase.PERMISSION_ADMIN, NAME, 1); this.plugin = plugin; this.updater = updater; + this.config = config; } @Override @@ -50,9 +52,11 @@ class CommandProtocol extends CommandBase { @Override public void run() { UpdateResult result = updater.update(UpdateType.NO_DOWNLOAD, true); - sender.sendMessage(ChatColor.DARK_BLUE + "Version check: " + result.toString()); + sender.sendMessage(ChatColor.BLUE + "Version check: " + result.toString()); } }); + + updateFinished(); } public void updateVersion(final CommandSender sender) { @@ -61,14 +65,24 @@ class CommandProtocol extends CommandBase { @Override public void run() { UpdateResult result = updater.update(UpdateType.DEFAULT, true); - sender.sendMessage(ChatColor.DARK_BLUE + "Update: " + result.toString()); + sender.sendMessage(ChatColor.BLUE + "Update: " + result.toString()); } }); + + updateFinished(); + } + + /** + * Prevent further automatic updates until the next delay. + */ + public void updateFinished() { + config.setAutoLastTime(System.currentTimeMillis()); + config.saveAll(); } public void reloadConfiguration(CommandSender sender) { plugin.saveConfig(); plugin.reloadConfig(); - sender.sendMessage(ChatColor.DARK_BLUE + "Reloaded configuration!"); + sender.sendMessage(ChatColor.BLUE + "Reloaded configuration!"); } } diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java b/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java index 6547a959..c74a6858 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java @@ -105,7 +105,7 @@ public class ProtocolLibrary extends JavaPlugin { reporter.addGlobalParameter("manager", protocolManager); // Initialize command handlers - commandProtocol = new CommandProtocol(this, updater); + commandProtocol = new CommandProtocol(this, updater, config); commandPacket = new CommandPacket(this, logger, reporter, protocolManager); // Send logging information to player listeners too @@ -237,16 +237,14 @@ public class ProtocolLibrary extends JavaPlugin { long currentTime = System.currentTimeMillis() / MILLI_PER_SECOND; // Should we update? - if (currentTime < config.getAutoLastTime() + config.getAutoDelay()) { - // Great. Save this check. - config.setAutoLastTime(currentTime); - config.saveAll(); - - // Initiate the update from the console + if (currentTime < config.getAutoLastTime() + config.getAutoDelay()) { + // Initiate the update as if it came from the console if (config.isAutoDownload()) commandProtocol.updateVersion(getServer().getConsoleSender()); else if (config.isAutoNotify()) commandProtocol.checkVersion(getServer().getConsoleSender()); + else + commandProtocol.updateFinished(); } } diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/metrics/Updater.java b/ProtocolLib/src/main/java/com/comphenix/protocol/metrics/Updater.java index dee8708e..eaea4a7b 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/metrics/Updater.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/metrics/Updater.java @@ -547,11 +547,13 @@ public class Updater { if (type != UpdateType.NO_VERSION_CHECK) { + String[] parts = title.split(" "); String version = plugin.getDescription().getVersion(); - if(title.split("v").length == 2) + + if(parts.length == 2) { - String remoteVersion = title.split("v")[1].split(" ")[0]; // Get the newest file's version number - int remVer = -1,curVer=0; + String remoteVersion = parts[1].split(" ")[0]; // Get the newest file's version number + int remVer = -1, curVer=0; try { remVer = calVer(remoteVersion); @@ -559,8 +561,9 @@ public class Updater } catch(NumberFormatException nfe) { - remVer=-1; + remVer=-1; } + if(hasTag(version)||version.equalsIgnoreCase(remoteVersion)||curVer>=remVer) { // We already have the latest version, or this build is tagged for no-update