diff --git a/src/de/diddiz/LogBlock/CommandsHandler.java b/src/de/diddiz/LogBlock/CommandsHandler.java index 9860149..0a77e91 100644 --- a/src/de/diddiz/LogBlock/CommandsHandler.java +++ b/src/de/diddiz/LogBlock/CommandsHandler.java @@ -50,6 +50,7 @@ public class CommandsHandler implements CommandExecutor return false; if (args.length == 0) { sender.sendMessage(ChatColor.LIGHT_PURPLE + "LogBlock v" + logblock.getDescription().getVersion() + " by DiddiZ"); + sender.sendMessage(ChatColor.LIGHT_PURPLE + logblock.getUpdater().checkVersion()); sender.sendMessage(ChatColor.LIGHT_PURPLE + "Type /lb help for help"); } else { final String command = args[0].toLowerCase(); diff --git a/src/de/diddiz/LogBlock/LogBlock.java b/src/de/diddiz/LogBlock/LogBlock.java index 7c09770..e78e637 100644 --- a/src/de/diddiz/LogBlock/LogBlock.java +++ b/src/de/diddiz/LogBlock/LogBlock.java @@ -33,6 +33,7 @@ public class LogBlock extends JavaPlugin private MySQLConnectionPool pool; private Consumer consumer = null; private CommandsHandler commandsHandler; + private Updater updater = null; private Timer timer = null; private PermissionHandler permissions = null; private boolean errorAtLoading = false; @@ -50,16 +51,22 @@ public class LogBlock extends JavaPlugin return commandsHandler; } + Updater getUpdater() { + return updater; + } + @Override public void onLoad() { log = getServer().getLogger(); try { + updater = new Updater(this); + log.info("[LogBlock] Version check: " + updater.checkVersion()); config = new Config(this); downloadIfNotExists(log, new File("lib/mysql-connector-java-bin.jar"), new URL("http://diddiz.insane-architects.net/download/mysql-connector-java-bin.jar")); log.info("[LogBlock] Connecting to " + config.user + "@" + config.url + "..."); pool = new MySQLConnectionPool(config.url, config.user, config.password); getConnection().close(); - new Updater(this).checkTables(); + updater.checkTables(); } catch (final Exception ex) { log.log(Level.SEVERE, "[LogBlock] Error while loading: ", ex); errorAtLoading = true; diff --git a/src/de/diddiz/LogBlock/Updater.java b/src/de/diddiz/LogBlock/Updater.java index 02243e1..3e64ee9 100644 --- a/src/de/diddiz/LogBlock/Updater.java +++ b/src/de/diddiz/LogBlock/Updater.java @@ -1,5 +1,7 @@ package de.diddiz.LogBlock; +import static de.diddiz.util.Utils.readURL; +import java.net.URL; import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.SQLException; @@ -61,4 +63,12 @@ class Updater state.close(); conn.close(); } + + String checkVersion() { + try { + return readURL(new URL("http://diddiz.insane-architects.net/lbuptodate.php?v=" + logblock.getDescription().getVersion())); + } catch (final Exception ex) { + return "Can't connect to server"; + } + } } diff --git a/src/de/diddiz/util/Utils.java b/src/de/diddiz/util/Utils.java index 98e2180..dfbc957 100644 --- a/src/de/diddiz/util/Utils.java +++ b/src/de/diddiz/util/Utils.java @@ -1,11 +1,13 @@ package de.diddiz.util; import java.io.BufferedOutputStream; +import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; import java.io.OutputStream; import java.net.URL; import java.text.ParseException; @@ -47,6 +49,16 @@ public class Utils throw new FileNotFoundException(file.getAbsolutePath() + file.getName()); } + public static String readURL(URL url) throws IOException { + final StringBuilder content = new StringBuilder(); + final BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); + String inputLine; + while ((inputLine = in.readLine()) != null) + content.append(inputLine); + in.close(); + return content.toString(); + } + public static boolean isInt(String str) { try { Integer.parseInt(str);