mirror of
https://github.com/TotalFreedomMC/TF-ProjectKorra.git
synced 2025-02-11 03:30:10 +00:00
Fix errors when starting server offline
- Updater would throw NPE and UnknownHostException when it could not connect to projectkorra.com - Also cleaned up output of DB connections
This commit is contained in:
parent
18ab899f27
commit
7cacdf82c2
2 changed files with 28 additions and 19 deletions
|
@ -16,7 +16,7 @@ public class DBConnection {
|
|||
|
||||
public static void init() {
|
||||
if (ProjectKorra.plugin.getConfig().getString("Storage.engine").equalsIgnoreCase("mysql")) {
|
||||
sql = new MySQL(ProjectKorra.log, "[ProjectKorra] Establishing MySQL Connection...", host, port, user, pass, db);
|
||||
sql = new MySQL(ProjectKorra.log, "Establishing MySQL Connection...", host, port, user, pass, db);
|
||||
if (((MySQL) sql).open() == null) {
|
||||
ProjectKorra.log.severe("Disabling due to database error");
|
||||
GeneralMethods.stopPlugin();
|
||||
|
@ -24,7 +24,7 @@ public class DBConnection {
|
|||
}
|
||||
|
||||
isOpen = true;
|
||||
ProjectKorra.log.info("[ProjectKorra] Database connection established.");
|
||||
ProjectKorra.log.info("Database connection established.");
|
||||
|
||||
if (!sql.tableExists("pk_players")) {
|
||||
ProjectKorra.log.info("Creating pk_players table");
|
||||
|
@ -38,7 +38,7 @@ public class DBConnection {
|
|||
sql.modifyQuery(query);
|
||||
}
|
||||
} else {
|
||||
sql = new SQLite(ProjectKorra.log, "[ProjectKorra] Establishing SQLite Connection.", "projectkorra.db", ProjectKorra.plugin.getDataFolder().getAbsolutePath());
|
||||
sql = new SQLite(ProjectKorra.log, "", "projectkorra.db", ProjectKorra.plugin.getDataFolder().getAbsolutePath());
|
||||
if (((SQLite) sql).open() == null) {
|
||||
ProjectKorra.log.severe("Disabling due to database error");
|
||||
GeneralMethods.stopPlugin();
|
||||
|
|
|
@ -1,18 +1,19 @@
|
|||
package com.projectkorra.projectkorra.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
/**
|
||||
* Updater class that takes an rss feed and checks for updates there
|
||||
* <br>
|
||||
|
@ -57,9 +58,11 @@ public class Updater {
|
|||
urlc = url.openConnection();
|
||||
urlc.setRequestProperty("User-Agent", ""); // Must be used or face 403
|
||||
document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(urlc.getInputStream());
|
||||
} catch (UnknownHostException e) {
|
||||
plugin.getLogger().info("Could not connect to ProjectKorra.com to check for updates");
|
||||
} catch (IOException | SAXException | ParserConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
this.currentVersion = plugin.getDescription().getVersion();
|
||||
this.pluginName = plugin.getDescription().getName();
|
||||
}
|
||||
|
@ -70,7 +73,9 @@ public class Updater {
|
|||
*
|
||||
*/
|
||||
public void checkUpdate() {
|
||||
if (updateAvailable()) {
|
||||
if (getUpdateVersion()==null)
|
||||
return;
|
||||
else if (updateAvailable()) {
|
||||
plugin.getLogger().info("===================[Update Available]===================");
|
||||
plugin.getLogger().info("You are running version " + getCurrentVersion());
|
||||
plugin.getLogger().info("The latest version avaliable is " + getUpdateVersion());
|
||||
|
@ -82,14 +87,17 @@ public class Updater {
|
|||
/**
|
||||
* Gets latest plugin version.
|
||||
*
|
||||
* @return Latest plugin version
|
||||
* @return Latest plugin version, or null if it cannot connect
|
||||
*/
|
||||
public String getUpdateVersion() {
|
||||
Node latestFile = document.getElementsByTagName("item").item(0);
|
||||
NodeList children = latestFile.getChildNodes();
|
||||
|
||||
String version = children.item(1).getTextContent();
|
||||
return version;
|
||||
if (document!=null) {
|
||||
Node latestFile = document.getElementsByTagName("item").item(0);
|
||||
NodeList children = latestFile.getChildNodes();
|
||||
|
||||
String version = children.item(1).getTextContent();
|
||||
return version;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -98,7 +106,8 @@ public class Updater {
|
|||
* @return true If there is an update
|
||||
*/
|
||||
public boolean updateAvailable() {
|
||||
if (currentVersion.equalsIgnoreCase(getUpdateVersion())) {
|
||||
String updateVersion = getUpdateVersion();
|
||||
if (updateVersion==null || currentVersion.equalsIgnoreCase(getUpdateVersion())) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
Loading…
Reference in a new issue