From d4384ac55070fa63c03e78c0120bd595c2b51204 Mon Sep 17 00:00:00 2001 From: h31ix Date: Wed, 16 Jan 2013 17:18:42 -0500 Subject: [PATCH] Update Updater, fix newline issue on event chain disabling --- .../anticheat/manage/AnticheatManager.java | 2 +- .../net/h31ix/anticheat/update/Updater.java | 24 +++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/h31ix/anticheat/manage/AnticheatManager.java b/src/main/java/net/h31ix/anticheat/manage/AnticheatManager.java index 68c43b8..d62ab02 100644 --- a/src/main/java/net/h31ix/anticheat/manage/AnticheatManager.java +++ b/src/main/java/net/h31ix/anticheat/manage/AnticheatManager.java @@ -122,7 +122,7 @@ public class AnticheatManager { public String getEventChainReport() { String gen = ""; if (!configuration.eventChains()) - return "Event Chains is disabled by the configuration."; + return "Event Chains is disabled by the configuration.\n"; for (Entry e : eventchains.entrySet()) { String toadd = ""; diff --git a/src/main/java/net/h31ix/anticheat/update/Updater.java b/src/main/java/net/h31ix/anticheat/update/Updater.java index 9195176..17fa6af 100644 --- a/src/main/java/net/h31ix/anticheat/update/Updater.java +++ b/src/main/java/net/h31ix/anticheat/update/Updater.java @@ -7,7 +7,9 @@ package net.h31ix.anticheat.update; import java.io.*; +import java.lang.IllegalThreadStateException; import java.lang.Runnable; +import java.lang.Thread; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; @@ -50,12 +52,12 @@ public class Updater private boolean announce; // Whether to announce file downloads private URL url; // Connecting to RSS private File file; // The plugin's file + private Thread thread; // Updater thread private static final String DBOUrl = "http://dev.bukkit.org/server-mods/"; // Slugs will be appended to this to get to the project's RSS feed private String [] noUpdateTag = {"-DEV","-PRE"}; // If the version number contains one of these, don't update. private static final int BYTE_SIZE = 1024; // Used for downloading files private String updateFolder = YamlConfiguration.loadConfiguration(new File("bukkit.yml")).getString("settings.update-folder"); // The folder that downloads will be placed in private Updater.UpdateResult result = Updater.UpdateResult.SUCCESS; // Used for determining the outcome of the update process - // Strings for reading RSS private static final String TITLE = "title"; private static final String LINK = "link"; @@ -147,7 +149,8 @@ public class Updater plugin.getLogger().warning("The project slug given ('" + slug + "') is invalid. Please nag the author about this."); result = Updater.UpdateResult.FAIL_BADSLUG; // Bad slug! Bad! } - new Thread(new UpdateRunnable()).start(); + thread = new Thread(new UpdateRunnable()); + thread.start(); } /** @@ -155,6 +158,7 @@ public class Updater */ public Updater.UpdateResult getResult() { + waitForThread(); return result; } @@ -163,6 +167,7 @@ public class Updater */ public long getFileSize() { + waitForThread(); return totalSize; } @@ -171,9 +176,24 @@ public class Updater */ public String getLatestVersionString() { + waitForThread(); return versionTitle; } + /** + * As the result of Updater output depends on the thread's completion, it is necessary to wait for the thread to finish + * before alloowing anyone to check the result. + */ + public void waitForThread() { + if(thread.isAlive()) { + try { + thread.join(); + } catch (InterruptedException e) { + e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. + } + } + } + /** * Save an update from dev.bukkit.org into the server's update folder. */