mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-27 21:29:47 +01:00
Save renamed group before syncing with storage (#3129)
This commit is contained in:
parent
433272518f
commit
0fa3095241
@ -37,6 +37,7 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* Utility methods for saving users, groups and tracks.
|
||||
@ -88,40 +89,28 @@ public final class StorageAssistant {
|
||||
}
|
||||
}
|
||||
|
||||
public static void save(Group group, Sender sender, LuckPermsPlugin plugin) {
|
||||
public static CompletableFuture<Void> save(Group group, Sender sender, LuckPermsPlugin plugin) {
|
||||
try {
|
||||
plugin.getStorage().saveGroup(group).get();
|
||||
} catch (Exception e) {
|
||||
plugin.getLogger().warn("Error whilst saving group", e);
|
||||
Message.GROUP_SAVE_ERROR.send(sender, group);
|
||||
return;
|
||||
return failedFuture(e);
|
||||
}
|
||||
|
||||
plugin.getGroupManager().invalidateAllGroupCaches();
|
||||
plugin.getUserManager().invalidateAllUserCaches();
|
||||
|
||||
Optional<InternalMessagingService> messagingService = plugin.getMessagingService();
|
||||
if (messagingService.isPresent() && plugin.getConfiguration().get(ConfigKeys.AUTO_PUSH_UPDATES)) {
|
||||
messagingService.get().getUpdateBuffer().request();
|
||||
}
|
||||
return invalidateCachesAndPushUpdates(plugin);
|
||||
}
|
||||
|
||||
public static void save(Track track, Sender sender, LuckPermsPlugin plugin) {
|
||||
public static CompletableFuture<Void> save(Track track, Sender sender, LuckPermsPlugin plugin) {
|
||||
try {
|
||||
plugin.getStorage().saveTrack(track).get();
|
||||
} catch (Exception e) {
|
||||
plugin.getLogger().warn("Error whilst saving track", e);
|
||||
Message.TRACK_SAVE_ERROR.send(sender, track.getName());
|
||||
return;
|
||||
return failedFuture(e);
|
||||
}
|
||||
|
||||
plugin.getGroupManager().invalidateAllGroupCaches();
|
||||
plugin.getUserManager().invalidateAllUserCaches();
|
||||
|
||||
Optional<InternalMessagingService> messagingService = plugin.getMessagingService();
|
||||
if (messagingService.isPresent() && plugin.getConfiguration().get(ConfigKeys.AUTO_PUSH_UPDATES)) {
|
||||
messagingService.get().getUpdateBuffer().request();
|
||||
}
|
||||
return invalidateCachesAndPushUpdates(plugin);
|
||||
}
|
||||
|
||||
public static void save(PermissionHolder holder, Sender sender, LuckPermsPlugin plugin) {
|
||||
@ -136,4 +125,21 @@ public final class StorageAssistant {
|
||||
}
|
||||
}
|
||||
|
||||
public static CompletableFuture<Void> invalidateCachesAndPushUpdates(LuckPermsPlugin plugin) {
|
||||
plugin.getGroupManager().invalidateAllGroupCaches();
|
||||
plugin.getUserManager().invalidateAllUserCaches();
|
||||
|
||||
Optional<InternalMessagingService> messagingService = plugin.getMessagingService();
|
||||
if (messagingService.isPresent() && plugin.getConfiguration().get(ConfigKeys.AUTO_PUSH_UPDATES)) {
|
||||
return messagingService.get().getUpdateBuffer().request();
|
||||
} else {
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> CompletableFuture<T> failedFuture(Throwable ex) {
|
||||
CompletableFuture<T> future = new CompletableFuture<>();
|
||||
future.completeExceptionally(ex);
|
||||
return future;
|
||||
}
|
||||
}
|
||||
|
@ -55,6 +55,7 @@ import net.luckperms.api.event.cause.DeletionCause;
|
||||
import net.luckperms.api.model.data.DataType;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class GroupRename extends ChildCommand<Group> {
|
||||
public GroupRename() {
|
||||
@ -104,9 +105,9 @@ public class GroupRename extends ChildCommand<Group> {
|
||||
.description("rename", newGroup.getName())
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
if (!args.remove("--update-parent-lists")) {
|
||||
StorageAssistant.save(newGroup, sender, plugin);
|
||||
} else {
|
||||
StorageAssistant.save(newGroup, sender, plugin)
|
||||
.thenCompose((v) -> {
|
||||
if (args.remove("--update-parent-lists")) {
|
||||
// the group is now renamed, proceed to update its representing inheritance nodes
|
||||
BulkUpdate operation = BulkUpdateBuilder.create()
|
||||
.trackStatistics(false)
|
||||
@ -114,14 +115,17 @@ public class GroupRename extends ChildCommand<Group> {
|
||||
.action(UpdateAction.of(QueryField.PERMISSION, Inheritance.key(newGroupName)))
|
||||
.query(Query.of(QueryField.PERMISSION, Constraint.of(StandardComparison.EQUAL, Inheritance.key(target.getName()))))
|
||||
.build();
|
||||
plugin.getStorage().applyBulkUpdate(operation).whenCompleteAsync((v, ex) -> {
|
||||
plugin.getSyncTaskBuffer().requestDirectly();
|
||||
return plugin.getStorage().applyBulkUpdate(operation);
|
||||
} else {
|
||||
return CompletableFuture.completedFuture(v);
|
||||
}
|
||||
}).whenCompleteAsync((v, ex) -> {
|
||||
if (ex != null) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}, plugin.getBootstrap().getScheduler().async())
|
||||
.thenRunAsync(() -> StorageAssistant.save(newGroup, sender, plugin));
|
||||
}
|
||||
|
||||
plugin.getSyncTaskBuffer().requestDirectly();
|
||||
}, plugin.getBootstrap().getScheduler().async());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user