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