diff --git a/gradle.properties b/gradle.properties index ef7e472..9b9ce46 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx8G org.gradle.daemon=false -my_version=1.3.3.6 +my_version=1.3.3.7 mc_version=1.19.2 forge_version=43.1.32 diff --git a/src/main/java/dev/zontreck/otemod/OTEMod.java b/src/main/java/dev/zontreck/otemod/OTEMod.java index 62ca946..60f8aef 100644 --- a/src/main/java/dev/zontreck/otemod/OTEMod.java +++ b/src/main/java/dev/zontreck/otemod/OTEMod.java @@ -79,7 +79,7 @@ public class OTEMod public static Map PROFILES = new HashMap(); public static List TeleportRegistry = new ArrayList<>(); public static MinecraftServer THE_SERVER; - private static boolean ALIVE; + public static boolean ALIVE; public static boolean DEVELOPER=false; private static Thread MasterThread; diff --git a/src/main/java/dev/zontreck/otemod/database/Database.java b/src/main/java/dev/zontreck/otemod/database/Database.java index ab061fe..e277b9f 100644 --- a/src/main/java/dev/zontreck/otemod/database/Database.java +++ b/src/main/java/dev/zontreck/otemod/database/Database.java @@ -12,7 +12,7 @@ public class Database { private Connection connection; - public Database (OTEMod instance) throws DatabaseConnectionException + public Database (OTEMod instance) throws DatabaseConnectionException, SQLException { mod=instance; try{ @@ -20,6 +20,48 @@ public class Database { }catch(Exception e){ throw new DatabaseConnectionException(e.getMessage()); } + + Thread tx = new Thread(new Runnable(){ + public void run() + { + while(true){ + + // Watch the connection for disconnections + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + if(!OTEMod.ALIVE)return;// Exit now. We are being torn down/server is going down + try { + if(!OTEMod.DB.isConnected()) + { + OTEMod.LOGGER.info("/!\\ Lost connection to data provider. Reconnecting..."); + // Refresh + try { + OTEMod.DB.connect(); + + if(OTEMod.DB.isConnected()) + { + OTEMod.LOGGER.info("/!\\ Reconnected!"); + } + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + }); + + if(isConnected()){ + tx.start(); + } } public void connect() throws Exception diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index b089198..c670511 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -19,7 +19,7 @@ modId="otemod" #mandatory # The version number of the mod - there's a few well known ${} variables useable here or just hardcode it # ${file.jarVersion} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata # see the associated build.gradle script for how to populate this completely automatically during a build -version="1.3.3.6" #mandatory +version="1.3.3.7" #mandatory # A display name for the mod displayName="OTEMod Resources" #mandatory # A URL to query for updates for this mod. See the JSON update specification https://mcforge.readthedocs.io/en/latest/gettingstarted/autoupdate/