Sponge support
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package me.lucko.luckperms;
|
||||
|
||||
import me.lucko.luckperms.api.Logger;
|
||||
import me.lucko.luckperms.data.Datastore;
|
||||
import me.lucko.luckperms.groups.GroupManager;
|
||||
import me.lucko.luckperms.tracks.TrackManager;
|
||||
@@ -9,7 +10,6 @@ import me.lucko.luckperms.utils.UuidCache;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public interface LuckPermsPlugin {
|
||||
|
||||
@@ -47,7 +47,7 @@ public interface LuckPermsPlugin {
|
||||
* Retrieves the {@link Logger} for the plugin
|
||||
* @return the plugin's {@link Logger}
|
||||
*/
|
||||
Logger getLogger();
|
||||
Logger getLog();
|
||||
|
||||
/**
|
||||
* Retrieves the {@link UuidCache} for the plugin
|
||||
|
||||
@@ -33,6 +33,11 @@ public class ApiProvider implements LuckPermsApi {
|
||||
return new DatastoreLink(plugin.getDatastore());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Logger getLogger() {
|
||||
return plugin.getLog();
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUser(@NonNull UUID uuid) {
|
||||
final me.lucko.luckperms.users.User user = plugin.getUserManager().getUser(uuid);
|
||||
|
||||
@@ -23,7 +23,6 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CommandManager {
|
||||
@@ -162,7 +161,7 @@ public class CommandManager {
|
||||
}
|
||||
|
||||
private void registerMainCommand(MainCommand command) {
|
||||
plugin.getLogger().log(Level.INFO, "[CommandManager] Registered main command '" + command.getName() + "'");
|
||||
plugin.getLog().info("[CommandManager] Registered main command '" + command.getName() + "'");
|
||||
mainCommands.add(command);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
package me.lucko.luckperms.data.methods;
|
||||
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import lombok.Cleanup;
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.data.MySQLConfiguration;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class MySQLDatastore extends SQLDatastore {
|
||||
|
||||
@@ -41,13 +43,53 @@ public class MySQLDatastore extends SQLDatastore {
|
||||
hikari.addDataSourceProperty("password", password);
|
||||
|
||||
if (!setupTables(CREATETABLE_UUID, CREATETABLE_USERS, CREATETABLE_GROUPS, CREATETABLE_TRACKS)) {
|
||||
plugin.getLogger().log(Level.SEVERE, "Error occurred whilst initialising the database. All connections are disallowed.");
|
||||
plugin.getLog().severe("Error occurred whilst initialising the database. All connections are disallowed.");
|
||||
shutdown();
|
||||
} else {
|
||||
setAcceptingLogins(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean runQuery(QueryPS queryPS) {
|
||||
boolean success = false;
|
||||
try {
|
||||
@Cleanup Connection connection = getConnection();
|
||||
if (connection == null || connection.isClosed()) {
|
||||
throw new IllegalStateException("SQL connection is null");
|
||||
}
|
||||
|
||||
@Cleanup PreparedStatement preparedStatement = connection.prepareStatement(queryPS.getQuery());
|
||||
queryPS.onRun(preparedStatement);
|
||||
preparedStatement.execute();
|
||||
success = true;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean runQuery(QueryRS queryRS) {
|
||||
boolean success = false;
|
||||
try {
|
||||
@Cleanup Connection connection = getConnection();
|
||||
if (connection == null || connection.isClosed()) {
|
||||
throw new IllegalStateException("SQL connection is null");
|
||||
}
|
||||
|
||||
@Cleanup PreparedStatement preparedStatement = connection.prepareStatement(queryRS.getQuery());
|
||||
queryRS.onRun(preparedStatement);
|
||||
preparedStatement.execute();
|
||||
|
||||
@Cleanup ResultSet resultSet = preparedStatement.executeQuery();
|
||||
success = queryRS.onResult(resultSet);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
if (hikari != null) {
|
||||
|
||||
@@ -3,7 +3,6 @@ package me.lucko.luckperms.data.methods;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Cleanup;
|
||||
import lombok.Getter;
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.data.Datastore;
|
||||
@@ -58,43 +57,8 @@ abstract class SQLDatastore extends Datastore {
|
||||
|
||||
abstract Connection getConnection() throws SQLException;
|
||||
|
||||
private boolean runQuery(QueryPS queryPS) {
|
||||
boolean success = false;
|
||||
try {
|
||||
@Cleanup Connection connection = getConnection();
|
||||
if (connection == null) {
|
||||
throw new IllegalStateException("SQL connection is null");
|
||||
}
|
||||
|
||||
@Cleanup PreparedStatement preparedStatement = connection.prepareStatement(queryPS.getQuery());
|
||||
queryPS.onRun(preparedStatement);
|
||||
preparedStatement.execute();
|
||||
success = true;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
private boolean runQuery(QueryRS queryRS) {
|
||||
boolean success = false;
|
||||
try {
|
||||
@Cleanup Connection connection = getConnection();
|
||||
if (connection == null || connection.isClosed()) {
|
||||
throw new IllegalStateException("SQL connection is null");
|
||||
}
|
||||
|
||||
@Cleanup PreparedStatement preparedStatement = connection.prepareStatement(queryRS.getQuery());
|
||||
queryRS.onRun(preparedStatement);
|
||||
preparedStatement.execute();
|
||||
|
||||
@Cleanup ResultSet resultSet = preparedStatement.executeQuery();
|
||||
success = queryRS.onResult(resultSet);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return success;
|
||||
}
|
||||
abstract boolean runQuery(QueryPS queryPS);
|
||||
abstract boolean runQuery(QueryRS queryRS);
|
||||
|
||||
boolean setupTables(String... tableQueries) {
|
||||
boolean success = true;
|
||||
@@ -467,14 +431,14 @@ abstract class SQLDatastore extends Datastore {
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
private abstract class QueryPS {
|
||||
abstract class QueryPS {
|
||||
private final String query;
|
||||
abstract void onRun(PreparedStatement preparedStatement) throws SQLException;
|
||||
}
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
private abstract class QueryRS {
|
||||
abstract class QueryRS {
|
||||
private final String query;
|
||||
abstract void onRun(PreparedStatement preparedStatement) throws SQLException;
|
||||
abstract boolean onResult(ResultSet resultSet) throws SQLException;
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package me.lucko.luckperms.data.methods;
|
||||
|
||||
import lombok.Cleanup;
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Level;
|
||||
import java.sql.*;
|
||||
|
||||
public class SQLiteDatastore extends SQLDatastore {
|
||||
|
||||
@@ -26,13 +24,53 @@ public class SQLiteDatastore extends SQLDatastore {
|
||||
@Override
|
||||
public void init() {
|
||||
if (!setupTables(CREATETABLE_UUID, CREATETABLE_USERS, CREATETABLE_GROUPS, CREATETABLE_TRACKS)) {
|
||||
plugin.getLogger().log(Level.SEVERE, "Error occurred whilst initialising the database. All connections are disallowed.");
|
||||
plugin.getLog().severe("Error occurred whilst initialising the database. All connections are disallowed.");
|
||||
shutdown();
|
||||
} else {
|
||||
setAcceptingLogins(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean runQuery(QueryPS queryPS) {
|
||||
boolean success = false;
|
||||
try {
|
||||
Connection connection = getConnection();
|
||||
if (connection == null || connection.isClosed()) {
|
||||
throw new IllegalStateException("SQL connection is null");
|
||||
}
|
||||
|
||||
@Cleanup PreparedStatement preparedStatement = connection.prepareStatement(queryPS.getQuery());
|
||||
queryPS.onRun(preparedStatement);
|
||||
preparedStatement.execute();
|
||||
success = true;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean runQuery(QueryRS queryRS) {
|
||||
boolean success = false;
|
||||
try {
|
||||
Connection connection = getConnection();
|
||||
if (connection == null || connection.isClosed()) {
|
||||
throw new IllegalStateException("SQL connection is null");
|
||||
}
|
||||
|
||||
@Cleanup PreparedStatement preparedStatement = connection.prepareStatement(queryRS.getQuery());
|
||||
queryRS.onRun(preparedStatement);
|
||||
preparedStatement.execute();
|
||||
|
||||
@Cleanup ResultSet resultSet = preparedStatement.executeQuery();
|
||||
success = queryRS.onResult(resultSet);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
try {
|
||||
|
||||
@@ -9,7 +9,7 @@ public class UpdateTask implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
plugin.getLogger().info("Running update task.");
|
||||
plugin.getLog().info("Running update task.");
|
||||
|
||||
// Reload all of the groups
|
||||
plugin.getDatastore().loadAllGroups();
|
||||
|
||||
@@ -22,14 +22,14 @@ public abstract class LPConfiguration<T extends LuckPermsPlugin> {
|
||||
init();
|
||||
|
||||
if (Patterns.NON_ALPHA_NUMERIC.matcher(getServer()).find()) {
|
||||
plugin.getLogger().severe("Server name defined in config.yml contains invalid characters. Server names can " +
|
||||
plugin.getLog().severe("Server name defined in config.yml contains invalid characters. Server names can " +
|
||||
"only contain alphanumeric characters.\nDefined server name '" + getServer() + "' will be replaced with '" +
|
||||
defaultServerName + "' (the default)");
|
||||
set("server", defaultServerName);
|
||||
}
|
||||
|
||||
if (Patterns.NON_ALPHA_NUMERIC.matcher(getDefaultGroupName()).find()) {
|
||||
plugin.getLogger().severe("Default group defined in config.yml contains invalid characters. Group names can " +
|
||||
plugin.getLog().severe("Default group defined in config.yml contains invalid characters. Group names can " +
|
||||
"only contain alphanumeric characters.\nDefined default group name '" + getDefaultGroupName() +
|
||||
"' will be replaced with 'default' (the default)");
|
||||
set("default-group", "default");
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package me.lucko.luckperms.utils;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import me.lucko.luckperms.api.Logger;
|
||||
|
||||
@UtilityClass
|
||||
public class LogUtil {
|
||||
public static Logger wrap(org.slf4j.Logger l) {
|
||||
return new Logger() {
|
||||
private final org.slf4j.Logger logger = l;
|
||||
|
||||
@Override
|
||||
public void info(String s) {
|
||||
logger.info(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String s) {
|
||||
logger.warn(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void severe(String s) {
|
||||
logger.error(s);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static Logger wrap(java.util.logging.Logger l) {
|
||||
return new Logger() {
|
||||
private final java.util.logging.Logger logger = l;
|
||||
|
||||
@Override
|
||||
public void info(String s) {
|
||||
logger.info(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String s) {
|
||||
logger.warning(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void severe(String s) {
|
||||
logger.severe(s);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import java.util.regex.Pattern;
|
||||
|
||||
@UtilityClass
|
||||
public class Patterns {
|
||||
public static final Pattern SPACE_SPLIT = Pattern.compile(" ");
|
||||
public static final Pattern SERVER_SPLIT = Pattern.compile("\\/");
|
||||
public static final Pattern WORLD_SPLIT = Pattern.compile("\\-");
|
||||
public static final Pattern TEMP_SPLIT = Pattern.compile("\\$");
|
||||
|
||||
@@ -580,7 +580,7 @@ public abstract class PermissionObject {
|
||||
if (group != null) {
|
||||
perms.putAll(group.getLocalPermissions(server, excludedGroups));
|
||||
} else {
|
||||
plugin.getLogger().warning("Error whilst refreshing the permissions of '" + objectName + "'." +
|
||||
plugin.getLog().warn("Error whilst refreshing the permissions of '" + objectName + "'." +
|
||||
"\n The group '" + groupName + "' is not loaded.");
|
||||
}
|
||||
}
|
||||
@@ -603,7 +603,7 @@ public abstract class PermissionObject {
|
||||
if (group != null) {
|
||||
perms.putAll(group.getLocalPermissions(server, excludedGroups));
|
||||
} else {
|
||||
plugin.getLogger().warning("Error whilst refreshing the permissions of '" + objectName + "'." +
|
||||
plugin.getLog().warn("Error whilst refreshing the permissions of '" + objectName + "'." +
|
||||
"\n The group '" + groupName + "' is not loaded.");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user