Implement the basis for deleting player uuid data from storage

This commit is contained in:
Luck 2020-09-07 17:22:42 +01:00
parent 84e7fd4d09
commit 198b86d7c3
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
9 changed files with 59 additions and 0 deletions

View File

@ -147,6 +147,17 @@ public interface UserManager {
*/ */
@NonNull CompletableFuture<PlayerSaveResult> savePlayerData(@NonNull UUID uniqueId, @NonNull String username); @NonNull CompletableFuture<PlayerSaveResult> savePlayerData(@NonNull UUID uniqueId, @NonNull String username);
/**
* Deletes any data about a given player from the uuid caching system.
*
* <p>Note that this method does not affect any saved user/permissions data.</p>
*
* @param uniqueId the users mojang unique id
* @return a future encapsulating the result of the operation
* @since 5.2
*/
@NonNull CompletableFuture<Void> deletePlayerData(@NonNull UUID uniqueId);
/** /**
* Gets a set all "unique" user UUIDs. * Gets a set all "unique" user UUIDs.
* *

View File

@ -114,6 +114,12 @@ public class ApiUserManager extends ApiAbstractManager<User, net.luckperms.api.m
return this.plugin.getStorage().savePlayerData(uniqueId, username); return this.plugin.getStorage().savePlayerData(uniqueId, username);
} }
@Override
public @NonNull CompletableFuture<Void> deletePlayerData(@NonNull UUID uniqueId) {
Objects.requireNonNull(uniqueId, "uniqueId");
return this.plugin.getStorage().deletePlayerData(uniqueId);
}
@Override @Override
public @NonNull CompletableFuture<Set<UUID>> getUniqueUsers() { public @NonNull CompletableFuture<Set<UUID>> getUniqueUsers() {
return this.plugin.getStorage().getUniqueUsers(); return this.plugin.getStorage().getUniqueUsers();

View File

@ -264,6 +264,10 @@ public class Storage {
}); });
} }
public CompletableFuture<Void> deletePlayerData(UUID uniqueId) {
return makeFuture(() -> this.implementation.deletePlayerData(uniqueId));
}
public CompletableFuture<UUID> getPlayerUniqueId(String username) { public CompletableFuture<UUID> getPlayerUniqueId(String username) {
return makeFuture(() -> this.implementation.getPlayerUniqueId(username)); return makeFuture(() -> this.implementation.getPlayerUniqueId(username));
} }

View File

@ -98,6 +98,8 @@ public interface StorageImplementation {
PlayerSaveResult savePlayerData(UUID uniqueId, String username) throws Exception; PlayerSaveResult savePlayerData(UUID uniqueId, String username) throws Exception;
void deletePlayerData(UUID uniqueId) throws Exception;
@Nullable UUID getPlayerUniqueId(String username) throws Exception; @Nullable UUID getPlayerUniqueId(String username) throws Exception;
@Nullable String getPlayerName(UUID uniqueId) throws Exception; @Nullable String getPlayerName(UUID uniqueId) throws Exception;

View File

@ -443,6 +443,11 @@ public abstract class AbstractConfigurateStorage implements StorageImplementatio
return this.uuidCache.addMapping(uniqueId, username); return this.uuidCache.addMapping(uniqueId, username);
} }
@Override
public void deletePlayerData(UUID uniqueId) {
this.uuidCache.removeMapping(uniqueId);
}
@Override @Override
public UUID getPlayerUniqueId(String username) { public UUID getPlayerUniqueId(String username) {
return this.uuidCache.lookupUuid(username); return this.uuidCache.lookupUuid(username);

View File

@ -124,6 +124,15 @@ public class FileUuidCache {
return result; 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 * Gets the most recent uuid which connected with the given username, or null
* *

View File

@ -618,6 +618,12 @@ public class MongoStorage implements StorageImplementation {
return result; return result;
} }
@Override
public void deletePlayerData(UUID uniqueId) {
MongoCollection<Document> c = this.database.getCollection(this.prefix + "uuid");
c.deleteMany(Filters.eq("_id", uniqueId));
}
@Override @Override
public UUID getPlayerUniqueId(String username) { public UUID getPlayerUniqueId(String username) {
MongoCollection<Document> c = this.database.getCollection(this.prefix + "uuid"); MongoCollection<Document> c = this.database.getCollection(this.prefix + "uuid");

View File

@ -218,6 +218,11 @@ public class SplitStorage implements StorageImplementation {
return implFor(SplitStorageType.UUID).savePlayerData(uniqueId, username); return implFor(SplitStorageType.UUID).savePlayerData(uniqueId, username);
} }
@Override
public void deletePlayerData(UUID uniqueId) throws Exception {
implFor(SplitStorageType.UUID).deletePlayerData(uniqueId);
}
@Override @Override
public UUID getPlayerUniqueId(String username) throws Exception { public UUID getPlayerUniqueId(String username) throws Exception {
return implFor(SplitStorageType.UUID).getPlayerUniqueId(username); return implFor(SplitStorageType.UUID).getPlayerUniqueId(username);

View File

@ -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_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_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_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_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_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=?"; 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; 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 @Override
public UUID getPlayerUniqueId(String username) throws SQLException { public UUID getPlayerUniqueId(String username) throws SQLException {
username = username.toLowerCase(); username = username.toLowerCase();