Skip to content
This repository has been archived by the owner on Jul 27, 2019. It is now read-only.

Commit

Permalink
Update checker is now optional.
Browse files Browse the repository at this point in the history
  • Loading branch information
cnaude committed Dec 23, 2014
1 parent 952a218 commit 2530da7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 21 deletions.
6 changes: 6 additions & 0 deletions src/main/java/com/cnaude/purpleirc/PurpleIRC.java
Expand Up @@ -147,6 +147,7 @@ public class PurpleIRC extends JavaPlugin {
+ ChatColor.WHITE + "%CHANNEL%";
public final String noPermission = ChatColor.RED + "You do not have permission to use this command.";

private boolean updateCheckerEnabled;
private boolean debugEnabled;
private boolean stripGameColors;
private boolean stripIRCColors;
Expand Down Expand Up @@ -646,6 +647,7 @@ private void loadConfig() {
} catch (IOException | InvalidConfigurationException ex) {
logError(ex.getMessage());
}
updateCheckerEnabled = getConfig().getBoolean("update-checker", true);
debugEnabled = getConfig().getBoolean("Debug");
identServerEnabled = getConfig().getBoolean("enable-ident-server");
logDebug("Debug enabled");
Expand Down Expand Up @@ -1413,5 +1415,9 @@ public String botify(String bot) {
return bot + ".yml";
}
}

public boolean isUpdateCheckerEnabled() {
return updateCheckerEnabled;
}

}
43 changes: 22 additions & 21 deletions src/main/java/com/cnaude/purpleirc/Utilities/UpdateChecker.java
Expand Up @@ -36,40 +36,41 @@ public class UpdateChecker {
PurpleIRC plugin;

private BukkitTask bt;
private int newVersion = 0;
private int currentVersion = 0;
private String currentVersionTitle = "";
private String newVersionTitle = "";
private int newBuild = 0;
private int currentBuild = 0;
private String currentVersion = "";
private String newVersion = "";

/**
*
* @param plugin
*/
public UpdateChecker(PurpleIRC plugin) {
this.plugin = plugin;
currentVersionTitle = plugin.getDescription().getVersion();
currentVersion = plugin.getDescription().getVersion();
try {
currentVersion = Integer.valueOf(currentVersionTitle.split("-")[1]);
currentBuild = Integer.valueOf(currentVersion.split("-")[1]);
} catch (NumberFormatException e) {
currentVersion = 0;
currentBuild = 0;
}
startUpdateChecker();
}

private void startUpdateChecker() {
plugin.logDebug("Starting update checker");
bt = this.plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() {
@Override
public void run() {
plugin.logInfo("Checking for Updates ... ");
newVersion = updateCheck(currentVersion);
if (newVersion > currentVersion) {
plugin.logInfo("Stable Version: " + newVersionTitle + " is out!" + " You are still running version: " + currentVersionTitle);
plugin.logInfo("Update at: http://dev.bukkit.org/server-mods/purpleirc");
} else if (currentVersion > newVersion) {
plugin.logInfo("Stable Version: " + newVersionTitle + " | Current Version: " + currentVersionTitle);
} else {
plugin.logInfo("No new version available");
if (plugin.isUpdateCheckerEnabled()) {
plugin.logInfo("Checking for updates ... ");
newBuild = updateCheck(currentBuild);
if (newBuild > currentBuild) {
plugin.logInfo("Stable version: " + newVersion + " is out!" + " You are still running version: " + currentVersion);
plugin.logInfo("Update at: http://dev.bukkit.org/server-mods/purpleirc");
} else if (currentBuild > newBuild) {
plugin.logInfo("Stable version: " + newVersion + " | Current Version: " + currentVersion);
} else {
plugin.logInfo("No new version available");
}
}
}
}, 0, 432000);
Expand All @@ -89,13 +90,13 @@ public int updateCheck(int currentVersion) {
plugin.logInfo("No files found, or Feed URL is bad.");
return currentVersion;
}
newVersionTitle = ((String) ((JSONObject) array.get(array.size() - 1)).get("name")).trim();
plugin.logDebug("newVersionTitle: " + newVersionTitle);
int t = Integer.valueOf(newVersionTitle.split("-")[1]);
newVersion = ((String) ((JSONObject) array.get(array.size() - 1)).get("name")).trim();
plugin.logDebug("newVersionTitle: " + newVersion);
int t = Integer.valueOf(newVersion.split("-")[1]);
plugin.logDebug("t: " + t);
return t;
} catch (IOException | NumberFormatException e) {
plugin.logInfo("There was an issue attempting to check for the latest version: " + e.getMessage());
plugin.logInfo("Error checking for latest version: " + e.getMessage());
}
return currentVersion;
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/config.yml
@@ -1,5 +1,7 @@
# Global configuration for PurpleIRC
# NOTE: If you make changes to this file while the server is running use "/irc reloadconfig" to load the changes into memory.
# Check for updates
update-checker: true
# How often we check to see if a bot is connected to the IRC server. This is in server ticks (There 20 ticks in one sec).
conn-check-interval: 1000
# Startup an ident server
Expand Down

0 comments on commit 2530da7

Please sign in to comment.