Skip to content

Commit

Permalink
Implement player data deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
lucko committed Jul 14, 2024
1 parent 061fc88 commit 7191c16
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,21 @@ record UpdateReq(@JsonProperty(required = true) String username) { }
@Override
public void delete(Context ctx) throws JsonProcessingException {
UUID uniqueId = pathParamAsUuid(ctx);
CompletableFuture<Void> future = this.userManager.loadUser(uniqueId).thenCompose(user -> {
user.data().clear();
return this.userManager.saveUser(user).thenRun(() -> {
this.messagingService.pushUserUpdate(user);
boolean playerDataOnly = ctx.queryParamAsClass("playerDataOnly", Boolean.class).getOrDefault(false);

CompletableFuture<Void> future;
if (playerDataOnly) {
future = this.userManager.deletePlayerData(uniqueId);
} else {
future = this.userManager.loadUser(uniqueId).thenCompose(user -> {
user.data().clear();
return this.userManager.saveUser(user).thenCompose(ignored -> {
this.messagingService.pushUserUpdate(user);
return this.userManager.deletePlayerData(uniqueId);
});
});
});
}

ctx.future(future, result -> ctx.result("ok"));
}

Expand Down Expand Up @@ -240,14 +249,18 @@ public void nodesDeleteAll(Context ctx) throws JsonProcessingException {
? null
: this.objectMapper.readValue(ctx.body(), new TypeReference<>(){});

CompletableFuture<?> future = this.userManager.modifyUser(uniqueId, user -> {
CompletableFuture<?> future = this.userManager.loadUser(uniqueId).thenCompose(user -> {
if (nodes == null) {
user.data().clear();
} else {
for (Node node : nodes) {
user.data().remove(node);
}
}
return this.userManager.saveUser(user).thenApply(v -> {
this.messagingService.pushUserUpdate(user);
return user.getNodes();
});
});
ctx.future(future, result -> ctx.result("ok"));
}
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/luckperms-openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,13 @@ paths:
'404':
description: User doesn't exist
description: Delete a user
parameters:
- schema:
type: boolean
in: query
name: playerDataOnly
description: if only player data should be deleted
required: false
tags:
- Users
'/user/{uniqueId}/nodes':
Expand Down

0 comments on commit 7191c16

Please sign in to comment.