1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-12-01 23:13:48 +01:00

Plugin needs to be disabled in case we can't connect to database

This commit is contained in:
Zrips 2022-02-07 15:28:23 +02:00
parent 5f57d4aa95
commit 68b74bfa1b
4 changed files with 30 additions and 5 deletions

View File

@ -76,6 +76,7 @@ import com.gamingmesh.jobs.container.JobInfo;
import com.gamingmesh.jobs.container.JobProgression; import com.gamingmesh.jobs.container.JobProgression;
import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.container.JobsPlayer;
import com.gamingmesh.jobs.container.JobsWorld; import com.gamingmesh.jobs.container.JobsWorld;
import com.gamingmesh.jobs.container.LoadStatus;
import com.gamingmesh.jobs.container.Log; import com.gamingmesh.jobs.container.Log;
import com.gamingmesh.jobs.container.PlayerInfo; import com.gamingmesh.jobs.container.PlayerInfo;
import com.gamingmesh.jobs.container.PlayerPoints; import com.gamingmesh.jobs.container.PlayerPoints;
@ -162,6 +163,8 @@ public final class Jobs extends JavaPlugin {
public static BufferedPaymentThread paymentThread; public static BufferedPaymentThread paymentThread;
private static DatabaseSaveThread saveTask; private static DatabaseSaveThread saveTask;
public static LoadStatus status = LoadStatus.Good;
private static final int MAX_ENTRIES = 5; private static final int MAX_ENTRIES = 5;
public static final LinkedHashMap<UUID, FastPayment> FASTPAYMENT = new LinkedHashMap<UUID, FastPayment>(MAX_ENTRIES + 1, .75F, false) { public static final LinkedHashMap<UUID, FastPayment> FASTPAYMENT = new LinkedHashMap<UUID, FastPayment>(MAX_ENTRIES + 1, .75F, false) {
protected boolean removeEldestEntry(Map.Entry<UUID, FastPayment> eldest) { protected boolean removeEldestEntry(Map.Entry<UUID, FastPayment> eldest) {
@ -729,6 +732,14 @@ public final class Jobs extends JavaPlugin {
startup(); startup();
if (status.equals(LoadStatus.MYSQLFailure) || status.equals(LoadStatus.SQLITEFailure)) {
CMIMessages.consoleMessage("&cCould not connect to " + (status.equals(LoadStatus.MYSQLFailure) ? "MySQL" : "SqLite") + "!");
CMIMessages.consoleMessage("&cPlugin will be disabled");
this.onDisable();
this.setEnabled(false);
return;
}
if (getGCManager().SignsEnabled) { if (getGCManager().SignsEnabled) {
new YmlMaker(getFolder(), "Signs.yml").saveDefaultConfig(); new YmlMaker(getFolder(), "Signs.yml").saveDefaultConfig();
} }

View File

@ -0,0 +1,5 @@
package com.gamingmesh.jobs.container;
public enum LoadStatus {
MYSQLFailure, SQLITEFailure, Good;
}

View File

@ -478,10 +478,10 @@ public abstract class JobsDAO {
} }
} }
public final synchronized void setUp() { public final synchronized boolean setUp() {
if (getConnection() == null) { if (getConnection() == null) {
CMIMessages.consoleMessage("&cFAILED to connect to database"); CMIMessages.consoleMessage("&cFAILED to connect to database");
return; return false;
} }
CMIMessages.consoleMessage("&eConnected to database (&6" + dbType + "&e)"); CMIMessages.consoleMessage("&eConnected to database (&6" + dbType + "&e)");
@ -492,10 +492,10 @@ public abstract class JobsDAO {
for (DBTables one : DBTables.values()) { for (DBTables one : DBTables.values()) {
createDefaultTable(one); createDefaultTable(one);
} }
checkDefaultCollumns(); checkDefaultCollumns();
} finally { } finally {
} }
return true;
} }
protected abstract void checkUpdate() throws SQLException; protected abstract void checkUpdate() throws SQLException;

View File

@ -3,8 +3,10 @@ package com.gamingmesh.jobs.dao;
import java.io.IOException; import java.io.IOException;
import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.container.LoadStatus;
import net.Zrips.CMILib.FileHandler.ConfigReader; import net.Zrips.CMILib.FileHandler.ConfigReader;
import net.Zrips.CMILib.Logs.CMIDebug;
public class JobsManager { public class JobsManager {
private JobsDAO dao; private JobsDAO dao;
@ -86,6 +88,9 @@ public class JobsManager {
if (storageMethod.equalsIgnoreCase("mysql")) { if (storageMethod.equalsIgnoreCase("mysql")) {
dbType = DataBaseType.MySQL; dbType = DataBaseType.MySQL;
dao = startMysql(); dao = startMysql();
if (dao == null || dao.getConnection() == null) {
Jobs.status = LoadStatus.MYSQLFailure;
}
} else { } else {
if (!storageMethod.equalsIgnoreCase("sqlite")) { if (!storageMethod.equalsIgnoreCase("sqlite")) {
Jobs.consoleMsg("&cInvalid storage method! Changing method to sqlite!"); Jobs.consoleMsg("&cInvalid storage method! Changing method to sqlite!");
@ -94,6 +99,10 @@ public class JobsManager {
dbType = DataBaseType.SqLite; dbType = DataBaseType.SqLite;
dao = startSqlite(); dao = startSqlite();
if (dao.getConnection() == null) {
Jobs.status = LoadStatus.SQLITEFailure;
}
} }
Jobs.setDAO(dao); Jobs.setDAO(dao);