mirror of
https://github.com/Zrips/Jobs.git
synced 2024-11-29 14:05:25 +01:00
Plugin needs to be disabled in case we can't connect to database
This commit is contained in:
parent
5f57d4aa95
commit
68b74bfa1b
@ -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();
|
||||
}
|
||||
|
@ -0,0 +1,5 @@
|
||||
package com.gamingmesh.jobs.container;
|
||||
|
||||
public enum LoadStatus {
|
||||
MYSQLFailure, SQLITEFailure, Good;
|
||||
}
|
@ -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;
|
||||
|
@ -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;
|
||||
@ -62,7 +64,7 @@ public class JobsManager {
|
||||
}
|
||||
|
||||
private String username = "root", password = "", hostname = "localhost:3306", database = "minecraft", prefix = "jobs_",
|
||||
characterEncoding = "utf8", encoding = "UTF-8";
|
||||
characterEncoding = "utf8", encoding = "UTF-8";
|
||||
private boolean certificate = false, ssl = false, autoReconnect = false;
|
||||
|
||||
public void start() {
|
||||
@ -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);
|
||||
@ -124,7 +133,7 @@ public class JobsManager {
|
||||
|
||||
if (plugin.isEnabled()) {
|
||||
JobsMySQL data = new JobsMySQL(plugin, hostname, database, username, password, prefix, certificate, ssl, autoReconnect,
|
||||
characterEncoding, encoding);
|
||||
characterEncoding, encoding);
|
||||
data.initialize();
|
||||
return data;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user