Archiviert
13
0

Save the last update check, even if it was initiated from a command.

Dieser Commit ist enthalten in:
Kristian S. Stangeland 2012-11-04 02:30:47 +01:00
Ursprung 64e3ba7f14
Commit f5dce019df
3 geänderte Dateien mit 30 neuen und 15 gelöschten Zeilen

Datei anzeigen

@ -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!");
}
}

Datei anzeigen

@ -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();
}
}

Datei anzeigen

@ -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