forked from LogBlock/LogBlock
Added version check
This commit is contained in:
@@ -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();
|
||||
|
@@ -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;
|
||||
|
@@ -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";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user