Update Updater, fix newline issue on event chain disabling

This commit is contained in:
h31ix committed 2013-01-16 17:18:42 -05:00
1 parent a7895f9414
commit d4384ac550
2 files changed
+23 -3

No files matched your search

@@ -122,7 +122,7 @@ public class AnticheatManager {
public String getEventChainReport() { public String getEventChainReport() {
String gen = ""; String gen = "";
if (!configuration.eventChains()) if (!configuration.eventChains())
return "Event Chains is disabled by the configuration."; return "Event Chains is disabled by the configuration.\n";
for (Entry<String, RegisteredListener[]> e : eventchains.entrySet()) { for (Entry<String, RegisteredListener[]> e : eventchains.entrySet()) {
String toadd = ""; String toadd = "";
@@ -7,7 +7,9 @@
package net.h31ix.anticheat.update; package net.h31ix.anticheat.update;
import java.io.*; import java.io.*;
import java.lang.IllegalThreadStateException;
import java.lang.Runnable; import java.lang.Runnable;
import java.lang.Thread;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
@@ -50,12 +52,12 @@ public class Updater
private boolean announce; // Whether to announce file downloads private boolean announce; // Whether to announce file downloads
private URL url; // Connecting to RSS private URL url; // Connecting to RSS
private File file; // The plugin's file 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 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 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 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 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 private Updater.UpdateResult result = Updater.UpdateResult.SUCCESS; // Used for determining the outcome of the update process
// Strings for reading RSS // Strings for reading RSS
private static final String TITLE = "title"; private static final String TITLE = "title";
private static final String LINK = "link"; 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."); plugin.getLogger().warning("The project slug given ('" + slug + "') is invalid. Please nag the author about this.");
result = Updater.UpdateResult.FAIL_BADSLUG; // Bad slug! Bad! 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() public Updater.UpdateResult getResult()
{ {
waitForThread();
return result; return result;
} }
@@ -163,6 +167,7 @@ public class Updater
*/ */
public long getFileSize() public long getFileSize()
{ {
waitForThread();
return totalSize; return totalSize;
} }
@@ -171,9 +176,24 @@ public class Updater
*/ */
public String getLatestVersionString() public String getLatestVersionString()
{ {
waitForThread();
return versionTitle; 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. * Save an update from dev.bukkit.org into the server's update folder.
*/ */