Added check for 0 byte downloads.

This commit is contained in:
Robin Kupper
2011-04-07 18:18:22 +02:00
parent ad1850ad03
commit 048f0221dd

View File

@@ -1,6 +1,7 @@
package de.diddiz.LogBlock; package de.diddiz.LogBlock;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException;
import java.net.URL; import java.net.URL;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DatabaseMetaData; import java.sql.DatabaseMetaData;
@@ -60,6 +61,11 @@ public class LogBlock extends JavaPlugin
log = getServer().getLogger(); log = getServer().getLogger();
try { try {
config = new Config(this); config = new Config(this);
} catch (Exception ex) {
log.log(Level.SEVERE, "[LogBlock] Exception while reading config", ex);
getServer().getPluginManager().disablePlugin(this);
return;
}
if (config.usePermissions) { if (config.usePermissions) {
if (getServer().getPluginManager().getPlugin("Permissions") != null) if (getServer().getPluginManager().getPlugin("Permissions") != null)
log.info("[LogBlock] Permissions enabled"); log.info("[LogBlock] Permissions enabled");
@@ -69,15 +75,24 @@ public class LogBlock extends JavaPlugin
} }
} }
File file = new File("lib/mysql-connector-java-bin.jar"); File file = new File("lib/mysql-connector-java-bin.jar");
if (!file.exists()) { try {
log.info("[LogBlock] Downloading mysql-connector-java-bin.jar ..."); if (!file.exists() || file.length() == 0) {
log.info("[LogBlock] Downloading " + file.getName() + "...");
Download.download(new URL("http://diddiz.insane-architects.net/download/mysql-connector-java-bin.jar"), file); Download.download(new URL("http://diddiz.insane-architects.net/download/mysql-connector-java-bin.jar"), file);
} }
if (!file.exists() || file.length() == 0)
throw new FileNotFoundException(file.getAbsolutePath() + file.getName());
} catch (Exception e) {
log.log(Level.SEVERE, "[LogBlock] Error while downloading " + file.getName() + ".");
getServer().getPluginManager().disablePlugin(this);
return;
}
try {
new JDCConnectionDriver(config.dbDriver, config.dbUrl, config.dbUsername, config.dbPassword); new JDCConnectionDriver(config.dbDriver, config.dbUrl, config.dbUsername, config.dbPassword);
Connection conn = getConnection(); Connection conn = getConnection();
conn.close(); conn.close();
} catch (Exception ex) { } catch (Exception ex) {
log.log(Level.SEVERE, "[LogBlock] Exception while enabling", ex); log.log(Level.SEVERE, "[LogBlock] Exception while cheching database connection", ex);
getServer().getPluginManager().disablePlugin(this); getServer().getPluginManager().disablePlugin(this);
return; return;
} }