From 38852749df29cb4b94312d3e97e7f7b392ddf403 Mon Sep 17 00:00:00 2001 From: Luis Date: Thu, 31 Oct 2024 13:18:17 +0000 Subject: [PATCH 1/8] chore(deps): upgrade to Minestom 1.21.2 --- minestom/build.gradle | 6 +- .../listeners/MinestomConnectionListener.java | 24 ++-- .../luckperms/minestom/ExamplePlayer.java | 108 ++---------------- .../luckperms/minestom/MinestomServer.java | 10 +- 4 files changed, 31 insertions(+), 117 deletions(-) diff --git a/minestom/build.gradle b/minestom/build.gradle index b62a73a2f..7971f1c07 100644 --- a/minestom/build.gradle +++ b/minestom/build.gradle @@ -13,6 +13,8 @@ repositories { } dependencies { + var minestom = "1_21_2-b4bd4ea221" + api(project(":common")) { // exclude default config providers as they are inaccessible from the minestom module anyway exclude group: "org.spongepowered", module: "configurate-yaml" @@ -20,11 +22,11 @@ dependencies { exclude group: "org.spongepowered", module: "configurate-hocon" exclude group: "me.lucko.configurate", module: "configurate-toml" } - compileOnly "net.minestom:minestom-snapshots:dba90a461b" + compileOnly "net.minestom:minestom-snapshots:$minestom" // testing testImplementation project(":common") - testImplementation "net.minestom:minestom-snapshots:dba90a461b" + testImplementation "net.minestom:minestom-snapshots:$minestom" testImplementation "commons-net:commons-net:3.10.0" // fix vulnerability in minestom testImplementation "ch.qos.logback:logback-classic:1.4.14" // logger testImplementation "org.spongepowered:configurate-hocon:3.7.2" // configuration using hocon diff --git a/minestom/src/main/java/me/lucko/luckperms/minestom/listeners/MinestomConnectionListener.java b/minestom/src/main/java/me/lucko/luckperms/minestom/listeners/MinestomConnectionListener.java index 8e5ef0bab..2f15d1ae9 100644 --- a/minestom/src/main/java/me/lucko/luckperms/minestom/listeners/MinestomConnectionListener.java +++ b/minestom/src/main/java/me/lucko/luckperms/minestom/listeners/MinestomConnectionListener.java @@ -1,5 +1,6 @@ package me.lucko.luckperms.minestom.listeners; +import java.util.UUID; import java.util.concurrent.TimeUnit; import me.lucko.luckperms.common.config.ConfigKeys; import me.lucko.luckperms.common.locale.Message; @@ -15,6 +16,7 @@ import net.minestom.server.event.player.AsyncPlayerConfigurationEvent; import net.minestom.server.event.player.AsyncPlayerPreLoginEvent; import net.minestom.server.event.player.PlayerDisconnectEvent; +import net.minestom.server.network.player.GameProfile; public final class MinestomConnectionListener extends AbstractConnectionListener { @@ -36,25 +38,29 @@ private void onPlayerPreLogin(AsyncPlayerPreLoginEvent event) { ex.printStackTrace(); } + GameProfile profile = event.getGameProfile(); + UUID uuid = profile.uuid(); + String username = profile.name(); + if (this.plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) { - this.plugin.getLogger().info("Processing pre-login for " + event.getPlayerUuid() + " - " + event.getUsername()); + this.plugin.getLogger().info("Processing pre-login for " + uuid + " - " + username); } - if (!event.getPlayer().isOnline()) { - this.plugin.getLogger().info("Another plugin has cancelled the connection for " + event.getPlayerUuid() + " - " + event.getUsername() + ". No permissions data will be loaded."); + if (!event.getConnection().isOnline()) { + this.plugin.getLogger().info("Another plugin has cancelled the connection for " + uuid + " - " + username + ". No permissions data will be loaded."); return; } try { - User user = loadUser(event.getPlayerUuid(), event.getUsername()); - recordConnection(event.getPlayerUuid()); - this.plugin.getEventDispatcher().dispatchPlayerLoginProcess(event.getPlayerUuid(), event.getUsername(), user); + User user = loadUser(uuid, username); + recordConnection(uuid); + this.plugin.getEventDispatcher().dispatchPlayerLoginProcess(uuid, username, user); } catch (Exception ex) { - this.plugin.getLogger().severe("Exception occurred whilst loading data for " + event.getPlayerUuid() + " - " + event.getUsername(), ex); + this.plugin.getLogger().severe("Exception occurred whilst loading data for " + uuid + " - " + username, ex); Component reason = TranslationManager.render(Message.LOADING_DATABASE_ERROR.build()); - event.getPlayer().kick(reason); - this.plugin.getEventDispatcher().dispatchPlayerLoginProcess(event.getPlayerUuid(), event.getUsername(), null); + event.getConnection().kick(reason); + this.plugin.getEventDispatcher().dispatchPlayerLoginProcess(uuid, username, null); } } diff --git a/minestom/src/test/java/me/lucko/luckperms/minestom/ExamplePlayer.java b/minestom/src/test/java/me/lucko/luckperms/minestom/ExamplePlayer.java index b2fb13829..140c24b53 100644 --- a/minestom/src/test/java/me/lucko/luckperms/minestom/ExamplePlayer.java +++ b/minestom/src/test/java/me/lucko/luckperms/minestom/ExamplePlayer.java @@ -1,6 +1,5 @@ package me.lucko.luckperms.minestom; -import java.util.UUID; import java.util.concurrent.CompletableFuture; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.MiniMessage; @@ -12,13 +11,10 @@ import net.luckperms.api.platform.PlayerAdapter; import net.luckperms.api.util.Tristate; import net.minestom.server.entity.Player; +import net.minestom.server.network.player.GameProfile; import net.minestom.server.network.player.PlayerConnection; -import net.minestom.server.permission.Permission; -import net.minestom.server.permission.PermissionVerifier; -import net.minestom.server.utils.Unit; import org.checkerframework.checker.nullness.qual.NonNull; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; /** * An example implementation of permission handling in a Player using LuckPerms. @@ -32,8 +28,8 @@ public final class ExamplePlayer extends Player { private final @NotNull LuckPerms luckPerms; private final @NonNull PlayerAdapter playerAdapter; - public ExamplePlayer(@NotNull LuckPerms luckPerms, @NotNull UUID uuid, @NotNull String username, @NotNull PlayerConnection playerConnection) { - super(uuid, username, playerConnection); + public ExamplePlayer(@NotNull LuckPerms luckPerms, @NotNull GameProfile profile, @NotNull PlayerConnection connection) { + super(connection, profile); this.luckPerms = luckPerms; this.playerAdapter = this.luckPerms.getPlayerAdapter(Player.class); } @@ -46,22 +42,6 @@ public ExamplePlayer(@NotNull LuckPerms luckPerms, @NotNull UUID uuid, @NotNull return this.getLuckPermsUser().getCachedData().getMetaData(); } - /** - * Adds a permission to the player. - * - * @param permission the permission to add - * @deprecated the {@link Permission} object is not used in the LuckPerms - * implementation and does not return a future - */ - @Deprecated - @Override - public void addPermission(@NotNull Permission permission) { - // this method implements itself as fire-and-forget as LuckPerms - // provides futures as responses to permission changes, which - // Minestom does not support in this context - this.addPermission(permission.getPermissionName()); - } - /** * Adds a permission to the player. You may choose not to implement * this method on a production server, and leave permission management @@ -95,90 +75,17 @@ public void addPermission(@NotNull Permission permission) { return this.luckPerms.getUserManager().saveUser(user).thenApply(ignored -> result); } - /** - * Removes a permission from the player. - * - * @param permission the permission to remove - * @deprecated the {@link Permission} object is not used in the LuckPerms implementation - */ - @Deprecated - public void removePermission(@NotNull Permission permission) { - // this method implements itself as fire-and-forget as LuckPerms - // provides futures as responses to permission changes, which - // Minestom does not support in this context - this.removePermission(permission.getPermissionName()); - } - /** * Removes a permission from the player. You may choose not to implement * this method on a production server, and leave permission management * to the LuckPerms web interface or in-game commands. * * @param permissionName the name of the permission to remove - * @deprecated the overridden method does not return a future */ - @Override - @Deprecated - public void removePermission(@NotNull String permissionName) { - User user = this.getLuckPermsUser(); - user.data().remove(Node.builder(permissionName).build()); - this.luckPerms.getUserManager().saveUser(user); - } - - /** - * Removes a permission from the player. You may choose not to implement - * this method on a production server, and leave permission management - * to the LuckPerms web interface or in-game commands. - * - * @param permissionName the name of the permission to remove - * @param ignored ignored parameter to differentiate from the overridden method - */ - public @NotNull CompletableFuture removePermission(@NotNull String permissionName, @Nullable Void ignored) { + public @NotNull CompletableFuture removePermission(@NotNull String permissionName) { User user = this.getLuckPermsUser(); DataMutateResult result = user.data().remove(Node.builder(permissionName).build()); - return this.luckPerms.getUserManager().saveUser(user).thenApply(ignored0 -> result); - } - - /** - * Checks if the player has a permission. - * - * @param permission the permission to check - * @return true if the player has the permission - * @deprecated the {@link Permission} object is not used in the LuckPerms implementation - */ - @Deprecated - @Override - public boolean hasPermission(@NotNull Permission permission) { - return this.hasPermission(permission.getPermissionName()); - } - - /** - * Gets a permission from the player. - * - * @param permissionName the name of the permission to check - * @return the permission if the player has it, or null if not - * @deprecated the {@link Permission} object is not used in the LuckPerms implementation - */ - @Deprecated - @Override - public @Nullable Permission getPermission(@NotNull String permissionName) { - if (!this.hasPermission(permissionName)) return null; - return new Permission(permissionName); - } - - /** - * Checks if the player has a permission. - * - * @param permissionName the name of the permission to check - * @param permissionVerifier the permission verifier, unused - * @return true if the player has the permission - * @deprecated the {@link PermissionVerifier} interface checks for NBT data, which is not - * used in the LuckPerms implementation - */ - @Deprecated - @Override - public boolean hasPermission(@NotNull String permissionName, @Nullable PermissionVerifier permissionVerifier) { - return this.hasPermission(permissionName); + return this.luckPerms.getUserManager().saveUser(user).thenApply(ignored -> result); } /** @@ -187,9 +94,8 @@ public boolean hasPermission(@NotNull String permissionName, @Nullable Permissio * @param permissionName the name of the permission to check * @return true if the player has the permission */ - @Override public boolean hasPermission(@NotNull String permissionName) { - return this.getPermissionValue(permissionName).asBoolean(); + return this.getPermission(permissionName).asBoolean(); } /** @@ -200,7 +106,7 @@ public boolean hasPermission(@NotNull String permissionName) { * @param permissionName the name of the permission to check * @return the value of the permission */ - public @NotNull Tristate getPermissionValue(@NotNull String permissionName) { + public @NotNull Tristate getPermission(@NotNull String permissionName) { User user = this.getLuckPermsUser(); return user.getCachedData().getPermissionData().checkPermission(permissionName); } diff --git a/minestom/src/test/java/me/lucko/luckperms/minestom/MinestomServer.java b/minestom/src/test/java/me/lucko/luckperms/minestom/MinestomServer.java index d5e530541..9b0921186 100644 --- a/minestom/src/test/java/me/lucko/luckperms/minestom/MinestomServer.java +++ b/minestom/src/test/java/me/lucko/luckperms/minestom/MinestomServer.java @@ -26,6 +26,7 @@ import net.minestom.server.instance.InstanceContainer; import net.minestom.server.instance.block.Block; import net.minestom.server.network.ConnectionManager; +import net.minestom.server.network.player.GameProfile; public final class MinestomServer { @@ -47,7 +48,7 @@ public static void main(String[] args) { // set custom player provider (optional) ConnectionManager connectionManager = MinecraftServer.getConnectionManager(); - connectionManager.setPlayerProvider((uuid, username, connection) -> new ExamplePlayer(luckPerms, uuid, username, connection)); + connectionManager.setPlayerProvider((connection, profile) -> new ExamplePlayer(luckPerms, profile, connection)); // set up Minestom InstanceContainer instance = MinecraftServer.getInstanceManager().createInstanceContainer(); @@ -62,12 +63,11 @@ public static void main(String[] args) { // set custom chat handling (optional) eventNode.addListener(PlayerChatEvent.class, event -> { if (!(event.getPlayer() instanceof ExamplePlayer player)) return; - event.setChatFormat(e -> Component.text().append( + event.setFormattedMessage(Component.text().append( player.getPrefix(), player.getName(), player.getSuffix(), - Component.text(": "), - Component.text(e.getMessage()) + Component.text(": " + event.getRawMessage()) ).build()); }); @@ -93,7 +93,7 @@ public static void main(String[] args) { ArgumentString permissionArgument = ArgumentType.String("permission"); command.addSyntax((sender, context) -> { String permission = context.get(permissionArgument); - if (sender instanceof ExamplePlayer player) sender.sendMessage(player.getPermissionValue(permission).toString()); + if (sender instanceof ExamplePlayer player) sender.sendMessage(player.getPermission(permission).toString()); else sender.sendMessage("Sender is not a player"); }, permissionArgument); commandManager.register(command); From a92e04f605f00e60301c24b8ce085278bf98e6b1 Mon Sep 17 00:00:00 2001 From: Luck Date: Sat, 9 Nov 2024 12:09:23 +0000 Subject: [PATCH 2/8] Recreate individual sql tables if they are missing (#3995) --- .../common/messaging/sql/SqlMessenger.java | 2 +- .../implementation/sql/SchemaReader.java | 37 ++++- .../implementation/sql/SqlStorage.java | 102 ++++++------ .../sql/StatementProcessor.java | 43 +++++ .../sql/builder/PreparedStatementBuilder.java | 7 +- .../sql/connection/ConnectionFactory.java | 4 +- .../connection/file/H2ConnectionFactory.java | 15 +- .../file/SqliteConnectionFactory.java | 6 +- .../hikari/MariaDbConnectionFactory.java | 7 +- .../hikari/MySqlConnectionFactory.java | 6 +- .../hikari/PostgresConnectionFactory.java | 6 +- .../common/storage/AbstractStorageTest.java | 2 +- .../common/storage/SqlStorageTest.java | 46 +++++- .../implementation/sql/SchemaReaderTest.java | 148 ++++++++++++++++++ .../listeners/ForgeConnectionListener.java | 1 - .../forge/util/AsyncConfigurationTask.java | 2 - neoforge/loader/build.gradle | 3 +- .../neoforge/NeoForgeCommandExecutor.java | 4 +- .../capabilities/UserCapabilityImpl.java | 2 +- .../listeners/NeoForgeConnectionListener.java | 7 +- .../listeners/NeoForgePlatformListener.java | 6 +- .../messaging/PluginMessageMessenger.java | 6 +- .../service/NeoForgePermissionHandler.java | 10 +- .../neoforge/util/AsyncConfigurationTask.java | 1 - .../neoforge/util/NeoForgeEventBusFacade.java | 2 +- 25 files changed, 367 insertions(+), 108 deletions(-) create mode 100644 common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/StatementProcessor.java create mode 100644 common/src/test/java/me/lucko/luckperms/common/storage/implementation/sql/SchemaReaderTest.java diff --git a/common/src/main/java/me/lucko/luckperms/common/messaging/sql/SqlMessenger.java b/common/src/main/java/me/lucko/luckperms/common/messaging/sql/SqlMessenger.java index 8e2c34672..e49208d7e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/messaging/sql/SqlMessenger.java +++ b/common/src/main/java/me/lucko/luckperms/common/messaging/sql/SqlMessenger.java @@ -86,6 +86,6 @@ protected Connection getConnection() throws SQLException { @Override protected String getTableName() { - return this.sqlStorage.getStatementProcessor().apply("{prefix}messenger"); + return this.sqlStorage.getStatementProcessor().process("{prefix}messenger"); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/SchemaReader.java b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/SchemaReader.java index bb7e48b00..f80d9fc57 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/SchemaReader.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/SchemaReader.java @@ -32,10 +32,24 @@ import java.nio.charset.StandardCharsets; import java.util.LinkedList; import java.util.List; +import java.util.Locale; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; public final class SchemaReader { private SchemaReader() {} + private static final Pattern CREATE_TABLE_PATTERN = Pattern.compile("^CREATE TABLE [`\"']([^`\"']+)[`\"'].*"); + private static final Pattern CREATE_INDEX_PATTERN = Pattern.compile("^CREATE INDEX.* ON [`\"']([^`\"']+)[`\"'].*"); + + /** + * Parses a schema file to a list of SQL statements + * + * @param is the input stream to read from + * @return a list of statements + * @throws IOException if an error occurs whilst reading the file + */ public static List getStatements(InputStream is) throws IOException { List queries = new LinkedList<>(); @@ -53,7 +67,7 @@ public static List getStatements(InputStream is) throws IOException { if (line.endsWith(";")) { sb.deleteCharAt(sb.length() - 1); - String result = sb.toString().trim(); + String result = sb.toString().trim().replaceAll(" +", " "); if (!result.isEmpty()) { queries.add(result); } @@ -66,4 +80,25 @@ public static List getStatements(InputStream is) throws IOException { return queries; } + + /** + * Filters which statements should be executed based on the current list of tables in the database + * + * @param statements the statements to filter + * @param currentTables the current tables in the database + * @return the filtered list of statements + */ + public static List filterStatements(List statements, List currentTables) { + return statements.stream().filter(statement -> { + Matcher table = CREATE_TABLE_PATTERN.matcher(statement); + if (table.matches()) { + return !currentTables.contains(table.group(1).toLowerCase(Locale.ROOT)); + } + Matcher index = CREATE_INDEX_PATTERN.matcher(statement); + if (index.matches()) { + return !currentTables.contains(index.group(1).toLowerCase(Locale.ROOT)); + } + throw new IllegalArgumentException("Unknown statement type: " + statement); + }).collect(Collectors.toList()); + } } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/SqlStorage.java b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/SqlStorage.java index 321b814ea..b3023d8cf 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/SqlStorage.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/SqlStorage.java @@ -80,7 +80,6 @@ import java.util.Optional; import java.util.Set; import java.util.UUID; -import java.util.function.Function; import java.util.stream.Collectors; public class SqlStorage implements StorageImplementation { @@ -137,7 +136,7 @@ public class SqlStorage implements StorageImplementation { private final LuckPermsPlugin plugin; private final ConnectionFactory connectionFactory; - private final Function statementProcessor; + private final StatementProcessor statementProcessor; public SqlStorage(LuckPermsPlugin plugin, ConnectionFactory connectionFactory, String tablePrefix) { this.plugin = plugin; @@ -159,7 +158,7 @@ public ConnectionFactory getConnectionFactory() { return this.connectionFactory; } - public Function getStatementProcessor() { + public StatementProcessor getStatementProcessor() { return this.statementProcessor; } @@ -167,30 +166,32 @@ public Function getStatementProcessor() { public void init() throws Exception { this.connectionFactory.init(this.plugin); - boolean tableExists; + List tables; try (Connection c = this.connectionFactory.getConnection()) { - tableExists = tableExists(c, this.statementProcessor.apply("{prefix}user_permissions")); - } - - if (!tableExists) { - applySchema(); + tables = listTables(c); } + applySchema(tables); } - private void applySchema() throws IOException, SQLException { - List statements; - + private void applySchema(List existingTables) throws IOException, SQLException { String schemaFileName = "me/lucko/luckperms/schema/" + this.connectionFactory.getImplementationName().toLowerCase(Locale.ROOT) + ".sql"; + + List statements; try (InputStream is = this.plugin.getBootstrap().getResourceStream(schemaFileName)) { if (is == null) { throw new IOException("Couldn't locate schema file for " + this.connectionFactory.getImplementationName()); } statements = SchemaReader.getStatements(is).stream() - .map(this.statementProcessor) + .map(this.statementProcessor::process) .collect(Collectors.toList()); } + statements = SchemaReader.filterStatements(statements, existingTables); + if (statements.isEmpty()) { + return; + } + try (Connection connection = this.connectionFactory.getConnection()) { boolean utf8mb4Unsupported = false; @@ -240,7 +241,7 @@ public StorageMetadata getMeta() { @Override public void logAction(Action entry) throws SQLException { try (Connection c = this.connectionFactory.getConnection()) { - try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.apply(ACTION_INSERT))) { + try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.process(ACTION_INSERT))) { writeAction(entry, ps); ps.execute(); } @@ -288,7 +289,7 @@ public void applyBulkUpdate(BulkUpdate bulkUpdate) throws SQLException { try (Connection c = this.connectionFactory.getConnection()) { if (bulkUpdate.getDataType().isIncludingUsers()) { - Function tableReplacement = s -> s.replace("{table}", "{prefix}user_permissions"); + StatementProcessor tableReplacement = s -> s.replace("{table}", "{prefix}user_permissions"); BulkUpdateSqlBuilder sqlBuilder = new BulkUpdateSqlBuilder(); sqlBuilder.visit(bulkUpdate); @@ -319,7 +320,7 @@ public void applyBulkUpdate(BulkUpdate bulkUpdate) throws SQLException { } if (bulkUpdate.getDataType().isIncludingGroups()) { - Function tableReplacement = s -> s.replace("{table}", "{prefix}group_permissions"); + StatementProcessor tableReplacement = s -> s.replace("{table}", "{prefix}group_permissions"); BulkUpdateSqlBuilder sqlBuilder = new BulkUpdateSqlBuilder(); sqlBuilder.visit(bulkUpdate); @@ -448,7 +449,7 @@ public void saveUser(User user) throws SQLException { public Set getUniqueUsers() throws SQLException { Set uuids = new HashSet<>(); try (Connection c = this.connectionFactory.getConnection()) { - try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.apply(USER_PERMISSIONS_SELECT_DISTINCT))) { + try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.process(USER_PERMISSIONS_SELECT_DISTINCT))) { try (ResultSet rs = ps.executeQuery()) { while (rs.next()) { UUID uuid = Uuids.fromString(rs.getString("uuid")); @@ -496,7 +497,7 @@ public List> searchUserNodes(ConstraintNodeM public Group createAndLoadGroup(String name) throws SQLException { String query = GROUP_INSERT.getOrDefault(this.connectionFactory.getImplementationName(), GROUP_INSERT_DEFAULT); try (Connection c = this.connectionFactory.getConnection()) { - try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.apply(query))) { + try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.process(query))) { ps.setString(1, name); ps.execute(); } @@ -559,7 +560,7 @@ public void deleteGroup(Group group) throws SQLException { try (Connection c = this.connectionFactory.getConnection()) { deleteGroupPermissions(c, group.getName()); - try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.apply(GROUP_DELETE))) { + try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.process(GROUP_DELETE))) { ps.setString(1, group.getName()); ps.execute(); } @@ -662,7 +663,7 @@ public void saveTrack(Track track) throws SQLException { @Override public void deleteTrack(Track track) throws SQLException { try (Connection c = this.connectionFactory.getConnection()) { - try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.apply(TRACK_DELETE))) { + try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.process(TRACK_DELETE))) { ps.setString(1, track.getName()); ps.execute(); } @@ -679,7 +680,7 @@ public PlayerSaveResult savePlayerData(UUID uniqueId, String username) throws SQ try (Connection c = this.connectionFactory.getConnection()) { SqlPlayerData existingPlayerData = selectPlayerData(c, uniqueId); if (existingPlayerData == null) { - try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.apply(PLAYER_INSERT))) { + try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.process(PLAYER_INSERT))) { ps.setString(1, uniqueId.toString()); ps.setString(2, username); ps.setString(3, GroupManager.DEFAULT_GROUP_NAME); @@ -688,7 +689,7 @@ public PlayerSaveResult savePlayerData(UUID uniqueId, String username) throws SQ } else { oldUsername = existingPlayerData.username; if (!username.equals(oldUsername)) { - try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.apply(PLAYER_UPDATE_USERNAME_FOR_UUID))) { + try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.process(PLAYER_UPDATE_USERNAME_FOR_UUID))) { ps.setString(1, username); ps.setString(2, uniqueId.toString()); ps.execute(); @@ -701,7 +702,7 @@ public PlayerSaveResult savePlayerData(UUID uniqueId, String username) throws SQ Set conflicting = new HashSet<>(); try (Connection c = this.connectionFactory.getConnection()) { - try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.apply(PLAYER_SELECT_ALL_UUIDS_BY_USERNAME))) { + try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.process(PLAYER_SELECT_ALL_UUIDS_BY_USERNAME))) { ps.setString(1, username); ps.setString(2, uniqueId.toString()); try (ResultSet rs = ps.executeQuery()) { @@ -715,7 +716,7 @@ public PlayerSaveResult savePlayerData(UUID uniqueId, String username) throws SQ if (!conflicting.isEmpty()) { // remove the mappings for conflicting uuids try (Connection c = this.connectionFactory.getConnection()) { - try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.apply(PLAYER_DELETE_ALL_UUIDS_BY_USERNAME))) { + try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.process(PLAYER_DELETE_ALL_UUIDS_BY_USERNAME))) { ps.setString(1, username); ps.setString(2, uniqueId.toString()); ps.execute(); @@ -730,7 +731,7 @@ public PlayerSaveResult savePlayerData(UUID uniqueId, String username) throws SQ @Override public void deletePlayerData(UUID uniqueId) throws SQLException { try (Connection c = this.connectionFactory.getConnection()) { - try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.apply(PLAYER_DELETE))) { + try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.process(PLAYER_DELETE))) { ps.setString(1, uniqueId.toString()); ps.execute(); } @@ -741,7 +742,7 @@ public void deletePlayerData(UUID uniqueId) throws SQLException { public UUID getPlayerUniqueId(String username) throws SQLException { username = username.toLowerCase(Locale.ROOT); try (Connection c = this.connectionFactory.getConnection()) { - try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.apply(PLAYER_SELECT_UUID_BY_USERNAME))) { + try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.process(PLAYER_SELECT_UUID_BY_USERNAME))) { ps.setString(1, username); try (ResultSet rs = ps.executeQuery()) { if (rs.next()) { @@ -756,7 +757,7 @@ public UUID getPlayerUniqueId(String username) throws SQLException { @Override public String getPlayerName(UUID uniqueId) throws SQLException { try (Connection c = this.connectionFactory.getConnection()) { - try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.apply(PLAYER_SELECT_USERNAME_BY_UUID))) { + try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.process(PLAYER_SELECT_USERNAME_BY_UUID))) { ps.setString(1, uniqueId.toString()); try (ResultSet rs = ps.executeQuery()) { if (rs.next()) { @@ -872,7 +873,7 @@ private void updatePermissions(Connection c, String holder, Set add, Set add, Set add, Set add, Set selectUserPermissions(Connection c, UUID user) throws SQLException { List nodes = new ArrayList<>(); - try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.apply(USER_PERMISSIONS_SELECT))) { + try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.process(USER_PERMISSIONS_SELECT))) { ps.setString(1, user.toString()); try (ResultSet rs = ps.executeQuery()) { while (rs.next()) { @@ -921,7 +922,7 @@ private List selectUserPermissions(Connection c, UUID user) throws SQLExce } private SqlPlayerData selectPlayerData(Connection c, UUID user) throws SQLException { - try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.apply(PLAYER_SELECT_BY_UUID))) { + try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.process(PLAYER_SELECT_BY_UUID))) { ps.setString(1, user.toString()); try (ResultSet rs = ps.executeQuery()) { if (rs.next()) { @@ -982,15 +983,15 @@ private String createUserSelectWhereClause(String baseQuery, Set users) { // we don't want to use preparedstatements because the parameter length is variable // safe to do string concat/replacement because the UUID.toString value isn't injectable - return this.statementProcessor.apply(baseQuery) + param; + return this.statementProcessor.process(baseQuery) + param; } private void deleteUser(Connection c, UUID user) throws SQLException { - try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.apply(USER_PERMISSIONS_DELETE))) { + try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.process(USER_PERMISSIONS_DELETE))) { ps.setString(1, user.toString()); ps.execute(); } - try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.apply(PLAYER_UPDATE_PRIMARY_GROUP_BY_UUID))) { + try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.process(PLAYER_UPDATE_PRIMARY_GROUP_BY_UUID))) { ps.setString(1, GroupManager.DEFAULT_GROUP_NAME); ps.setString(2, user.toString()); ps.execute(); @@ -999,7 +1000,7 @@ private void deleteUser(Connection c, UUID user) throws SQLException { private void insertPlayerData(Connection c, UUID user, SqlPlayerData data) throws SQLException { boolean hasPrimaryGroupSaved; - try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.apply(PLAYER_SELECT_PRIMARY_GROUP_BY_UUID))) { + try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.process(PLAYER_SELECT_PRIMARY_GROUP_BY_UUID))) { ps.setString(1, user.toString()); try (ResultSet rs = ps.executeQuery()) { hasPrimaryGroupSaved = rs.next(); @@ -1008,14 +1009,14 @@ private void insertPlayerData(Connection c, UUID user, SqlPlayerData data) throw if (hasPrimaryGroupSaved) { // update - try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.apply(PLAYER_UPDATE_PRIMARY_GROUP_BY_UUID))) { + try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.process(PLAYER_UPDATE_PRIMARY_GROUP_BY_UUID))) { ps.setString(1, data.primaryGroup); ps.setString(2, user.toString()); ps.execute(); } } else { // insert - try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.apply(PLAYER_INSERT))) { + try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.process(PLAYER_INSERT))) { ps.setString(1, user.toString()); ps.setString(2, data.username); ps.setString(3, data.primaryGroup); @@ -1026,7 +1027,7 @@ private void insertPlayerData(Connection c, UUID user, SqlPlayerData data) throw private Set selectGroups(Connection c) throws SQLException { Set groups = new HashSet<>(); - try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.apply(GROUP_SELECT_ALL))) { + try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.process(GROUP_SELECT_ALL))) { try (ResultSet rs = ps.executeQuery()) { while (rs.next()) { groups.add(rs.getString("name").toLowerCase(Locale.ROOT)); @@ -1038,7 +1039,7 @@ private Set selectGroups(Connection c) throws SQLException { private List selectGroupPermissions(Connection c, String group) throws SQLException { List nodes = new ArrayList<>(); - try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.apply(GROUP_PERMISSIONS_SELECT))) { + try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.process(GROUP_PERMISSIONS_SELECT))) { ps.setString(1, group); try (ResultSet rs = ps.executeQuery()) { while (rs.next()) { @@ -1053,7 +1054,7 @@ private List selectGroupPermissions(Connection c, String group) throws SQL } private void selectAllGroupPermissions(Map> nodes, Connection c) throws SQLException { - try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.apply(GROUP_PERMISSIONS_SELECT_ALL))) { + try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.process(GROUP_PERMISSIONS_SELECT_ALL))) { try (ResultSet rs = ps.executeQuery()) { while (rs.next()) { String holder = rs.getString("name"); @@ -1070,7 +1071,7 @@ private void selectAllGroupPermissions(Map> nodes, Conn } private void deleteGroupPermissions(Connection c, String group) throws SQLException { - try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.apply(GROUP_PERMISSIONS_DELETE))) { + try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.process(GROUP_PERMISSIONS_DELETE))) { ps.setString(1, group); ps.execute(); } @@ -1078,7 +1079,7 @@ private void deleteGroupPermissions(Connection c, String group) throws SQLExcept private List selectTrack(Connection c, String name) throws SQLException { String groups; - try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.apply(TRACK_SELECT))) { + try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.process(TRACK_SELECT))) { ps.setString(1, name); try (ResultSet rs = ps.executeQuery()) { if (rs.next()) { @@ -1093,7 +1094,7 @@ private List selectTrack(Connection c, String name) throws SQLException private void insertTrack(Connection c, String name, List groups) throws SQLException { String json = GsonProvider.normal().toJson(groups); - try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.apply(TRACK_INSERT))) { + try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.process(TRACK_INSERT))) { ps.setString(1, name); ps.setString(2, json); ps.execute(); @@ -1102,7 +1103,7 @@ private void insertTrack(Connection c, String name, List groups) throws private void updateTrack(Connection c, String name, List groups) throws SQLException { String json = GsonProvider.normal().toJson(groups); - try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.apply(TRACK_UPDATE))) { + try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.process(TRACK_UPDATE))) { ps.setString(1, json); ps.setString(2, name); ps.execute(); @@ -1111,7 +1112,7 @@ private void updateTrack(Connection c, String name, List groups) throws private Set selectTracks(Connection c) throws SQLException { Set tracks = new HashSet<>(); - try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.apply(TRACK_SELECT_ALL))) { + try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.process(TRACK_SELECT_ALL))) { try (ResultSet rs = ps.executeQuery()) { while (rs.next()) { tracks.add(rs.getString("name").toLowerCase(Locale.ROOT)); @@ -1121,15 +1122,14 @@ private Set selectTracks(Connection c) throws SQLException { return tracks; } - private static boolean tableExists(Connection connection, String table) throws SQLException { + private static List listTables(Connection connection) throws SQLException { + List tables = new ArrayList<>(); try (ResultSet rs = connection.getMetaData().getTables(connection.getCatalog(), null, "%", null)) { while (rs.next()) { - if (rs.getString(3).equalsIgnoreCase(table)) { - return true; - } + tables.add(rs.getString(3).toLowerCase(Locale.ROOT)); } - return false; } + return tables; } private static final class SqlPlayerData { diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/StatementProcessor.java b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/StatementProcessor.java new file mode 100644 index 000000000..2cf80ea5b --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/StatementProcessor.java @@ -0,0 +1,43 @@ +/* + * This file is part of LuckPerms, licensed under the MIT License. + * + * Copyright (c) lucko (Luck) + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.lucko.luckperms.common.storage.implementation.sql; + +import java.util.Objects; + +public interface StatementProcessor { + + StatementProcessor USE_BACKTICKS = s -> s.replace('\'', '`'); + + StatementProcessor USE_DOUBLE_QUOTES = s -> s.replace('\'', '"'); + + String process(String statement); + + default StatementProcessor compose(StatementProcessor before) { + Objects.requireNonNull(before); + return s -> process(before.process(s)); + } + +} diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/builder/PreparedStatementBuilder.java b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/builder/PreparedStatementBuilder.java index 28a92242e..7c1ad3f18 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/builder/PreparedStatementBuilder.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/builder/PreparedStatementBuilder.java @@ -25,12 +25,13 @@ package me.lucko.luckperms.common.storage.implementation.sql.builder; +import me.lucko.luckperms.common.storage.implementation.sql.StatementProcessor; + import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; -import java.util.function.Function; public class PreparedStatementBuilder { private final StringBuilder sb = new StringBuilder(); @@ -56,10 +57,10 @@ public PreparedStatementBuilder variable(String variable) { return this; } - public PreparedStatement build(Connection connection, Function mapping) throws SQLException { + public PreparedStatement build(Connection connection, StatementProcessor processor) throws SQLException { PreparedStatement statement = null; try { - statement = connection.prepareStatement(mapping.apply(this.sb.toString())); + statement = connection.prepareStatement(processor.process(this.sb.toString())); for (int i = 0; i < this.variables.size(); i++) { String var = this.variables.get(i); statement.setString(i + 1, var); diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/ConnectionFactory.java b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/ConnectionFactory.java index 494313bb4..52adbac3a 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/ConnectionFactory.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/ConnectionFactory.java @@ -27,10 +27,10 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.storage.StorageMetadata; +import me.lucko.luckperms.common.storage.implementation.sql.StatementProcessor; import java.sql.Connection; import java.sql.SQLException; -import java.util.function.Function; public interface ConnectionFactory { @@ -42,7 +42,7 @@ public interface ConnectionFactory { StorageMetadata getMeta(); - Function getStatementProcessor(); + StatementProcessor getStatementProcessor(); Connection getConnection() throws SQLException; diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/file/H2ConnectionFactory.java b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/file/H2ConnectionFactory.java index cc36994ed..2764e3bba 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/file/H2ConnectionFactory.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/file/H2ConnectionFactory.java @@ -27,6 +27,7 @@ import me.lucko.luckperms.common.dependencies.Dependency; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; +import me.lucko.luckperms.common.storage.implementation.sql.StatementProcessor; import java.io.IOException; import java.lang.reflect.Constructor; @@ -38,9 +39,14 @@ import java.util.Collections; import java.util.EnumSet; import java.util.Properties; -import java.util.function.Function; public class H2ConnectionFactory extends FlatfileConnectionFactory { + public static final StatementProcessor STATEMENT_PROCESSOR = s -> s + .replace('\'', '`') + .replace("LIKE", "ILIKE") + .replace("value", "`value`") + .replace("``value``", "`value`"); + private Constructor connectionConstructor; public H2ConnectionFactory(Path file) { @@ -91,11 +97,8 @@ protected Path getWriteFile() { } @Override - public Function getStatementProcessor() { - return s -> s.replace('\'', '`') - .replace("LIKE", "ILIKE") - .replace("value", "`value`") - .replace("``value``", "`value`"); + public StatementProcessor getStatementProcessor() { + return STATEMENT_PROCESSOR; } /** diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/file/SqliteConnectionFactory.java b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/file/SqliteConnectionFactory.java index ab9e986fe..9d4e5b896 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/file/SqliteConnectionFactory.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/file/SqliteConnectionFactory.java @@ -27,6 +27,7 @@ import me.lucko.luckperms.common.dependencies.Dependency; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; +import me.lucko.luckperms.common.storage.implementation.sql.StatementProcessor; import java.lang.reflect.Constructor; import java.nio.file.Path; @@ -34,7 +35,6 @@ import java.sql.SQLException; import java.util.EnumSet; import java.util.Properties; -import java.util.function.Function; public class SqliteConnectionFactory extends FlatfileConnectionFactory { private Constructor connectionConstructor; @@ -74,7 +74,7 @@ protected Connection createConnection(Path file) throws SQLException { } @Override - public Function getStatementProcessor() { - return s -> s.replace('\'', '`'); + public StatementProcessor getStatementProcessor() { + return StatementProcessor.USE_BACKTICKS; } } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/hikari/MariaDbConnectionFactory.java b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/hikari/MariaDbConnectionFactory.java index abd395637..82ec8f6d3 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/hikari/MariaDbConnectionFactory.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/hikari/MariaDbConnectionFactory.java @@ -25,10 +25,9 @@ package me.lucko.luckperms.common.storage.implementation.sql.connection.hikari; +import me.lucko.luckperms.common.storage.implementation.sql.StatementProcessor; import me.lucko.luckperms.common.storage.misc.StorageCredentials; -import java.util.function.Function; - public class MariaDbConnectionFactory extends DriverBasedHikariConnectionFactory { public MariaDbConnectionFactory(StorageCredentials configuration) { super(configuration); @@ -55,7 +54,7 @@ protected String driverJdbcIdentifier() { } @Override - public Function getStatementProcessor() { - return s -> s.replace('\'', '`'); // use backticks for quotes + public StatementProcessor getStatementProcessor() { + return StatementProcessor.USE_BACKTICKS; } } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/hikari/MySqlConnectionFactory.java b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/hikari/MySqlConnectionFactory.java index 926069021..4b9872822 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/hikari/MySqlConnectionFactory.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/hikari/MySqlConnectionFactory.java @@ -25,10 +25,10 @@ package me.lucko.luckperms.common.storage.implementation.sql.connection.hikari; +import me.lucko.luckperms.common.storage.implementation.sql.StatementProcessor; import me.lucko.luckperms.common.storage.misc.StorageCredentials; import java.util.Map; -import java.util.function.Function; public class MySqlConnectionFactory extends DriverBasedHikariConnectionFactory { public MySqlConnectionFactory(StorageCredentials configuration) { @@ -80,7 +80,7 @@ protected void overrideProperties(Map properties) { } @Override - public Function getStatementProcessor() { - return s -> s.replace('\'', '`'); // use backticks for quotes + public StatementProcessor getStatementProcessor() { + return StatementProcessor.USE_BACKTICKS; } } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/hikari/PostgresConnectionFactory.java b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/hikari/PostgresConnectionFactory.java index 581be1246..0dc726e87 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/hikari/PostgresConnectionFactory.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/hikari/PostgresConnectionFactory.java @@ -25,10 +25,10 @@ package me.lucko.luckperms.common.storage.implementation.sql.connection.hikari; +import me.lucko.luckperms.common.storage.implementation.sql.StatementProcessor; import me.lucko.luckperms.common.storage.misc.StorageCredentials; import java.util.Map; -import java.util.function.Function; public class PostgresConnectionFactory extends DriverBasedHikariConnectionFactory { public PostgresConnectionFactory(StorageCredentials configuration) { @@ -65,7 +65,7 @@ protected void overrideProperties(Map properties) { } @Override - public Function getStatementProcessor() { - return s -> s.replace('\'', '"'); + public StatementProcessor getStatementProcessor() { + return StatementProcessor.USE_DOUBLE_QUOTES; } } diff --git a/common/src/test/java/me/lucko/luckperms/common/storage/AbstractStorageTest.java b/common/src/test/java/me/lucko/luckperms/common/storage/AbstractStorageTest.java index cf5025a6d..a4058a01e 100644 --- a/common/src/test/java/me/lucko/luckperms/common/storage/AbstractStorageTest.java +++ b/common/src/test/java/me/lucko/luckperms/common/storage/AbstractStorageTest.java @@ -88,7 +88,7 @@ public abstract class AbstractStorageTest { @Mock protected LuckPermsBootstrap bootstrap; @Mock protected LuckPermsConfiguration configuration; - private StorageImplementation storage; + protected StorageImplementation storage; @BeforeEach public final void setupMocksAndStorage() throws Exception { diff --git a/common/src/test/java/me/lucko/luckperms/common/storage/SqlStorageTest.java b/common/src/test/java/me/lucko/luckperms/common/storage/SqlStorageTest.java index f098c75ab..dc0e39f47 100644 --- a/common/src/test/java/me/lucko/luckperms/common/storage/SqlStorageTest.java +++ b/common/src/test/java/me/lucko/luckperms/common/storage/SqlStorageTest.java @@ -25,16 +25,24 @@ package me.lucko.luckperms.common.storage; +import me.lucko.luckperms.common.actionlog.LoggedAction; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.storage.implementation.StorageImplementation; import me.lucko.luckperms.common.storage.implementation.sql.SqlStorage; +import me.lucko.luckperms.common.storage.implementation.sql.StatementProcessor; import me.lucko.luckperms.common.storage.implementation.sql.connection.ConnectionFactory; +import me.lucko.luckperms.common.storage.implementation.sql.connection.file.H2ConnectionFactory; import me.lucko.luckperms.common.storage.implementation.sql.connection.file.NonClosableConnection; +import net.luckperms.api.actionlog.Action; +import org.junit.jupiter.api.Test; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; -import java.util.function.Function; +import java.time.Instant; +import java.util.UUID; + +import static org.junit.jupiter.api.Assertions.assertThrows; public class SqlStorageTest extends AbstractStorageTest { @@ -43,6 +51,35 @@ protected StorageImplementation makeStorage(LuckPermsPlugin plugin) throws Excep return new SqlStorage(plugin, new TestH2ConnectionFactory(), "luckperms_"); } + @Test + public void testRecreateTables() throws Exception { + SqlStorage sql = (SqlStorage) this.storage; + + LoggedAction testAction = LoggedAction.build() + .source(UUID.randomUUID()) + .sourceName("Test") + .targetType(Action.Target.Type.TRACK) + .targetName("test") + .description("test ") + .timestamp(Instant.now()) + .build(); + + // perform an action - ensure it works + this.storage.logAction(testAction); + + // delete the table + try (Connection c = sql.getConnectionFactory().getConnection()) { + c.createStatement().execute("DROP TABLE `luckperms_actions`"); + } + + // perform the action again - expect an exception + assertThrows(SQLException.class, () -> this.storage.logAction(testAction)); + + // recreate the table & repeat the action, ensure it works + this.storage.init(); + this.storage.logAction(testAction); + } + private static class TestH2ConnectionFactory implements ConnectionFactory { private final NonClosableConnection connection; @@ -73,11 +110,8 @@ public void init(LuckPermsPlugin plugin) { } @Override - public Function getStatementProcessor() { - return s -> s.replace('\'', '`') - .replace("LIKE", "ILIKE") - .replace("value", "`value`") - .replace("``value``", "`value`"); + public StatementProcessor getStatementProcessor() { + return H2ConnectionFactory.STATEMENT_PROCESSOR; } @Override diff --git a/common/src/test/java/me/lucko/luckperms/common/storage/implementation/sql/SchemaReaderTest.java b/common/src/test/java/me/lucko/luckperms/common/storage/implementation/sql/SchemaReaderTest.java new file mode 100644 index 000000000..45d20c8a1 --- /dev/null +++ b/common/src/test/java/me/lucko/luckperms/common/storage/implementation/sql/SchemaReaderTest.java @@ -0,0 +1,148 @@ +/* + * This file is part of LuckPerms, licensed under the MIT License. + * + * Copyright (c) lucko (Luck) + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.lucko.luckperms.common.storage.implementation.sql; + +import org.junit.jupiter.api.Test; +import org.testcontainers.shaded.com.google.common.collect.ImmutableList; + +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.stream.Collectors; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class SchemaReaderTest { + + private static List readStatements(String type) throws IOException { + List statements; + try (InputStream is = SchemaReaderTest.class.getResourceAsStream("/me/lucko/luckperms/schema/" + type + ".sql")) { + if (is == null) { + throw new IOException("Couldn't locate schema file"); + } + + statements = SchemaReader.getStatements(is); + } + return statements; + } + + @Test + public void testReadH2() throws IOException { + assertEquals(ImmutableList.of( + "CREATE TABLE `{prefix}user_permissions` ( `id` INT AUTO_INCREMENT NOT NULL, `uuid` VARCHAR(36) NOT NULL, `permission` VARCHAR(200) NOT NULL, `value` BOOL NOT NULL, `server` VARCHAR(36) NOT NULL, `world` VARCHAR(64) NOT NULL, `expiry` BIGINT NOT NULL, `contexts` VARCHAR(200) NOT NULL, PRIMARY KEY (`id`))", + "CREATE INDEX ON `{prefix}user_permissions` (`uuid`)", + "CREATE TABLE `{prefix}group_permissions` ( `id` INT AUTO_INCREMENT NOT NULL, `name` VARCHAR(36) NOT NULL, `permission` VARCHAR(200) NOT NULL, `value` BOOL NOT NULL, `server` VARCHAR(36) NOT NULL, `world` VARCHAR(64) NOT NULL, `expiry` BIGINT NOT NULL, `contexts` VARCHAR(200) NOT NULL, PRIMARY KEY (`id`))", + "CREATE INDEX ON `{prefix}group_permissions` (`name`)", + "CREATE TABLE `{prefix}players` ( `uuid` VARCHAR(36) NOT NULL, `username` VARCHAR(16) NOT NULL, `primary_group` VARCHAR(36) NOT NULL, PRIMARY KEY (`uuid`))", + "CREATE INDEX ON `{prefix}players` (`username`)", + "CREATE TABLE `{prefix}groups` ( `name` VARCHAR(36) NOT NULL, PRIMARY KEY (`name`))", + "CREATE TABLE `{prefix}actions` ( `id` INT AUTO_INCREMENT NOT NULL, `time` BIGINT NOT NULL, `actor_uuid` VARCHAR(36) NOT NULL, `actor_name` VARCHAR(100) NOT NULL, `type` CHAR(1) NOT NULL, `acted_uuid` VARCHAR(36) NOT NULL, `acted_name` VARCHAR(36) NOT NULL, `action` VARCHAR(300) NOT NULL, PRIMARY KEY (`id`))", + "CREATE TABLE `{prefix}tracks` ( `name` VARCHAR(36) NOT NULL, `groups` TEXT NOT NULL, PRIMARY KEY (`name`))" + ), readStatements("h2")); + } + + @Test + public void testReadSqlite() throws IOException { + assertEquals(ImmutableList.of( + "CREATE TABLE `{prefix}user_permissions` ( `id` INTEGER PRIMARY KEY NOT NULL, `uuid` VARCHAR(36) NOT NULL, `permission` VARCHAR(200) NOT NULL, `value` BOOL NOT NULL, `server` VARCHAR(36) NOT NULL, `world` VARCHAR(64) NOT NULL, `expiry` BIGINT NOT NULL, `contexts` VARCHAR(200) NOT NULL)", + "CREATE INDEX `{prefix}user_permissions_uuid` ON `{prefix}user_permissions` (`uuid`)", + "CREATE TABLE `{prefix}group_permissions` ( `id` INTEGER PRIMARY KEY NOT NULL, `name` VARCHAR(36) NOT NULL, `permission` VARCHAR(200) NOT NULL, `value` BOOL NOT NULL, `server` VARCHAR(36) NOT NULL, `world` VARCHAR(64) NOT NULL, `expiry` BIGINT NOT NULL, `contexts` VARCHAR(200) NOT NULL)", + "CREATE INDEX `{prefix}group_permissions_name` ON `{prefix}group_permissions` (`name`)", + "CREATE TABLE `{prefix}players` ( `uuid` VARCHAR(36) NOT NULL, `username` VARCHAR(16) NOT NULL, `primary_group` VARCHAR(36) NOT NULL, PRIMARY KEY (`uuid`))", + "CREATE INDEX `{prefix}players_username` ON `{prefix}players` (`username`)", + "CREATE TABLE `{prefix}groups` ( `name` VARCHAR(36) NOT NULL, PRIMARY KEY (`name`))", + "CREATE TABLE `{prefix}actions` ( `id` INTEGER PRIMARY KEY NOT NULL, `time` BIGINT NOT NULL, `actor_uuid` VARCHAR(36) NOT NULL, `actor_name` VARCHAR(100) NOT NULL, `type` CHAR(1) NOT NULL, `acted_uuid` VARCHAR(36) NOT NULL, `acted_name` VARCHAR(36) NOT NULL, `action` VARCHAR(300) NOT NULL)", + "CREATE TABLE `{prefix}tracks` ( `name` VARCHAR(36) NOT NULL, `groups` TEXT NOT NULL, PRIMARY KEY (`name`))" + ), readStatements("sqlite")); + } + + @Test + public void testReadMysql() throws IOException { + ImmutableList expected = ImmutableList.of( + "CREATE TABLE `{prefix}user_permissions` ( `id` INT AUTO_INCREMENT NOT NULL, `uuid` VARCHAR(36) NOT NULL, `permission` VARCHAR(200) NOT NULL, `value` BOOL NOT NULL, `server` VARCHAR(36) NOT NULL, `world` VARCHAR(64) NOT NULL, `expiry` BIGINT NOT NULL, `contexts` VARCHAR(200) NOT NULL, PRIMARY KEY (`id`)) DEFAULT CHARSET = utf8mb4", + "CREATE INDEX `{prefix}user_permissions_uuid` ON `{prefix}user_permissions` (`uuid`)", + "CREATE TABLE `{prefix}group_permissions` ( `id` INT AUTO_INCREMENT NOT NULL, `name` VARCHAR(36) NOT NULL, `permission` VARCHAR(200) NOT NULL, `value` BOOL NOT NULL, `server` VARCHAR(36) NOT NULL, `world` VARCHAR(64) NOT NULL, `expiry` BIGINT NOT NULL, `contexts` VARCHAR(200) NOT NULL, PRIMARY KEY (`id`)) DEFAULT CHARSET = utf8mb4", + "CREATE INDEX `{prefix}group_permissions_name` ON `{prefix}group_permissions` (`name`)", + "CREATE TABLE `{prefix}players` ( `uuid` VARCHAR(36) NOT NULL, `username` VARCHAR(16) NOT NULL, `primary_group` VARCHAR(36) NOT NULL, PRIMARY KEY (`uuid`)) DEFAULT CHARSET = utf8mb4", + "CREATE INDEX `{prefix}players_username` ON `{prefix}players` (`username`)", + "CREATE TABLE `{prefix}groups` ( `name` VARCHAR(36) NOT NULL, PRIMARY KEY (`name`)) DEFAULT CHARSET = utf8mb4", + "CREATE TABLE `{prefix}actions` ( `id` INT AUTO_INCREMENT NOT NULL, `time` BIGINT NOT NULL, `actor_uuid` VARCHAR(36) NOT NULL, `actor_name` VARCHAR(100) NOT NULL, `type` CHAR(1) NOT NULL, `acted_uuid` VARCHAR(36) NOT NULL, `acted_name` VARCHAR(36) NOT NULL, `action` VARCHAR(300) NOT NULL, PRIMARY KEY (`id`)) DEFAULT CHARSET = utf8mb4", + "CREATE TABLE `{prefix}tracks` ( `name` VARCHAR(36) NOT NULL, `groups` TEXT NOT NULL, PRIMARY KEY (`name`)) DEFAULT CHARSET = utf8mb4" + ); + assertEquals(expected, readStatements("mysql")); + assertEquals(expected, readStatements("mariadb")); + } + + @Test + public void testReadPostgres() throws IOException { + assertEquals(ImmutableList.of( + "CREATE TABLE \"{prefix}user_permissions\" ( \"id\" SERIAL PRIMARY KEY NOT NULL, \"uuid\" VARCHAR(36) NOT NULL, \"permission\" VARCHAR(200) NOT NULL, \"value\" BOOL NOT NULL, \"server\" VARCHAR(36) NOT NULL, \"world\" VARCHAR(64) NOT NULL, \"expiry\" BIGINT NOT NULL, \"contexts\" VARCHAR(200) NOT NULL)", + "CREATE INDEX \"{prefix}user_permissions_uuid\" ON \"{prefix}user_permissions\" (\"uuid\")", + "CREATE TABLE \"{prefix}group_permissions\" ( \"id\" SERIAL PRIMARY KEY NOT NULL, \"name\" VARCHAR(36) NOT NULL, \"permission\" VARCHAR(200) NOT NULL, \"value\" BOOL NOT NULL, \"server\" VARCHAR(36) NOT NULL, \"world\" VARCHAR(64) NOT NULL, \"expiry\" BIGINT NOT NULL, \"contexts\" VARCHAR(200) NOT NULL)", + "CREATE INDEX \"{prefix}group_permissions_name\" ON \"{prefix}group_permissions\" (\"name\")", + "CREATE TABLE \"{prefix}players\" ( \"uuid\" VARCHAR(36) PRIMARY KEY NOT NULL, \"username\" VARCHAR(16) NOT NULL, \"primary_group\" VARCHAR(36) NOT NULL)", + "CREATE INDEX \"{prefix}players_username\" ON \"{prefix}players\" (\"username\")", + "CREATE TABLE \"{prefix}groups\" ( \"name\" VARCHAR(36) PRIMARY KEY NOT NULL)", + "CREATE TABLE \"{prefix}actions\" ( \"id\" SERIAL PRIMARY KEY NOT NULL, \"time\" BIGINT NOT NULL, \"actor_uuid\" VARCHAR(36) NOT NULL, \"actor_name\" VARCHAR(100) NOT NULL, \"type\" CHAR(1) NOT NULL, \"acted_uuid\" VARCHAR(36) NOT NULL, \"acted_name\" VARCHAR(36) NOT NULL, \"action\" VARCHAR(300) NOT NULL)", + "CREATE TABLE \"{prefix}tracks\" ( \"name\" VARCHAR(36) PRIMARY KEY NOT NULL, \"groups\" TEXT NOT NULL)" + ), readStatements("postgresql")); + } + + @Test + public void testFilter() throws IOException { + StatementProcessor processor = s -> s.replace("{prefix}", "luckperms_"); + List statements = readStatements("mysql").stream().map(processor::process).collect(Collectors.toList()); + + // no tables exist, all should be created + List filtered = SchemaReader.filterStatements(statements, ImmutableList.of()); + assertEquals(statements, filtered); + + // all tables exist, none should be created + filtered = SchemaReader.filterStatements(statements, ImmutableList.of( + "luckperms_user_permissions", + "luckperms_group_permissions", + "luckperms_players", + "luckperms_groups", + "luckperms_actions", + "luckperms_tracks" + )); + assertEquals(ImmutableList.of(), filtered); + + // some tables exist, some should be created + filtered = SchemaReader.filterStatements(statements, ImmutableList.of( + "luckperms_user_permissions", + "luckperms_players", + "luckperms_groups", + "luckperms_actions", + "luckperms_tracks" + )); + assertEquals(ImmutableList.of( + "CREATE TABLE `luckperms_group_permissions` ( `id` INT AUTO_INCREMENT NOT NULL, `name` VARCHAR(36) NOT NULL, `permission` VARCHAR(200) NOT NULL, `value` BOOL NOT NULL, `server` VARCHAR(36) NOT NULL, `world` VARCHAR(64) NOT NULL, `expiry` BIGINT NOT NULL, `contexts` VARCHAR(200) NOT NULL, PRIMARY KEY (`id`)) DEFAULT CHARSET = utf8mb4", + "CREATE INDEX `luckperms_group_permissions_name` ON `luckperms_group_permissions` (`name`)" + ), filtered); + } + +} diff --git a/forge/src/main/java/me/lucko/luckperms/forge/listeners/ForgeConnectionListener.java b/forge/src/main/java/me/lucko/luckperms/forge/listeners/ForgeConnectionListener.java index 9efef7cb6..5c4575e72 100644 --- a/forge/src/main/java/me/lucko/luckperms/forge/listeners/ForgeConnectionListener.java +++ b/forge/src/main/java/me/lucko/luckperms/forge/listeners/ForgeConnectionListener.java @@ -49,7 +49,6 @@ import net.minecraftforge.eventbus.api.SubscribeEvent; import java.util.UUID; -import java.util.concurrent.CompletableFuture; public class ForgeConnectionListener extends AbstractConnectionListener { private static final ConfigurationTask.Type USER_LOGIN_TASK_TYPE = new ConfigurationTask.Type("luckperms:user_login"); diff --git a/forge/src/main/java/me/lucko/luckperms/forge/util/AsyncConfigurationTask.java b/forge/src/main/java/me/lucko/luckperms/forge/util/AsyncConfigurationTask.java index 48294016c..fd5176301 100644 --- a/forge/src/main/java/me/lucko/luckperms/forge/util/AsyncConfigurationTask.java +++ b/forge/src/main/java/me/lucko/luckperms/forge/util/AsyncConfigurationTask.java @@ -32,8 +32,6 @@ import java.util.concurrent.CompletableFuture; import java.util.function.Consumer; -import java.util.function.Function; -import java.util.function.Supplier; public class AsyncConfigurationTask implements ConfigurationTask { private final LPForgePlugin plugin; diff --git a/neoforge/loader/build.gradle b/neoforge/loader/build.gradle index 38dbed6b0..6522005e1 100644 --- a/neoforge/loader/build.gradle +++ b/neoforge/loader/build.gradle @@ -1,6 +1,7 @@ +import net.neoforged.moddevgradle.internal.RunGameTask + import java.nio.file.Files import java.nio.file.StandardCopyOption -import net.neoforged.moddevgradle.internal.RunGameTask plugins { alias(libs.plugins.shadow) diff --git a/neoforge/src/main/java/me/lucko/luckperms/neoforge/NeoForgeCommandExecutor.java b/neoforge/src/main/java/me/lucko/luckperms/neoforge/NeoForgeCommandExecutor.java index 0a5ef3767..d2c5b474d 100644 --- a/neoforge/src/main/java/me/lucko/luckperms/neoforge/NeoForgeCommandExecutor.java +++ b/neoforge/src/main/java/me/lucko/luckperms/neoforge/NeoForgeCommandExecutor.java @@ -36,11 +36,11 @@ import net.minecraft.commands.Commands; import net.minecraft.commands.arguments.EntityArgument; import net.minecraft.server.level.ServerPlayer; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.neoforge.event.RegisterCommandsEvent; import java.util.List; import java.util.ListIterator; -import net.neoforged.bus.api.SubscribeEvent; -import net.neoforged.neoforge.event.RegisterCommandsEvent; public class NeoForgeCommandExecutor extends BrigadierCommandExecutor { diff --git a/neoforge/src/main/java/me/lucko/luckperms/neoforge/capabilities/UserCapabilityImpl.java b/neoforge/src/main/java/me/lucko/luckperms/neoforge/capabilities/UserCapabilityImpl.java index eec08754f..cdaf197eb 100644 --- a/neoforge/src/main/java/me/lucko/luckperms/neoforge/capabilities/UserCapabilityImpl.java +++ b/neoforge/src/main/java/me/lucko/luckperms/neoforge/capabilities/UserCapabilityImpl.java @@ -25,7 +25,6 @@ package me.lucko.luckperms.neoforge.capabilities; -import java.util.Optional; import me.lucko.luckperms.common.cacheddata.type.PermissionCache; import me.lucko.luckperms.common.context.manager.QueryOptionsCache; import me.lucko.luckperms.common.locale.TranslationManager; @@ -40,6 +39,7 @@ import org.jetbrains.annotations.Nullable; import java.util.Locale; +import java.util.Optional; public class UserCapabilityImpl implements UserCapability { diff --git a/neoforge/src/main/java/me/lucko/luckperms/neoforge/listeners/NeoForgeConnectionListener.java b/neoforge/src/main/java/me/lucko/luckperms/neoforge/listeners/NeoForgeConnectionListener.java index 18b848f78..df1c29a44 100644 --- a/neoforge/src/main/java/me/lucko/luckperms/neoforge/listeners/NeoForgeConnectionListener.java +++ b/neoforge/src/main/java/me/lucko/luckperms/neoforge/listeners/NeoForgeConnectionListener.java @@ -31,8 +31,8 @@ import me.lucko.luckperms.common.locale.TranslationManager; import me.lucko.luckperms.common.model.User; import me.lucko.luckperms.common.plugin.util.AbstractConnectionListener; -import me.lucko.luckperms.neoforge.NeoForgeSenderFactory; import me.lucko.luckperms.neoforge.LPNeoForgePlugin; +import me.lucko.luckperms.neoforge.NeoForgeSenderFactory; import me.lucko.luckperms.neoforge.capabilities.UserCapabilityImpl; import me.lucko.luckperms.neoforge.util.AsyncConfigurationTask; import net.kyori.adventure.text.Component; @@ -42,14 +42,13 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.network.ConfigurationTask; import net.minecraft.server.network.ServerConfigurationPacketListenerImpl; - -import java.util.UUID; -import java.util.concurrent.CompletableFuture; import net.neoforged.bus.api.EventPriority; import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.neoforge.event.entity.player.PlayerEvent; import net.neoforged.neoforge.network.event.RegisterConfigurationTasksEvent; +import java.util.UUID; + public class NeoForgeConnectionListener extends AbstractConnectionListener { private static final ConfigurationTask.Type USER_LOGIN_TASK_TYPE = new ConfigurationTask.Type("luckperms:user_login"); diff --git a/neoforge/src/main/java/me/lucko/luckperms/neoforge/listeners/NeoForgePlatformListener.java b/neoforge/src/main/java/me/lucko/luckperms/neoforge/listeners/NeoForgePlatformListener.java index 1d04d8ca1..3daa3177f 100644 --- a/neoforge/src/main/java/me/lucko/luckperms/neoforge/listeners/NeoForgePlatformListener.java +++ b/neoforge/src/main/java/me/lucko/luckperms/neoforge/listeners/NeoForgePlatformListener.java @@ -35,14 +35,14 @@ import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; import net.minecraft.server.players.ServerOpList; - -import java.io.IOException; -import java.util.Locale; import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.neoforge.event.AddReloadListenerEvent; import net.neoforged.neoforge.event.CommandEvent; import net.neoforged.neoforge.event.server.ServerStartedEvent; +import java.io.IOException; +import java.util.Locale; + public class NeoForgePlatformListener { private final LPNeoForgePlugin plugin; diff --git a/neoforge/src/main/java/me/lucko/luckperms/neoforge/messaging/PluginMessageMessenger.java b/neoforge/src/main/java/me/lucko/luckperms/neoforge/messaging/PluginMessageMessenger.java index 6bfbcbd69..49fb23321 100644 --- a/neoforge/src/main/java/me/lucko/luckperms/neoforge/messaging/PluginMessageMessenger.java +++ b/neoforge/src/main/java/me/lucko/luckperms/neoforge/messaging/PluginMessageMessenger.java @@ -37,14 +37,14 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.players.PlayerList; - -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicReference; import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.neoforge.network.PacketDistributor; import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent; import net.neoforged.neoforge.network.registration.HandlerThread; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; + public class PluginMessageMessenger extends AbstractPluginMessageMessenger implements Messenger { private static final ResourceLocation CHANNEL_ID = ResourceLocation.parse(AbstractPluginMessageMessenger.CHANNEL); private static final CustomPacketPayload.Type PAYLOAD_TYPE = new CustomPacketPayload.Type<>(CHANNEL_ID); diff --git a/neoforge/src/main/java/me/lucko/luckperms/neoforge/service/NeoForgePermissionHandler.java b/neoforge/src/main/java/me/lucko/luckperms/neoforge/service/NeoForgePermissionHandler.java index 85966a01c..56e844a84 100644 --- a/neoforge/src/main/java/me/lucko/luckperms/neoforge/service/NeoForgePermissionHandler.java +++ b/neoforge/src/main/java/me/lucko/luckperms/neoforge/service/NeoForgePermissionHandler.java @@ -39,17 +39,17 @@ import net.luckperms.api.util.Tristate; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; +import net.neoforged.neoforge.server.permission.handler.IPermissionHandler; +import net.neoforged.neoforge.server.permission.nodes.PermissionDynamicContext; +import net.neoforged.neoforge.server.permission.nodes.PermissionNode; +import net.neoforged.neoforge.server.permission.nodes.PermissionType; +import net.neoforged.neoforge.server.permission.nodes.PermissionTypes; import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.Set; import java.util.UUID; -import net.neoforged.neoforge.server.permission.handler.IPermissionHandler; -import net.neoforged.neoforge.server.permission.nodes.PermissionDynamicContext; -import net.neoforged.neoforge.server.permission.nodes.PermissionNode; -import net.neoforged.neoforge.server.permission.nodes.PermissionType; -import net.neoforged.neoforge.server.permission.nodes.PermissionTypes; public class NeoForgePermissionHandler implements IPermissionHandler { public static final ResourceLocation IDENTIFIER = ResourceLocation.fromNamespaceAndPath(LPNeoForgeBootstrap.ID, "permission_handler"); diff --git a/neoforge/src/main/java/me/lucko/luckperms/neoforge/util/AsyncConfigurationTask.java b/neoforge/src/main/java/me/lucko/luckperms/neoforge/util/AsyncConfigurationTask.java index f7c34d794..1d3c42fa7 100644 --- a/neoforge/src/main/java/me/lucko/luckperms/neoforge/util/AsyncConfigurationTask.java +++ b/neoforge/src/main/java/me/lucko/luckperms/neoforge/util/AsyncConfigurationTask.java @@ -32,7 +32,6 @@ import java.util.concurrent.CompletableFuture; import java.util.function.Consumer; -import java.util.function.Supplier; public class AsyncConfigurationTask implements ConfigurationTask { private final LPNeoForgePlugin plugin; diff --git a/neoforge/src/main/java/me/lucko/luckperms/neoforge/util/NeoForgeEventBusFacade.java b/neoforge/src/main/java/me/lucko/luckperms/neoforge/util/NeoForgeEventBusFacade.java index e2cdc129f..806701557 100644 --- a/neoforge/src/main/java/me/lucko/luckperms/neoforge/util/NeoForgeEventBusFacade.java +++ b/neoforge/src/main/java/me/lucko/luckperms/neoforge/util/NeoForgeEventBusFacade.java @@ -31,6 +31,7 @@ import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.fml.ModLoadingContext; import net.neoforged.fml.event.IModBusEvent; +import net.neoforged.neoforge.common.NeoForge; import java.lang.invoke.CallSite; import java.lang.invoke.LambdaMetafactory; @@ -44,7 +45,6 @@ import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; -import net.neoforged.neoforge.common.NeoForge; /** * A utility for registering Forge listeners for methods in a jar-in-jar. From 49dd074f831304b96198ddd95a7ba0663e950273 Mon Sep 17 00:00:00 2001 From: Luis Date: Mon, 11 Nov 2024 23:17:45 +0000 Subject: [PATCH 3/8] chore(deps): upgrade Gradle and Minestom --- gradle.properties | 6 +++--- gradle/wrapper/gradle-wrapper.jar | Bin 43504 -> 43583 bytes gradle/wrapper/gradle-wrapper.properties | 2 +- minestom/build.gradle | 2 +- .../luckperms/minestom/LuckPermsMinestom.java | 13 +++++++++++++ .../luckperms/minestom/MinestomServer.java | 1 - 6 files changed, 18 insertions(+), 6 deletions(-) diff --git a/gradle.properties b/gradle.properties index ab51df5b1..75fa0d162 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -# Fabric requires some more ram. org.gradle.jvmargs=-Xmx2G -# ForgeGradle is special. -org.gradle.daemon=false +org.gradle.parallel=true +org.gradle.configuration-cache.parallel=true +org.gradle.caching=true \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 2c3521197d7c4586c843d1d3e9090525f1898cde..a4b76b9530d66f5e68d973ea569d8e19de379189 100644 GIT binary patch delta 3990 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 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 9355b4155..94113f200 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/minestom/build.gradle b/minestom/build.gradle index 7971f1c07..9ff590ff5 100644 --- a/minestom/build.gradle +++ b/minestom/build.gradle @@ -13,7 +13,7 @@ repositories { } dependencies { - var minestom = "1_21_2-b4bd4ea221" + var minestom = "1_21_2-888f9896cc" api(project(":common")) { // exclude default config providers as they are inaccessible from the minestom module anyway diff --git a/minestom/src/main/java/me/lucko/luckperms/minestom/LuckPermsMinestom.java b/minestom/src/main/java/me/lucko/luckperms/minestom/LuckPermsMinestom.java index 4afb615b6..3fee85a2e 100644 --- a/minestom/src/main/java/me/lucko/luckperms/minestom/LuckPermsMinestom.java +++ b/minestom/src/main/java/me/lucko/luckperms/minestom/LuckPermsMinestom.java @@ -12,6 +12,7 @@ import net.luckperms.api.LuckPerms; import net.luckperms.api.LuckPermsProvider; import net.minestom.server.command.builder.Command; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; @@ -44,6 +45,7 @@ public interface Builder { * @deprecated use {@link Builder#commandRegistry(CommandRegistry)} */ @Deprecated + @Contract("_ -> this") default @NotNull Builder commands(boolean enabled) { return enabled ? this.commandRegistry(CommandRegistry.minestom()) : this.commandRegistry(null); } @@ -60,12 +62,14 @@ public interface Builder { * @param handler the command registry handler * @return the builder instance */ + @Contract("_ -> this") @NotNull Builder commandRegistry(@Nullable CommandRegistry handler); /** * Sets the command registry handler where LuckPerms commands * should be registered. */ + @Contract("_, _ -> this") default @NotNull Builder commandRegistry( @NotNull Consumer register, @NotNull Consumer unregister @@ -79,6 +83,7 @@ public interface Builder { * @param provider the provider to add * @return the builder instance */ + @Contract("_ -> this") @NotNull Builder contextProvider(@NotNull ContextProvider provider); /** @@ -87,6 +92,7 @@ public interface Builder { * @param providers the providers to add * @return the builder instance */ + @Contract("_ -> this") @NotNull Builder contextProviders(@NotNull ContextProvider... providers); /** @@ -95,6 +101,7 @@ public interface Builder { * @param providers the providers to add * @return the builder instance */ + @Contract("_ -> this") @NotNull Builder contextProviders(@NotNull Iterable providers); @@ -104,6 +111,7 @@ public interface Builder { * @param permission the permission to suggest * @return the builder instance */ + @Contract("_ -> this") @NotNull Builder permissionSuggestion(@NotNull String permission); /** @@ -112,6 +120,7 @@ public interface Builder { * @param permissions the permissions to suggest * @return the builder instance */ + @Contract("_ -> this") @NotNull Builder permissionSuggestions(@NotNull String... permissions); /** @@ -120,6 +129,7 @@ public interface Builder { * @param permissions the permissions to suggest * @return the builder instance */ + @Contract("_ -> this") @NotNull Builder permissionSuggestions(@NotNull Iterable permissions); @@ -135,6 +145,7 @@ public interface Builder { * @param adapter the adapter to use * @return the builder instance */ + @Contract("_ -> this") @NotNull Builder configurationAdapter(@NotNull Function adapter); @@ -145,6 +156,7 @@ public interface Builder { * @param enabled if the dependency manager should be enabled * @return the builder instance */ + @Contract("_ -> this") @NotNull Builder dependencyManager(boolean enabled); @@ -154,6 +166,7 @@ public interface Builder { * @param logger the logger to use * @return the builder instance */ + @Contract("_ -> this") @NotNull Builder logger(@NotNull Logger logger); diff --git a/minestom/src/test/java/me/lucko/luckperms/minestom/MinestomServer.java b/minestom/src/test/java/me/lucko/luckperms/minestom/MinestomServer.java index 9b0921186..49d8d8be5 100644 --- a/minestom/src/test/java/me/lucko/luckperms/minestom/MinestomServer.java +++ b/minestom/src/test/java/me/lucko/luckperms/minestom/MinestomServer.java @@ -26,7 +26,6 @@ import net.minestom.server.instance.InstanceContainer; import net.minestom.server.instance.block.Block; import net.minestom.server.network.ConnectionManager; -import net.minestom.server.network.player.GameProfile; public final class MinestomServer { From 2e67011f455edb648e98c038eb25b6fc78865db9 Mon Sep 17 00:00:00 2001 From: Luck Date: Wed, 4 Dec 2024 11:25:06 +0000 Subject: [PATCH 4/8] Refactor some unit tests --- .../implementation/sql/SchemaReader.java | 26 +++++++++++-------- .../implementation/sql/SchemaReaderTest.java | 26 ++++++++++++++++++- .../standalone/CommandsIntegrationTest.java | 4 +-- .../ImportExportIntegrationTest.java | 4 +-- .../standalone/utils/TestPluginProvider.java | 2 +- 5 files changed, 45 insertions(+), 17 deletions(-) diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/SchemaReader.java b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/SchemaReader.java index f80d9fc57..c40fc6e17 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/SchemaReader.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/SchemaReader.java @@ -81,6 +81,18 @@ public static List getStatements(InputStream is) throws IOException { return queries; } + public static String tableFromStatement(String statement) { + Matcher table = CREATE_TABLE_PATTERN.matcher(statement); + if (table.matches()) { + return table.group(1).toLowerCase(Locale.ROOT); + } + Matcher index = CREATE_INDEX_PATTERN.matcher(statement); + if (index.matches()) { + return index.group(1).toLowerCase(Locale.ROOT); + } + throw new IllegalArgumentException("Unknown statement type: " + statement); + } + /** * Filters which statements should be executed based on the current list of tables in the database * @@ -89,16 +101,8 @@ public static List getStatements(InputStream is) throws IOException { * @return the filtered list of statements */ public static List filterStatements(List statements, List currentTables) { - return statements.stream().filter(statement -> { - Matcher table = CREATE_TABLE_PATTERN.matcher(statement); - if (table.matches()) { - return !currentTables.contains(table.group(1).toLowerCase(Locale.ROOT)); - } - Matcher index = CREATE_INDEX_PATTERN.matcher(statement); - if (index.matches()) { - return !currentTables.contains(index.group(1).toLowerCase(Locale.ROOT)); - } - throw new IllegalArgumentException("Unknown statement type: " + statement); - }).collect(Collectors.toList()); + return statements.stream() + .filter(statement -> !currentTables.contains(tableFromStatement(statement))) + .collect(Collectors.toList()); } } diff --git a/common/src/test/java/me/lucko/luckperms/common/storage/implementation/sql/SchemaReaderTest.java b/common/src/test/java/me/lucko/luckperms/common/storage/implementation/sql/SchemaReaderTest.java index 45d20c8a1..8b926dd9e 100644 --- a/common/src/test/java/me/lucko/luckperms/common/storage/implementation/sql/SchemaReaderTest.java +++ b/common/src/test/java/me/lucko/luckperms/common/storage/implementation/sql/SchemaReaderTest.java @@ -25,15 +25,18 @@ package me.lucko.luckperms.common.storage.implementation.sql; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; import org.junit.jupiter.api.Test; -import org.testcontainers.shaded.com.google.common.collect.ImmutableList; import java.io.IOException; import java.io.InputStream; import java.util.List; +import java.util.Set; import java.util.stream.Collectors; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class SchemaReaderTest { @@ -111,6 +114,27 @@ public void testReadPostgres() throws IOException { ), readStatements("postgresql")); } + @Test + public void testTableFromStatement() throws IOException { + Set allowedTables = ImmutableSet.of( + "luckperms_user_permissions", + "luckperms_group_permissions", + "luckperms_players", + "luckperms_groups", + "luckperms_actions", + "luckperms_tracks" + ); + + for (String type : new String[]{"h2", "mariadb", "mysql", "postgresql", "sqlite"}) { + List tables = readStatements(type).stream() + .map(s -> s.replace("{prefix}", "luckperms_")) + .map(SchemaReader::tableFromStatement) + .collect(Collectors.toList()); + + assertTrue(allowedTables.containsAll(tables)); + } + } + @Test public void testFilter() throws IOException { StatementProcessor processor = s -> s.replace("{prefix}", "luckperms_"); diff --git a/standalone/src/test/java/me/lucko/luckperms/standalone/CommandsIntegrationTest.java b/standalone/src/test/java/me/lucko/luckperms/standalone/CommandsIntegrationTest.java index 362825e84..4e5780141 100644 --- a/standalone/src/test/java/me/lucko/luckperms/standalone/CommandsIntegrationTest.java +++ b/standalone/src/test/java/me/lucko/luckperms/standalone/CommandsIntegrationTest.java @@ -25,6 +25,8 @@ package me.lucko.luckperms.standalone; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; import me.lucko.luckperms.common.model.Group; import me.lucko.luckperms.common.model.User; import me.lucko.luckperms.common.node.types.Inheritance; @@ -36,8 +38,6 @@ import net.luckperms.api.event.log.LogNotifyEvent; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -import org.testcontainers.shaded.com.google.common.collect.ImmutableMap; -import org.testcontainers.shaded.com.google.common.collect.ImmutableSet; import java.nio.file.Path; import java.util.HashMap; diff --git a/standalone/src/test/java/me/lucko/luckperms/standalone/ImportExportIntegrationTest.java b/standalone/src/test/java/me/lucko/luckperms/standalone/ImportExportIntegrationTest.java index 2600033d5..cea228030 100644 --- a/standalone/src/test/java/me/lucko/luckperms/standalone/ImportExportIntegrationTest.java +++ b/standalone/src/test/java/me/lucko/luckperms/standalone/ImportExportIntegrationTest.java @@ -25,6 +25,8 @@ package me.lucko.luckperms.standalone; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; import com.google.gson.Gson; import com.google.gson.JsonObject; import me.lucko.luckperms.common.commands.misc.ExportCommand; @@ -38,8 +40,6 @@ import me.lucko.luckperms.standalone.utils.TestPluginProvider; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -import org.testcontainers.shaded.com.google.common.collect.ImmutableList; -import org.testcontainers.shaded.com.google.common.collect.ImmutableSet; import java.io.BufferedReader; import java.io.IOException; diff --git a/standalone/src/test/java/me/lucko/luckperms/standalone/utils/TestPluginProvider.java b/standalone/src/test/java/me/lucko/luckperms/standalone/utils/TestPluginProvider.java index 89f6ba076..de3f394a1 100644 --- a/standalone/src/test/java/me/lucko/luckperms/standalone/utils/TestPluginProvider.java +++ b/standalone/src/test/java/me/lucko/luckperms/standalone/utils/TestPluginProvider.java @@ -25,9 +25,9 @@ package me.lucko.luckperms.standalone.utils; +import com.google.common.collect.ImmutableMap; import me.lucko.luckperms.standalone.app.LuckPermsApplication; import me.lucko.luckperms.standalone.utils.TestPluginBootstrap.TestPlugin; -import org.testcontainers.shaded.com.google.common.collect.ImmutableMap; import java.nio.file.Path; import java.util.HashMap; From 29c93fac4fc55040f661ca9f3ef6b9e120249e30 Mon Sep 17 00:00:00 2001 From: Luck Date: Wed, 4 Dec 2024 11:27:14 +0000 Subject: [PATCH 5/8] Add note about shading LuckPerms API into plugin jars --- api/src/main/java/net/luckperms/api/LuckPermsProvider.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/net/luckperms/api/LuckPermsProvider.java b/api/src/main/java/net/luckperms/api/LuckPermsProvider.java index 4f9579aa8..4f36c2d28 100644 --- a/api/src/main/java/net/luckperms/api/LuckPermsProvider.java +++ b/api/src/main/java/net/luckperms/api/LuckPermsProvider.java @@ -79,7 +79,8 @@ private static final class NotLoadedException extends IllegalStateException { " a) the LuckPerms plugin is not installed or it failed to enable\n" + " b) the plugin in the stacktrace does not declare a dependency on LuckPerms\n" + " c) the plugin in the stacktrace is retrieving the API before the plugin 'enable' phase\n" + - " (call the #get method in onEnable, not the constructor!)\n"; + " (call the #get method in onEnable, not the constructor!)\n" + + " d) the plugin in the stacktrace is incorrectly 'shading' the LuckPerms API into its jar\n"; NotLoadedException() { super(MESSAGE); From b18717edefabae99a8aa75ee5f49cda2e2ee823c Mon Sep 17 00:00:00 2001 From: Luck Date: Wed, 4 Dec 2024 20:39:55 +0000 Subject: [PATCH 6/8] Remove NeoForge capability attachment --- .../bungee/context/BungeeContextManager.java | 47 +---- .../context/manager/ContextManager.java | 3 +- .../context/manager/InlineContextManager.java | 90 ++++++++++ .../manager/InlineQueryOptionsSupplier.java | 44 ----- neoforge/build.gradle | 1 - neoforge/loader/build.gradle | 2 - neoforge/neoforge-api/build.gradle | 16 -- .../neoforge/capabilities/UserCapability.java | 83 --------- .../luckperms/neoforge/LPNeoForgePlugin.java | 4 - .../neoforge/NeoForgeSenderFactory.java | 28 ++- .../capabilities/UserCapabilityImpl.java | 163 ------------------ .../capabilities/UserCapabilityListener.java | 69 -------- .../context/NeoForgeContextManager.java | 24 +-- .../listeners/NeoForgeConnectionListener.java | 4 - .../service/NeoForgePermissionHandler.java | 10 +- .../neoforge/util/BrigadierInjector.java | 25 +-- settings.gradle | 1 - .../sponge/context/SpongeContextManager.java | 45 +---- .../context/VelocityContextManager.java | 38 +--- 19 files changed, 125 insertions(+), 572 deletions(-) create mode 100644 common/src/main/java/me/lucko/luckperms/common/context/manager/InlineContextManager.java delete mode 100644 common/src/main/java/me/lucko/luckperms/common/context/manager/InlineQueryOptionsSupplier.java delete mode 100644 neoforge/neoforge-api/build.gradle delete mode 100644 neoforge/neoforge-api/src/main/java/me/lucko/luckperms/neoforge/capabilities/UserCapability.java delete mode 100644 neoforge/src/main/java/me/lucko/luckperms/neoforge/capabilities/UserCapabilityImpl.java delete mode 100644 neoforge/src/main/java/me/lucko/luckperms/neoforge/capabilities/UserCapabilityListener.java diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/context/BungeeContextManager.java b/bungee/src/main/java/me/lucko/luckperms/bungee/context/BungeeContextManager.java index d4772301a..1529c184d 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/context/BungeeContextManager.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/context/BungeeContextManager.java @@ -25,25 +25,13 @@ package me.lucko.luckperms.bungee.context; -import com.github.benmanes.caffeine.cache.LoadingCache; import me.lucko.luckperms.bungee.LPBungeePlugin; -import me.lucko.luckperms.common.context.manager.ContextManager; -import me.lucko.luckperms.common.context.manager.InlineQueryOptionsSupplier; -import me.lucko.luckperms.common.context.manager.QueryOptionsSupplier; -import me.lucko.luckperms.common.util.CaffeineFactory; -import net.luckperms.api.context.ImmutableContextSet; -import net.luckperms.api.query.QueryOptions; +import me.lucko.luckperms.common.context.manager.InlineContextManager; import net.md_5.bungee.api.connection.ProxiedPlayer; import java.util.UUID; -import java.util.concurrent.TimeUnit; - -public class BungeeContextManager extends ContextManager { - - private final LoadingCache contextsCache = CaffeineFactory.newBuilder() - .expireAfterWrite(50, TimeUnit.MILLISECONDS) - .build(this::calculate); +public class BungeeContextManager extends InlineContextManager { public BungeeContextManager(LPBungeePlugin plugin) { super(plugin, ProxiedPlayer.class, ProxiedPlayer.class); } @@ -52,35 +40,4 @@ public BungeeContextManager(LPBungeePlugin plugin) { public UUID getUniqueId(ProxiedPlayer player) { return player.getUniqueId(); } - - @Override - public QueryOptionsSupplier getCacheFor(ProxiedPlayer subject) { - if (subject == null) { - throw new NullPointerException("subject"); - } - - return new InlineQueryOptionsSupplier<>(subject, this.contextsCache); - } - - // override getContext, getQueryOptions and invalidateCache to skip the QueryOptionsSupplier - @Override - public ImmutableContextSet getContext(ProxiedPlayer subject) { - return getQueryOptions(subject).context(); - } - - @Override - public QueryOptions getQueryOptions(ProxiedPlayer subject) { - return this.contextsCache.get(subject); - } - - @Override - protected void invalidateCache(ProxiedPlayer subject) { - this.contextsCache.invalidate(subject); - } - - @Override - public QueryOptions formQueryOptions(ProxiedPlayer subject, ImmutableContextSet contextSet) { - return formQueryOptions(contextSet); - } - } diff --git a/common/src/main/java/me/lucko/luckperms/common/context/manager/ContextManager.java b/common/src/main/java/me/lucko/luckperms/common/context/manager/ContextManager.java index 5b95b8f6a..4cc2d7a8b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/context/manager/ContextManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/context/manager/ContextManager.java @@ -48,7 +48,8 @@ /** * Base implementation of {@link ContextManager} which caches content lookups. * - * @param the calculator type + * @param the subject type + * @param

the player type */ public abstract class ContextManager { diff --git a/common/src/main/java/me/lucko/luckperms/common/context/manager/InlineContextManager.java b/common/src/main/java/me/lucko/luckperms/common/context/manager/InlineContextManager.java new file mode 100644 index 000000000..ced09b136 --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/common/context/manager/InlineContextManager.java @@ -0,0 +1,90 @@ +/* + * This file is part of LuckPerms, licensed under the MIT License. + * + * Copyright (c) lucko (Luck) + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.lucko.luckperms.common.context.manager; + +import com.github.benmanes.caffeine.cache.LoadingCache; +import me.lucko.luckperms.common.plugin.LuckPermsPlugin; +import me.lucko.luckperms.common.util.CaffeineFactory; +import net.luckperms.api.context.ImmutableContextSet; +import net.luckperms.api.query.QueryOptions; + +import java.util.concurrent.TimeUnit; + +public abstract class InlineContextManager extends ContextManager { + + private final LoadingCache contextsCache = CaffeineFactory.newBuilder() + .expireAfterWrite(50, TimeUnit.MILLISECONDS) + .build(this::calculate); + + protected InlineContextManager(LuckPermsPlugin plugin, Class subjectClass, Class

playerClass) { + super(plugin, subjectClass, playerClass); + } + + @Override + public final QueryOptionsSupplier getCacheFor(S subject) { + if (subject == null) { + throw new NullPointerException("subject"); + } + + return new InlineQueryOptionsSupplier<>(subject, this.contextsCache); + } + + // override getContext, getQueryOptions and invalidateCache to skip the QueryOptionsSupplier + @Override + public final ImmutableContextSet getContext(S subject) { + return getQueryOptions(subject).context(); + } + + @Override + public final QueryOptions getQueryOptions(S subject) { + return this.contextsCache.get(subject); + } + + @Override + protected final void invalidateCache(S subject) { + this.contextsCache.invalidate(subject); + } + + @Override + public QueryOptions formQueryOptions(S subject, ImmutableContextSet contextSet) { + return formQueryOptions(contextSet); + } + + private static final class InlineQueryOptionsSupplier implements QueryOptionsSupplier { + private final T key; + private final LoadingCache cache; + + InlineQueryOptionsSupplier(T key, LoadingCache cache) { + this.key = key; + this.cache = cache; + } + + @Override + public QueryOptions getQueryOptions() { + return this.cache.get(this.key); + } + } +} diff --git a/common/src/main/java/me/lucko/luckperms/common/context/manager/InlineQueryOptionsSupplier.java b/common/src/main/java/me/lucko/luckperms/common/context/manager/InlineQueryOptionsSupplier.java deleted file mode 100644 index b4d7b6d5d..000000000 --- a/common/src/main/java/me/lucko/luckperms/common/context/manager/InlineQueryOptionsSupplier.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * This file is part of LuckPerms, licensed under the MIT License. - * - * Copyright (c) lucko (Luck) - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package me.lucko.luckperms.common.context.manager; - -import com.github.benmanes.caffeine.cache.LoadingCache; -import net.luckperms.api.query.QueryOptions; - -public final class InlineQueryOptionsSupplier implements QueryOptionsSupplier { - private final T key; - private final LoadingCache cache; - - public InlineQueryOptionsSupplier(T key, LoadingCache cache) { - this.key = key; - this.cache = cache; - } - - @Override - public QueryOptions getQueryOptions() { - return this.cache.get(this.key); - } -} diff --git a/neoforge/build.gradle b/neoforge/build.gradle index 8e1adb360..4ea4651d8 100644 --- a/neoforge/build.gradle +++ b/neoforge/build.gradle @@ -26,7 +26,6 @@ neoForge { dependencies { add('shade', project(':common')) compileOnly project(':common:loader-utils') - compileOnly project(':neoforge:neoforge-api') } shadowJar { diff --git a/neoforge/loader/build.gradle b/neoforge/loader/build.gradle index 6522005e1..3d698ed58 100644 --- a/neoforge/loader/build.gradle +++ b/neoforge/loader/build.gradle @@ -47,12 +47,10 @@ configurations.implementation { dependencies { add('shade', project(':api')) add('shade', project(':common:loader-utils')) - add('shade', project(':neoforge:neoforge-api')) } build { dependsOn(":neoforge:build") - dependsOn(":neoforge:neoforge-api:build") } jar { diff --git a/neoforge/neoforge-api/build.gradle b/neoforge/neoforge-api/build.gradle deleted file mode 100644 index b231d62e4..000000000 --- a/neoforge/neoforge-api/build.gradle +++ /dev/null @@ -1,16 +0,0 @@ -plugins { - alias(libs.plugins.moddevgradle) -} - -sourceCompatibility = 17 -targetCompatibility = 21 - -neoForge { - version = project.neoForgeVersion - - validateAccessTransformers = true -} - -dependencies { - implementation project(':api') -} diff --git a/neoforge/neoforge-api/src/main/java/me/lucko/luckperms/neoforge/capabilities/UserCapability.java b/neoforge/neoforge-api/src/main/java/me/lucko/luckperms/neoforge/capabilities/UserCapability.java deleted file mode 100644 index 5fbdb85b2..000000000 --- a/neoforge/neoforge-api/src/main/java/me/lucko/luckperms/neoforge/capabilities/UserCapability.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * This file is part of LuckPerms, licensed under the MIT License. - * - * Copyright (c) lucko (Luck) - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package me.lucko.luckperms.neoforge.capabilities; - -import net.luckperms.api.query.QueryOptions; -import net.luckperms.api.util.Tristate; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.level.ServerPlayer; -import net.neoforged.neoforge.capabilities.EntityCapability; - -/** - * A NeoForge {@link EntityCapability} that attaches LuckPerms functionality onto {@link ServerPlayer}s. - */ -public interface UserCapability { - - /** - * The identifier used for the capability - */ - ResourceLocation IDENTIFIER = ResourceLocation.fromNamespaceAndPath("luckperms", "user"); - - /** - * The capability instance. - */ - EntityCapability CAPABILITY = EntityCapability.createVoid(IDENTIFIER, UserCapability.class); - - /** - * Checks for a permission. - * - * @param permission the permission - * @return the result - */ - default boolean hasPermission(String permission) { - return checkPermission(permission).asBoolean(); - } - - /** - * Runs a permission check. - * - * @param permission the permission - * @return the result - */ - Tristate checkPermission(String permission); - - /** - * Runs a permission check. - * - * @param permission the permission - * @param queryOptions the query options - * @return the result - */ - Tristate checkPermission(String permission, QueryOptions queryOptions); - - /** - * Gets the user's currently query options. - * - * @return the current query options for the user - */ - QueryOptions getQueryOptions(); - -} diff --git a/neoforge/src/main/java/me/lucko/luckperms/neoforge/LPNeoForgePlugin.java b/neoforge/src/main/java/me/lucko/luckperms/neoforge/LPNeoForgePlugin.java index 453614480..c2bf68c46 100644 --- a/neoforge/src/main/java/me/lucko/luckperms/neoforge/LPNeoForgePlugin.java +++ b/neoforge/src/main/java/me/lucko/luckperms/neoforge/LPNeoForgePlugin.java @@ -41,7 +41,6 @@ import me.lucko.luckperms.common.sender.DummyConsoleSender; import me.lucko.luckperms.common.sender.Sender; import me.lucko.luckperms.neoforge.calculator.NeoForgeCalculatorFactory; -import me.lucko.luckperms.neoforge.capabilities.UserCapabilityListener; import me.lucko.luckperms.neoforge.context.NeoForgeContextManager; import me.lucko.luckperms.neoforge.context.NeoForgePlayerCalculator; import me.lucko.luckperms.neoforge.listeners.NeoForgeAutoOpListener; @@ -93,9 +92,6 @@ protected void registerEarlyListeners() { NeoForgePlatformListener platformListener = new NeoForgePlatformListener(this); this.bootstrap.registerListeners(platformListener); - UserCapabilityListener userCapabilityListener = new UserCapabilityListener(); - this.bootstrap.registerListeners(userCapabilityListener); - NeoForgePermissionHandlerListener permissionHandlerListener = new NeoForgePermissionHandlerListener(this); this.bootstrap.registerListeners(permissionHandlerListener); diff --git a/neoforge/src/main/java/me/lucko/luckperms/neoforge/NeoForgeSenderFactory.java b/neoforge/src/main/java/me/lucko/luckperms/neoforge/NeoForgeSenderFactory.java index 25049df2e..1dbd1521d 100644 --- a/neoforge/src/main/java/me/lucko/luckperms/neoforge/NeoForgeSenderFactory.java +++ b/neoforge/src/main/java/me/lucko/luckperms/neoforge/NeoForgeSenderFactory.java @@ -28,15 +28,15 @@ import com.mojang.brigadier.ParseResults; import me.lucko.luckperms.common.cacheddata.result.TristateResult; import me.lucko.luckperms.common.locale.TranslationManager; +import me.lucko.luckperms.common.model.User; import me.lucko.luckperms.common.query.QueryOptionsImpl; import me.lucko.luckperms.common.sender.Sender; import me.lucko.luckperms.common.sender.SenderFactory; import me.lucko.luckperms.common.verbose.VerboseCheckTarget; import me.lucko.luckperms.common.verbose.event.CheckOrigin; -import me.lucko.luckperms.neoforge.capabilities.UserCapability; -import me.lucko.luckperms.neoforge.capabilities.UserCapabilityImpl; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; +import net.luckperms.api.query.QueryOptions; import net.luckperms.api.util.Tristate; import net.minecraft.commands.CommandSource; import net.minecraft.commands.CommandSourceStack; @@ -72,24 +72,22 @@ protected String getName(CommandSourceStack commandSource) { @Override protected void sendMessage(CommandSourceStack sender, Component message) { - Locale locale; - if (sender.getEntity() instanceof ServerPlayer) { - ServerPlayer player = (ServerPlayer) sender.getEntity(); - UserCapabilityImpl user = UserCapabilityImpl.get(player); - locale = user.getLocale(player); - } else { - locale = null; - } - + Locale locale = sender.getEntity() instanceof ServerPlayer player + ? TranslationManager.parseLocale(player.getLanguage()) + : null; sender.sendSuccess(() -> toNativeText(TranslationManager.render(message, locale)), false); } @Override protected Tristate getPermissionValue(CommandSourceStack commandSource, String node) { - if (commandSource.getEntity() instanceof ServerPlayer) { - ServerPlayer player = (ServerPlayer) commandSource.getEntity(); - UserCapability user = UserCapabilityImpl.get(player); - return user.checkPermission(node); + if (commandSource.getEntity() instanceof ServerPlayer player) { + User user = getPlugin().getUserManager().getIfLoaded(player.getUUID()); + if (user == null) { + return Tristate.UNDEFINED; + } + + QueryOptions queryOptions = getPlugin().getContextManager().getQueryOptions(player); + return user.getCachedData().getPermissionData(queryOptions).checkPermission(node, CheckOrigin.PLATFORM_API_HAS_PERMISSION).result(); } VerboseCheckTarget target = VerboseCheckTarget.internal(commandSource.getTextName()); diff --git a/neoforge/src/main/java/me/lucko/luckperms/neoforge/capabilities/UserCapabilityImpl.java b/neoforge/src/main/java/me/lucko/luckperms/neoforge/capabilities/UserCapabilityImpl.java deleted file mode 100644 index cdaf197eb..000000000 --- a/neoforge/src/main/java/me/lucko/luckperms/neoforge/capabilities/UserCapabilityImpl.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * This file is part of LuckPerms, licensed under the MIT License. - * - * Copyright (c) lucko (Luck) - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package me.lucko.luckperms.neoforge.capabilities; - -import me.lucko.luckperms.common.cacheddata.type.PermissionCache; -import me.lucko.luckperms.common.context.manager.QueryOptionsCache; -import me.lucko.luckperms.common.locale.TranslationManager; -import me.lucko.luckperms.common.model.User; -import me.lucko.luckperms.common.verbose.event.CheckOrigin; -import me.lucko.luckperms.neoforge.context.NeoForgeContextManager; -import net.luckperms.api.query.QueryOptions; -import net.luckperms.api.util.Tristate; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.entity.player.Player; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Locale; -import java.util.Optional; - -public class UserCapabilityImpl implements UserCapability { - - private static Optional getCapability(Player player) { - return Optional.ofNullable(player.getCapability(CAPABILITY)); - } - - /** - * Gets a {@link UserCapability} for a given {@link ServerPlayer}. - * - * @param player the player - * @return the capability - */ - public static @NotNull UserCapabilityImpl get(@NotNull Player player) { - return (UserCapabilityImpl) getCapability(player).orElseThrow(() -> new IllegalStateException("Capability missing for " + player.getUUID())); - } - - /** - * Gets a {@link UserCapability} for a given {@link ServerPlayer}. - * - * @param player the player - * @return the capability, or null - */ - public static @Nullable UserCapabilityImpl getNullable(@NotNull Player player) { - return (UserCapabilityImpl) getCapability(player).orElse(null); - } - - private boolean initialised = false; - private boolean invalidated = false; - - private User user; - private QueryOptionsCache queryOptionsCache; - private String language; - private Locale locale; - - public UserCapabilityImpl() { - - } - - public void initialise(UserCapabilityImpl previous) { - this.user = previous.user; - this.queryOptionsCache = previous.queryOptionsCache; - this.language = previous.language; - this.locale = previous.locale; - this.initialised = true; - } - - public void initialise(User user, ServerPlayer player, NeoForgeContextManager contextManager) { - this.user = user; - this.queryOptionsCache = new QueryOptionsCache<>(player, contextManager); - this.initialised = true; - } - - private void assertInitialised() { - if (!this.initialised) { - throw new IllegalStateException("Capability has not been initialised"); - } - if (this.invalidated) { - throw new IllegalStateException("Capability has been invalidated"); - } - } - - public void invalidate() { - this.invalidated = false; - this.user = null; - this.queryOptionsCache = null; - this.language = null; - this.locale = null; - } - - @Override - public Tristate checkPermission(String permission) { - assertInitialised(); - - if (permission == null) { - throw new NullPointerException("permission"); - } - - return checkPermission(permission, this.queryOptionsCache.getQueryOptions()); - } - - @Override - public Tristate checkPermission(String permission, QueryOptions queryOptions) { - assertInitialised(); - - if (permission == null) { - throw new NullPointerException("permission"); - } - - if (queryOptions == null) { - throw new NullPointerException("queryOptions"); - } - - PermissionCache cache = this.user.getCachedData().getPermissionData(queryOptions); - return cache.checkPermission(permission, CheckOrigin.PLATFORM_API_HAS_PERMISSION).result(); - } - - public User getUser() { - assertInitialised(); - return this.user; - } - - @Override - public QueryOptions getQueryOptions() { - return getQueryOptionsCache().getQueryOptions(); - } - - public QueryOptionsCache getQueryOptionsCache() { - assertInitialised(); - return this.queryOptionsCache; - } - - public Locale getLocale(ServerPlayer player) { - if (this.language == null || !this.language.equals(player.getLanguage())) { - this.language = player.getLanguage(); - this.locale = TranslationManager.parseLocale(this.language); - } - - return this.locale; - } -} \ No newline at end of file diff --git a/neoforge/src/main/java/me/lucko/luckperms/neoforge/capabilities/UserCapabilityListener.java b/neoforge/src/main/java/me/lucko/luckperms/neoforge/capabilities/UserCapabilityListener.java deleted file mode 100644 index c34f66473..000000000 --- a/neoforge/src/main/java/me/lucko/luckperms/neoforge/capabilities/UserCapabilityListener.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * This file is part of LuckPerms, licensed under the MIT License. - * - * Copyright (c) lucko (Luck) - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package me.lucko.luckperms.neoforge.capabilities; - -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.entity.EntityType; -import net.minecraft.world.entity.player.Player; -import net.neoforged.bus.api.SubscribeEvent; -import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; -import net.neoforged.neoforge.event.entity.player.PlayerEvent; - -public class UserCapabilityListener { - - @SubscribeEvent - public void onRegisterCapabilities(RegisterCapabilitiesEvent event) { - event.registerEntity( - UserCapability.CAPABILITY, - EntityType.PLAYER, - (player, ctx) -> { - if (!(player instanceof ServerPlayer)) { - // Don't attach to LocalPlayer - return null; - } - return new UserCapabilityImpl(); - } - ); - } - - @SubscribeEvent - public void onPlayerClone(PlayerEvent.Clone event) { - Player previousPlayer = event.getOriginal(); - Player currentPlayer = event.getEntity(); - - try { - UserCapabilityImpl previous = UserCapabilityImpl.get(previousPlayer); - UserCapabilityImpl current = UserCapabilityImpl.get(currentPlayer); - - current.initialise(previous); - previous.invalidate(); - current.getQueryOptionsCache().invalidate(); - } catch (IllegalStateException e) { - // continue on if we cannot copy original data - } - } - -} diff --git a/neoforge/src/main/java/me/lucko/luckperms/neoforge/context/NeoForgeContextManager.java b/neoforge/src/main/java/me/lucko/luckperms/neoforge/context/NeoForgeContextManager.java index 8aca67312..41632e229 100644 --- a/neoforge/src/main/java/me/lucko/luckperms/neoforge/context/NeoForgeContextManager.java +++ b/neoforge/src/main/java/me/lucko/luckperms/neoforge/context/NeoForgeContextManager.java @@ -26,10 +26,8 @@ package me.lucko.luckperms.neoforge.context; import me.lucko.luckperms.common.config.ConfigKeys; -import me.lucko.luckperms.common.context.manager.ContextManager; -import me.lucko.luckperms.common.context.manager.QueryOptionsCache; +import me.lucko.luckperms.common.context.manager.InlineContextManager; import me.lucko.luckperms.neoforge.LPNeoForgePlugin; -import me.lucko.luckperms.neoforge.capabilities.UserCapabilityImpl; import net.luckperms.api.context.ImmutableContextSet; import net.luckperms.api.query.OptionKey; import net.luckperms.api.query.QueryOptions; @@ -37,7 +35,7 @@ import java.util.UUID; -public class NeoForgeContextManager extends ContextManager { +public class NeoForgeContextManager extends InlineContextManager { public static final OptionKey INTEGRATED_SERVER_OWNER = OptionKey.of("integrated_server_owner", Boolean.class); public NeoForgeContextManager(LPNeoForgePlugin plugin) { @@ -49,15 +47,6 @@ public UUID getUniqueId(ServerPlayer player) { return player.getUUID(); } - @Override - public QueryOptionsCache getCacheFor(ServerPlayer subject) { - if (subject == null) { - throw new NullPointerException("subject"); - } - - return UserCapabilityImpl.get(subject).getQueryOptionsCache(); - } - @Override public QueryOptions formQueryOptions(ServerPlayer subject, ImmutableContextSet contextSet) { QueryOptions.Builder builder = this.plugin.getConfiguration().get(ConfigKeys.GLOBAL_QUERY_OPTIONS).toBuilder(); @@ -67,13 +56,4 @@ public QueryOptions formQueryOptions(ServerPlayer subject, ImmutableContextSet c return builder.context(contextSet).build(); } - - @Override - public void invalidateCache(ServerPlayer subject) { - UserCapabilityImpl capability = UserCapabilityImpl.getNullable(subject); - if (capability != null) { - capability.getQueryOptionsCache().invalidate(); - } - } - } diff --git a/neoforge/src/main/java/me/lucko/luckperms/neoforge/listeners/NeoForgeConnectionListener.java b/neoforge/src/main/java/me/lucko/luckperms/neoforge/listeners/NeoForgeConnectionListener.java index df1c29a44..4f703141a 100644 --- a/neoforge/src/main/java/me/lucko/luckperms/neoforge/listeners/NeoForgeConnectionListener.java +++ b/neoforge/src/main/java/me/lucko/luckperms/neoforge/listeners/NeoForgeConnectionListener.java @@ -33,7 +33,6 @@ import me.lucko.luckperms.common.plugin.util.AbstractConnectionListener; import me.lucko.luckperms.neoforge.LPNeoForgePlugin; import me.lucko.luckperms.neoforge.NeoForgeSenderFactory; -import me.lucko.luckperms.neoforge.capabilities.UserCapabilityImpl; import me.lucko.luckperms.neoforge.util.AsyncConfigurationTask; import net.kyori.adventure.text.Component; import net.minecraft.network.Connection; @@ -146,9 +145,6 @@ public void onPlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent event) { } } - // initialise capability - UserCapabilityImpl userCapability = UserCapabilityImpl.get(player); - userCapability.initialise(user, player, this.plugin.getContextManager()); this.plugin.getContextManager().signalContextUpdate(player); } diff --git a/neoforge/src/main/java/me/lucko/luckperms/neoforge/service/NeoForgePermissionHandler.java b/neoforge/src/main/java/me/lucko/luckperms/neoforge/service/NeoForgePermissionHandler.java index 56e844a84..1b9fbd5e1 100644 --- a/neoforge/src/main/java/me/lucko/luckperms/neoforge/service/NeoForgePermissionHandler.java +++ b/neoforge/src/main/java/me/lucko/luckperms/neoforge/service/NeoForgePermissionHandler.java @@ -32,7 +32,6 @@ import me.lucko.luckperms.common.verbose.event.CheckOrigin; import me.lucko.luckperms.neoforge.LPNeoForgeBootstrap; import me.lucko.luckperms.neoforge.LPNeoForgePlugin; -import me.lucko.luckperms.neoforge.capabilities.UserCapabilityImpl; import net.luckperms.api.context.ImmutableContextSet; import net.luckperms.api.query.QueryMode; import net.luckperms.api.query.QueryOptions; @@ -78,12 +77,9 @@ public Set> getRegisteredNodes() { @Override public T getPermission(ServerPlayer player, PermissionNode node, PermissionDynamicContext... context) { - UserCapabilityImpl capability = UserCapabilityImpl.getNullable(player); - - if (capability != null) { - User user = capability.getUser(); - QueryOptions queryOptions = capability.getQueryOptionsCache().getQueryOptions(); - + User user = plugin.getUserManager().getIfLoaded(player.getUUID()); + if (user != null) { + QueryOptions queryOptions = plugin.getContextManager().getQueryOptions(player); T value = getPermissionValue(user, queryOptions, node, context); if (value != null) { return value; diff --git a/neoforge/src/main/java/me/lucko/luckperms/neoforge/util/BrigadierInjector.java b/neoforge/src/main/java/me/lucko/luckperms/neoforge/util/BrigadierInjector.java index 7cd65d6df..ed91fcd29 100644 --- a/neoforge/src/main/java/me/lucko/luckperms/neoforge/util/BrigadierInjector.java +++ b/neoforge/src/main/java/me/lucko/luckperms/neoforge/util/BrigadierInjector.java @@ -32,8 +32,7 @@ import me.lucko.luckperms.common.graph.TraversalAlgorithm; import me.lucko.luckperms.common.model.User; import me.lucko.luckperms.neoforge.LPNeoForgePlugin; -import me.lucko.luckperms.neoforge.capabilities.UserCapability; -import me.lucko.luckperms.neoforge.capabilities.UserCapabilityImpl; +import net.luckperms.api.query.QueryOptions; import net.luckperms.api.util.Tristate; import net.minecraft.commands.CommandSourceStack; import net.minecraft.server.level.ServerPlayer; @@ -140,22 +139,16 @@ private InjectedPermissionRequirement(LPNeoForgePlugin plugin, String permission @Override public boolean test(CommandSourceStack source) { - if (source.getEntity() instanceof ServerPlayer) { - ServerPlayer player = (ServerPlayer) source.getEntity(); - Tristate state = Tristate.UNDEFINED; - // If player is still connecting and has not been added to world then check LP user directly - if (!player.isAddedToLevel()) { - User user = this.plugin.getUserManager().getIfLoaded(player.getUUID()); - if (user == null) { - // Should never happen but just in case... - return false; - } - state = user.getCachedData().getPermissionData().checkPermission(permission); - } else { - UserCapability user = UserCapabilityImpl.get(player); - state = user.checkPermission(this.permission); + if (source.getEntity() instanceof ServerPlayer player) { + + User user = this.plugin.getUserManager().getIfLoaded(player.getUUID()); + if (user == null) { + return false; } + QueryOptions queryOptions = this.plugin.getContextManager().getQueryOptions(player); + Tristate state = user.getCachedData().getPermissionData(queryOptions).checkPermission(this.permission); + if (state != Tristate.UNDEFINED) { return state.asBoolean() && this.delegate.test(source.withPermission(4)); } diff --git a/settings.gradle b/settings.gradle index db360fbf6..5598dd55f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -30,7 +30,6 @@ include ( 'fabric', 'neoforge', 'neoforge:loader', - 'neoforge:neoforge-api', 'forge', 'forge:loader', 'forge:forge-api', diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/context/SpongeContextManager.java b/sponge/src/main/java/me/lucko/luckperms/sponge/context/SpongeContextManager.java index 2fa491800..046b2f478 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/context/SpongeContextManager.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/context/SpongeContextManager.java @@ -25,31 +25,20 @@ package me.lucko.luckperms.sponge.context; -import com.github.benmanes.caffeine.cache.LoadingCache; -import me.lucko.luckperms.common.context.manager.ContextManager; -import me.lucko.luckperms.common.context.manager.InlineQueryOptionsSupplier; -import me.lucko.luckperms.common.context.manager.QueryOptionsSupplier; -import me.lucko.luckperms.common.util.CaffeineFactory; +import me.lucko.luckperms.common.context.manager.InlineContextManager; import me.lucko.luckperms.sponge.LPSpongePlugin; import me.lucko.luckperms.sponge.service.model.ContextCalculatorProxy; import me.lucko.luckperms.sponge.service.model.TemporaryCauseHolderSubject; import net.luckperms.api.context.ContextCalculator; import net.luckperms.api.context.ContextConsumer; -import net.luckperms.api.context.ImmutableContextSet; import net.luckperms.api.context.StaticContextCalculator; -import net.luckperms.api.query.QueryOptions; import org.spongepowered.api.entity.living.player.server.ServerPlayer; import org.spongepowered.api.event.Cause; import org.spongepowered.api.service.permission.Subject; import java.util.UUID; -import java.util.concurrent.TimeUnit; -public class SpongeContextManager extends ContextManager { - - private final LoadingCache contextsCache = CaffeineFactory.newBuilder() - .expireAfterWrite(50, TimeUnit.MILLISECONDS) - .build(this::calculate); +public class SpongeContextManager extends InlineContextManager { public SpongeContextManager(LPSpongePlugin plugin) { super(plugin, Subject.class, ServerPlayer.class); @@ -86,34 +75,4 @@ protected void callContextCalculator(ContextCalculator calculat public UUID getUniqueId(ServerPlayer player) { return player.uniqueId(); } - - @Override - public QueryOptionsSupplier getCacheFor(Subject subject) { - if (subject == null) { - throw new NullPointerException("subject"); - } - - return new InlineQueryOptionsSupplier<>(subject, this.contextsCache); - } - - // override getContext, getQueryOptions and invalidateCache to skip the QueryOptionsSupplier - @Override - public ImmutableContextSet getContext(Subject subject) { - return getQueryOptions(subject).context(); - } - - @Override - public QueryOptions getQueryOptions(Subject subject) { - return this.contextsCache.get(subject); - } - - @Override - protected void invalidateCache(Subject subject) { - this.contextsCache.invalidate(subject); - } - - @Override - public QueryOptions formQueryOptions(Subject subject, ImmutableContextSet contextSet) { - return formQueryOptions(contextSet); - } } diff --git a/velocity/src/main/java/me/lucko/luckperms/velocity/context/VelocityContextManager.java b/velocity/src/main/java/me/lucko/luckperms/velocity/context/VelocityContextManager.java index add4b7501..50bbc15b5 100644 --- a/velocity/src/main/java/me/lucko/luckperms/velocity/context/VelocityContextManager.java +++ b/velocity/src/main/java/me/lucko/luckperms/velocity/context/VelocityContextManager.java @@ -25,25 +25,13 @@ package me.lucko.luckperms.velocity.context; -import com.github.benmanes.caffeine.cache.LoadingCache; import com.velocitypowered.api.proxy.Player; -import me.lucko.luckperms.common.context.manager.ContextManager; -import me.lucko.luckperms.common.context.manager.QueryOptionsCache; -import me.lucko.luckperms.common.context.manager.QueryOptionsSupplier; -import me.lucko.luckperms.common.util.CaffeineFactory; +import me.lucko.luckperms.common.context.manager.InlineContextManager; import me.lucko.luckperms.velocity.LPVelocityPlugin; -import net.luckperms.api.context.ImmutableContextSet; -import net.luckperms.api.query.QueryOptions; import java.util.UUID; -import java.util.concurrent.TimeUnit; - -public class VelocityContextManager extends ContextManager { - - private final LoadingCache> subjectCaches = CaffeineFactory.newBuilder() - .expireAfterAccess(1, TimeUnit.MINUTES) - .build(key -> new QueryOptionsCache<>(key, this)); +public class VelocityContextManager extends InlineContextManager { public VelocityContextManager(LPVelocityPlugin plugin) { super(plugin, Player.class, Player.class); } @@ -52,26 +40,4 @@ public VelocityContextManager(LPVelocityPlugin plugin) { public UUID getUniqueId(Player player) { return player.getUniqueId(); } - - @Override - public QueryOptionsSupplier getCacheFor(Player subject) { - if (subject == null) { - throw new NullPointerException("subject"); - } - - return this.subjectCaches.get(subject); - } - - @Override - protected void invalidateCache(Player subject) { - QueryOptionsCache cache = this.subjectCaches.getIfPresent(subject); - if (cache != null) { - cache.invalidate(); - } - } - - @Override - public QueryOptions formQueryOptions(Player subject, ImmutableContextSet contextSet) { - return formQueryOptions(contextSet); - } } From a036591b11f5e10ccf0488a55ce9919f00a81f74 Mon Sep 17 00:00:00 2001 From: Luis Date: Fri, 6 Dec 2024 16:05:31 +0000 Subject: [PATCH 7/8] chore(deps): bump Minestom --- minestom/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/minestom/build.gradle b/minestom/build.gradle index 9ff590ff5..45a8e1062 100644 --- a/minestom/build.gradle +++ b/minestom/build.gradle @@ -13,7 +13,7 @@ repositories { } dependencies { - var minestom = "1_21_2-888f9896cc" + var minestom = "ccea53ac44" api(project(":common")) { // exclude default config providers as they are inaccessible from the minestom module anyway From 1683783c113cbb2b32c3b42e301504621e3965e5 Mon Sep 17 00:00:00 2001 From: Luis Date: Fri, 6 Dec 2024 16:09:02 +0000 Subject: [PATCH 8/8] chore(deps): upgrade Gradle to 8.11.1 --- gradle/wrapper/gradle-wrapper.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 94113f200..e2847c820 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME