mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-28 05:35:26 +01:00
Fixes towards #77
This commit is contained in:
parent
a81a361a93
commit
2dad9f84fc
@ -81,6 +81,7 @@ import org.bukkit.plugin.ServicePriority;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
@ -420,6 +421,11 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
return getDataFolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getResourceStream(String path) {
|
||||
return getResource(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Player getPlayer(User user) {
|
||||
return getServer().getPlayer(uuidCache.getExternalUUID(user.getUuid()));
|
||||
|
@ -67,6 +67,7 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@ -227,6 +228,11 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
||||
return getDataFolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getResourceStream(String path) {
|
||||
return getResourceAsStream(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProxiedPlayer getPlayer(User user) {
|
||||
return getProxy().getPlayer(uuidCache.getExternalUUID(user.getUuid()));
|
||||
|
@ -47,6 +47,7 @@ import me.lucko.luckperms.common.utils.LocaleManager;
|
||||
import me.lucko.luckperms.common.utils.PermissionCache;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
@ -228,6 +229,14 @@ public interface LuckPermsPlugin {
|
||||
*/
|
||||
File getDataFolder();
|
||||
|
||||
/**
|
||||
* Gets a bundled resource file from the jar
|
||||
*
|
||||
* @param path the path of the file
|
||||
* @return the file as an input stream
|
||||
*/
|
||||
InputStream getResourceStream(String path);
|
||||
|
||||
/**
|
||||
* Returns a colored string indicating the status of a player
|
||||
*
|
||||
|
@ -63,7 +63,7 @@ public class SQLBacking extends AbstractBacking {
|
||||
|
||||
private static final String USER_PERMISSIONS_SELECT = "SELECT permission, value, server, world, expiry, contexts FROM {prefix}user_permissions WHERE uuid=?";
|
||||
private static final String USER_PERMISSIONS_DELETE = "DELETE FROM {prefix}user_permissions WHERE uuid=?";
|
||||
private static final String USER_PERMISSIONS_INSERT = "INSERT INTO {prefix}user_permissions VALUES(?, ?, ?, ?, ?, ?, ?)";
|
||||
private static final String USER_PERMISSIONS_INSERT = "INSERT INTO {prefix}user_permissions(uuid, permission, value, server, world, expiry, contexts) VALUES(?, ?, ?, ?, ?, ?, ?)";
|
||||
private static final String USER_PERMISSIONS_SELECT_DISTINCT = "SELECT DISTINCT uuid FROM {prefix}user_permissions";
|
||||
|
||||
private static final String PLAYER_SELECT = "SELECT username, primary_group FROM {prefix}players WHERE uuid=?";
|
||||
@ -75,7 +75,7 @@ public class SQLBacking extends AbstractBacking {
|
||||
|
||||
private static final String GROUP_PERMISSIONS_SELECT = "SELECT permission, value, server, world, expiry, contexts FROM {prefix}group_permissions WHERE name=?";
|
||||
private static final String GROUP_PERMISSIONS_DELETE = "DELETE FROM {prefix}group_permissions WHERE name=?";
|
||||
private static final String GROUP_PERMISSIONS_INSERT = "INSERT INTO {prefix}group_permissions VALUES(?, ?, ?, ?, ?, ?, ?)";
|
||||
private static final String GROUP_PERMISSIONS_INSERT = "INSERT INTO {prefix}group_permissions(name, permission, value, server, world, expiry, contexts) VALUES(?, ?, ?, ?, ?, ?, ?)";
|
||||
|
||||
private static final String GROUP_SELECT = "SELECT name FROM {prefix}groups";
|
||||
private static final String GROUP_INSERT = "INSERT INTO {prefix}groups VALUES(?)";
|
||||
@ -87,7 +87,7 @@ public class SQLBacking extends AbstractBacking {
|
||||
private static final String TRACK_UPDATE = "UPDATE {prefix}tracks SET groups=? WHERE name=?";
|
||||
private static final String TRACK_DELETE = "DELETE FROM {prefix}tracks WHERE name=?";
|
||||
|
||||
private static final String ACTION_INSERT = "INSERT INTO {prefix}actions(`time`, `actor_uuid`, `actor_name`, `type`, `acted_uuid`, `acted_name`, `action`) VALUES(?, ?, ?, ?, ?, ?, ?)";
|
||||
private static final String ACTION_INSERT = "INSERT INTO {prefix}actions(time, actor_uuid, actor_name, type, acted_uuid, acted_name, action) VALUES(?, ?, ?, ?, ?, ?, ?)";
|
||||
private static final String ACTION_SELECT_ALL = "SELECT * FROM {prefix}actions";
|
||||
|
||||
|
||||
@ -130,9 +130,9 @@ public class SQLBacking extends AbstractBacking {
|
||||
provider.init();
|
||||
|
||||
// Init tables
|
||||
if (!tableExists(prefix + "user_permissions")) {
|
||||
if (!tableExists(prefix.apply("{prefix}user_permissions"))) {
|
||||
String schemaFileName = "lp-schema-" + provider.getName().toLowerCase() + ".sql";
|
||||
try (InputStream is = plugin.getClass().getResourceAsStream("sql/" + schemaFileName)) {
|
||||
try (InputStream is = plugin.getResourceStream(schemaFileName)) {
|
||||
if (is == null) {
|
||||
throw new Exception("Couldn't locate schema file for " + provider.getName());
|
||||
}
|
||||
|
@ -27,9 +27,6 @@ import com.zaxxer.hikari.HikariDataSource;
|
||||
|
||||
import me.lucko.luckperms.common.storage.DatastoreConfiguration;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@ -82,46 +79,7 @@ public class PostgreSQLProvider extends SQLProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection getConnection() throws SQLException {
|
||||
return hikari.getConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean runQuery(String query, QueryPS queryPS) {
|
||||
try (Connection connection = getConnection()) {
|
||||
if (connection == null || connection.isClosed()) {
|
||||
throw new IllegalStateException("SQL connection is null");
|
||||
}
|
||||
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(query)) {
|
||||
queryPS.onRun(preparedStatement);
|
||||
|
||||
preparedStatement.execute();
|
||||
return true;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean runQuery(String query, QueryPS queryPS, QueryRS queryRS) {
|
||||
try (Connection connection = getConnection()){
|
||||
if (connection == null || connection.isClosed()) {
|
||||
throw new IllegalStateException("SQL connection is null");
|
||||
}
|
||||
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(query)) {
|
||||
queryPS.onRun(preparedStatement);
|
||||
|
||||
try (ResultSet resultSet = preparedStatement.executeQuery()) {
|
||||
return queryRS.onResult(resultSet);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
public WrappedConnection getConnection() throws SQLException {
|
||||
return new WrappedConnection(hikari.getConnection(), true);
|
||||
}
|
||||
}
|
||||
|
@ -93,6 +93,7 @@ import org.spongepowered.api.service.permission.SubjectCollection;
|
||||
import org.spongepowered.api.text.Text;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
@ -336,6 +337,11 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
||||
return getMainDir();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getResourceStream(String path) {
|
||||
return getClass().getClassLoader().getResourceAsStream(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Player getPlayer(User user) {
|
||||
return game.getServer().getPlayer(uuidCache.getExternalUUID(user.getUuid())).orElse(null);
|
||||
|
Loading…
Reference in New Issue
Block a user