1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-12-01 15:03:36 +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.JobsPlayer;
import com.gamingmesh.jobs.container.JobsWorld;
import com.gamingmesh.jobs.container.LoadStatus;
import com.gamingmesh.jobs.container.Log;
import com.gamingmesh.jobs.container.PlayerInfo;
import com.gamingmesh.jobs.container.PlayerPoints;
@ -162,6 +163,8 @@ public final class Jobs extends JavaPlugin {
public static BufferedPaymentThread paymentThread;
private static DatabaseSaveThread saveTask;
public static LoadStatus status = LoadStatus.Good;
private static final int MAX_ENTRIES = 5;
public static final LinkedHashMap<UUID, FastPayment> FASTPAYMENT = new LinkedHashMap<UUID, FastPayment>(MAX_ENTRIES + 1, .75F, false) {
protected boolean removeEldestEntry(Map.Entry<UUID, FastPayment> eldest) {
@ -729,6 +732,14 @@ public final class Jobs extends JavaPlugin {
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) {
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) {
CMIMessages.consoleMessage("&cFAILED to connect to database");
return;
return false;
}
CMIMessages.consoleMessage("&eConnected to database (&6" + dbType + "&e)");
@ -492,10 +492,10 @@ public abstract class JobsDAO {
for (DBTables one : DBTables.values()) {
createDefaultTable(one);
}
checkDefaultCollumns();
} finally {
}
return true;
}
protected abstract void checkUpdate() throws SQLException;

View File

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