diff --git a/api/src/main/java/net/luckperms/api/model/user/UserManager.java b/api/src/main/java/net/luckperms/api/model/user/UserManager.java index 82ca25523..07fcf2387 100644 --- a/api/src/main/java/net/luckperms/api/model/user/UserManager.java +++ b/api/src/main/java/net/luckperms/api/model/user/UserManager.java @@ -147,6 +147,17 @@ public interface UserManager { */ @NonNull CompletableFuture savePlayerData(@NonNull UUID uniqueId, @NonNull String username); + /** + * Deletes any data about a given player from the uuid caching system. + * + *

Note that this method does not affect any saved user/permissions data.

+ * + * @param uniqueId the users mojang unique id + * @return a future encapsulating the result of the operation + * @since 5.2 + */ + @NonNull CompletableFuture deletePlayerData(@NonNull UUID uniqueId); + /** * Gets a set all "unique" user UUIDs. * diff --git a/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiUserManager.java b/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiUserManager.java index 4e5e425a4..ad774bc03 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiUserManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiUserManager.java @@ -114,6 +114,12 @@ public class ApiUserManager extends ApiAbstractManager deletePlayerData(@NonNull UUID uniqueId) { + Objects.requireNonNull(uniqueId, "uniqueId"); + return this.plugin.getStorage().deletePlayerData(uniqueId); + } + @Override public @NonNull CompletableFuture> getUniqueUsers() { return this.plugin.getStorage().getUniqueUsers(); diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/Storage.java b/common/src/main/java/me/lucko/luckperms/common/storage/Storage.java index 25ba4368a..a2ae3c6f9 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/Storage.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/Storage.java @@ -264,6 +264,10 @@ public class Storage { }); } + public CompletableFuture deletePlayerData(UUID uniqueId) { + return makeFuture(() -> this.implementation.deletePlayerData(uniqueId)); + } + public CompletableFuture getPlayerUniqueId(String username) { return makeFuture(() -> this.implementation.getPlayerUniqueId(username)); } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/StorageImplementation.java b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/StorageImplementation.java index df6404da3..1e18c9183 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/StorageImplementation.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/StorageImplementation.java @@ -98,6 +98,8 @@ public interface StorageImplementation { PlayerSaveResult savePlayerData(UUID uniqueId, String username) throws Exception; + void deletePlayerData(UUID uniqueId) throws Exception; + @Nullable UUID getPlayerUniqueId(String username) throws Exception; @Nullable String getPlayerName(UUID uniqueId) throws Exception; diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/file/AbstractConfigurateStorage.java b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/file/AbstractConfigurateStorage.java index 3558ea7a7..1500e3c35 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/file/AbstractConfigurateStorage.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/file/AbstractConfigurateStorage.java @@ -443,6 +443,11 @@ public abstract class AbstractConfigurateStorage implements StorageImplementatio return this.uuidCache.addMapping(uniqueId, username); } + @Override + public void deletePlayerData(UUID uniqueId) { + this.uuidCache.removeMapping(uniqueId); + } + @Override public UUID getPlayerUniqueId(String username) { return this.uuidCache.lookupUuid(username); diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/file/FileUuidCache.java b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/file/FileUuidCache.java index 9d05b45af..8fb04665a 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/file/FileUuidCache.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/file/FileUuidCache.java @@ -124,6 +124,15 @@ public class FileUuidCache { return result; } + /** + * Removes a mapping from the cache + * + * @param uuid the uuid of the player to remove + */ + public void removeMapping(UUID uuid) { + this.lookupMap.remove(uuid); + } + /** * Gets the most recent uuid which connected with the given username, or null * diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/mongodb/MongoStorage.java b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/mongodb/MongoStorage.java index 2b3c5282c..c3c96d6bc 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/mongodb/MongoStorage.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/mongodb/MongoStorage.java @@ -618,6 +618,12 @@ public class MongoStorage implements StorageImplementation { return result; } + @Override + public void deletePlayerData(UUID uniqueId) { + MongoCollection c = this.database.getCollection(this.prefix + "uuid"); + c.deleteMany(Filters.eq("_id", uniqueId)); + } + @Override public UUID getPlayerUniqueId(String username) { MongoCollection c = this.database.getCollection(this.prefix + "uuid"); diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/split/SplitStorage.java b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/split/SplitStorage.java index dc79afb95..6778ebe7e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/split/SplitStorage.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/split/SplitStorage.java @@ -218,6 +218,11 @@ public class SplitStorage implements StorageImplementation { return implFor(SplitStorageType.UUID).savePlayerData(uniqueId, username); } + @Override + public void deletePlayerData(UUID uniqueId) throws Exception { + implFor(SplitStorageType.UUID).deletePlayerData(uniqueId); + } + @Override public UUID getPlayerUniqueId(String username) throws Exception { return implFor(SplitStorageType.UUID).getPlayerUniqueId(username); 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 8596fad88..4db755fe8 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 @@ -87,6 +87,7 @@ public class SqlStorage implements StorageImplementation { private static final String PLAYER_SELECT_USERNAME_BY_UUID = "SELECT username FROM '{prefix}players' WHERE uuid=? LIMIT 1"; private static final String PLAYER_UPDATE_USERNAME_FOR_UUID = "UPDATE '{prefix}players' SET username=? WHERE uuid=?"; private static final String PLAYER_INSERT = "INSERT INTO '{prefix}players' (uuid, username, primary_group) VALUES(?, ?, ?)"; + private static final String PLAYER_DELETE = "DELETE FROM '{prefix}players' WHERE uuid=?"; private static final String PLAYER_SELECT_ALL_UUIDS_BY_USERNAME = "SELECT uuid FROM '{prefix}players' WHERE username=? AND NOT uuid=?"; private static final String PLAYER_DELETE_ALL_UUIDS_BY_USERNAME = "DELETE FROM '{prefix}players' WHERE username=? AND NOT uuid=?"; private static final String PLAYER_SELECT_BY_UUID = "SELECT username, primary_group FROM '{prefix}players' WHERE uuid=?"; @@ -688,6 +689,16 @@ public class SqlStorage implements StorageImplementation { return result; } + @Override + public void deletePlayerData(UUID uniqueId) throws SQLException { + try (Connection c = this.connectionFactory.getConnection()) { + try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.apply(PLAYER_DELETE))) { + ps.setString(1, uniqueId.toString()); + ps.execute(); + } + } + } + @Override public UUID getPlayerUniqueId(String username) throws SQLException { username = username.toLowerCase();