Added version check

This commit is contained in:
Robin Kupper
2011-06-11 16:14:13 +02:00
parent ad7910ab7e
commit 9aa4657e5f
4 changed files with 31 additions and 1 deletions

View File

@@ -50,6 +50,7 @@ public class CommandsHandler implements CommandExecutor
return false; return false;
if (args.length == 0) { if (args.length == 0) {
sender.sendMessage(ChatColor.LIGHT_PURPLE + "LogBlock v" + logblock.getDescription().getVersion() + " by DiddiZ"); 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"); sender.sendMessage(ChatColor.LIGHT_PURPLE + "Type /lb help for help");
} else { } else {
final String command = args[0].toLowerCase(); final String command = args[0].toLowerCase();

View File

@@ -33,6 +33,7 @@ public class LogBlock extends JavaPlugin
private MySQLConnectionPool pool; private MySQLConnectionPool pool;
private Consumer consumer = null; private Consumer consumer = null;
private CommandsHandler commandsHandler; private CommandsHandler commandsHandler;
private Updater updater = null;
private Timer timer = null; private Timer timer = null;
private PermissionHandler permissions = null; private PermissionHandler permissions = null;
private boolean errorAtLoading = false; private boolean errorAtLoading = false;
@@ -50,16 +51,22 @@ public class LogBlock extends JavaPlugin
return commandsHandler; return commandsHandler;
} }
Updater getUpdater() {
return updater;
}
@Override @Override
public void onLoad() { public void onLoad() {
log = getServer().getLogger(); log = getServer().getLogger();
try { try {
updater = new Updater(this);
log.info("[LogBlock] Version check: " + updater.checkVersion());
config = new Config(this); 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")); 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 + "..."); log.info("[LogBlock] Connecting to " + config.user + "@" + config.url + "...");
pool = new MySQLConnectionPool(config.url, config.user, config.password); pool = new MySQLConnectionPool(config.url, config.user, config.password);
getConnection().close(); getConnection().close();
new Updater(this).checkTables(); updater.checkTables();
} catch (final Exception ex) { } catch (final Exception ex) {
log.log(Level.SEVERE, "[LogBlock] Error while loading: ", ex); log.log(Level.SEVERE, "[LogBlock] Error while loading: ", ex);
errorAtLoading = true; errorAtLoading = true;

View File

@@ -1,5 +1,7 @@
package de.diddiz.LogBlock; package de.diddiz.LogBlock;
import static de.diddiz.util.Utils.readURL;
import java.net.URL;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DatabaseMetaData; import java.sql.DatabaseMetaData;
import java.sql.SQLException; import java.sql.SQLException;
@@ -61,4 +63,12 @@ class Updater
state.close(); state.close();
conn.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";
}
}
} }

View File

@@ -1,11 +1,13 @@
package de.diddiz.util; package de.diddiz.util;
import java.io.BufferedOutputStream; import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.URL; import java.net.URL;
import java.text.ParseException; import java.text.ParseException;
@@ -47,6 +49,16 @@ public class Utils
throw new FileNotFoundException(file.getAbsolutePath() + file.getName()); 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) { public static boolean isInt(String str) {
try { try {
Integer.parseInt(str); Integer.parseInt(str);