Fix NPE and plugin not loading when Vault missing
This commit is contained in:
@@ -21,7 +21,7 @@ public abstract class Datastore {
|
||||
protected Datastore(LuckPermsPlugin plugin, String name) {
|
||||
this.plugin = plugin;
|
||||
this.name = name;
|
||||
this.acceptingLogins = true;
|
||||
this.acceptingLogins = false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -89,12 +89,12 @@ public class FlatfileDatastore extends Datastore {
|
||||
try {
|
||||
makeFiles();
|
||||
} catch (IOException e) {
|
||||
// TODO catch here or something
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
uuidCache.putAll(getUUIDCache());
|
||||
setAcceptingLogins(true);
|
||||
}
|
||||
|
||||
private void makeFiles() throws IOException {
|
||||
|
||||
@@ -6,6 +6,7 @@ import me.lucko.luckperms.data.MySQLConfiguration;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class MySQLDatastore extends SQLDatastore {
|
||||
|
||||
@@ -38,7 +39,12 @@ public class MySQLDatastore extends SQLDatastore {
|
||||
hikari.addDataSourceProperty("user", username);
|
||||
hikari.addDataSourceProperty("password", password);
|
||||
|
||||
setupTables(CREATETABLE_UUID, CREATETABLE_USERS, CREATETABLE_GROUPS);
|
||||
if (!setupTables(CREATETABLE_UUID, CREATETABLE_USERS, CREATETABLE_GROUPS)) {
|
||||
plugin.getLogger().log(Level.SEVERE, "Error occurred whilst initialising the database. All connections are disallowed.");
|
||||
shutdown();
|
||||
} else {
|
||||
setAcceptingLogins(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -113,17 +113,13 @@ abstract class SQLDatastore extends Datastore {
|
||||
return success;
|
||||
}
|
||||
|
||||
void setupTables(String... tableQueries) {
|
||||
boolean setupTables(String... tableQueries) {
|
||||
boolean success = true;
|
||||
for (String q : tableQueries) {
|
||||
if (!runQuery(new Query(q))) success = false;
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
plugin.getLogger().log(Level.SEVERE, "Error occurred whilst initialising the database. All connections are disallowed.");
|
||||
shutdown();
|
||||
setAcceptingLogins(false);
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class SQLiteDatastore extends SQLDatastore {
|
||||
|
||||
@@ -23,12 +24,23 @@ public class SQLiteDatastore extends SQLDatastore {
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
setupTables(CREATETABLE_UUID, CREATETABLE_USERS, CREATETABLE_GROUPS);
|
||||
if (!setupTables(CREATETABLE_UUID, CREATETABLE_USERS, CREATETABLE_GROUPS)) {
|
||||
plugin.getLogger().log(Level.SEVERE, "Error occurred whilst initialising the database. All connections are disallowed.");
|
||||
shutdown();
|
||||
} else {
|
||||
setAcceptingLogins(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
|
||||
try {
|
||||
if (connection != null && !connection.isClosed()) {
|
||||
connection.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user