mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-24 03:25:19 +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 me.lucko.luckperms.common.sender.Sender;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility methods for saving users, groups and tracks.
|
* 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 {
|
try {
|
||||||
plugin.getStorage().saveGroup(group).get();
|
plugin.getStorage().saveGroup(group).get();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
plugin.getLogger().warn("Error whilst saving group", e);
|
plugin.getLogger().warn("Error whilst saving group", e);
|
||||||
Message.GROUP_SAVE_ERROR.send(sender, group);
|
Message.GROUP_SAVE_ERROR.send(sender, group);
|
||||||
return;
|
return failedFuture(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.getGroupManager().invalidateAllGroupCaches();
|
return invalidateCachesAndPushUpdates(plugin);
|
||||||
plugin.getUserManager().invalidateAllUserCaches();
|
|
||||||
|
|
||||||
Optional<InternalMessagingService> messagingService = plugin.getMessagingService();
|
|
||||||
if (messagingService.isPresent() && plugin.getConfiguration().get(ConfigKeys.AUTO_PUSH_UPDATES)) {
|
|
||||||
messagingService.get().getUpdateBuffer().request();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void save(Track track, Sender sender, LuckPermsPlugin plugin) {
|
public static CompletableFuture<Void> save(Track track, Sender sender, LuckPermsPlugin plugin) {
|
||||||
try {
|
try {
|
||||||
plugin.getStorage().saveTrack(track).get();
|
plugin.getStorage().saveTrack(track).get();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
plugin.getLogger().warn("Error whilst saving track", e);
|
plugin.getLogger().warn("Error whilst saving track", e);
|
||||||
Message.TRACK_SAVE_ERROR.send(sender, track.getName());
|
Message.TRACK_SAVE_ERROR.send(sender, track.getName());
|
||||||
return;
|
return failedFuture(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.getGroupManager().invalidateAllGroupCaches();
|
return invalidateCachesAndPushUpdates(plugin);
|
||||||
plugin.getUserManager().invalidateAllUserCaches();
|
|
||||||
|
|
||||||
Optional<InternalMessagingService> messagingService = plugin.getMessagingService();
|
|
||||||
if (messagingService.isPresent() && plugin.getConfiguration().get(ConfigKeys.AUTO_PUSH_UPDATES)) {
|
|
||||||
messagingService.get().getUpdateBuffer().request();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void save(PermissionHolder holder, Sender sender, LuckPermsPlugin 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 net.luckperms.api.model.data.DataType;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public class GroupRename extends ChildCommand<Group> {
|
public class GroupRename extends ChildCommand<Group> {
|
||||||
public GroupRename() {
|
public GroupRename() {
|
||||||
@ -104,24 +105,27 @@ public class GroupRename extends ChildCommand<Group> {
|
|||||||
.description("rename", newGroup.getName())
|
.description("rename", newGroup.getName())
|
||||||
.build().submit(plugin, sender);
|
.build().submit(plugin, sender);
|
||||||
|
|
||||||
if (!args.remove("--update-parent-lists")) {
|
StorageAssistant.save(newGroup, sender, plugin)
|
||||||
StorageAssistant.save(newGroup, sender, plugin);
|
.thenCompose((v) -> {
|
||||||
} else {
|
if (args.remove("--update-parent-lists")) {
|
||||||
// the group is now renamed, proceed to update its representing inheritance nodes
|
// the group is now renamed, proceed to update its representing inheritance nodes
|
||||||
BulkUpdate operation = BulkUpdateBuilder.create()
|
BulkUpdate operation = BulkUpdateBuilder.create()
|
||||||
.trackStatistics(false)
|
.trackStatistics(false)
|
||||||
.dataType(me.lucko.luckperms.common.bulkupdate.DataType.ALL)
|
.dataType(me.lucko.luckperms.common.bulkupdate.DataType.ALL)
|
||||||
.action(UpdateAction.of(QueryField.PERMISSION, Inheritance.key(newGroupName)))
|
.action(UpdateAction.of(QueryField.PERMISSION, Inheritance.key(newGroupName)))
|
||||||
.query(Query.of(QueryField.PERMISSION, Constraint.of(StandardComparison.EQUAL, Inheritance.key(target.getName()))))
|
.query(Query.of(QueryField.PERMISSION, Constraint.of(StandardComparison.EQUAL, Inheritance.key(target.getName()))))
|
||||||
.build();
|
.build();
|
||||||
plugin.getStorage().applyBulkUpdate(operation).whenCompleteAsync((v, ex) -> {
|
return plugin.getStorage().applyBulkUpdate(operation);
|
||||||
plugin.getSyncTaskBuffer().requestDirectly();
|
} else {
|
||||||
if (ex != null) {
|
return CompletableFuture.completedFuture(v);
|
||||||
ex.printStackTrace();
|
}
|
||||||
}
|
}).whenCompleteAsync((v, ex) -> {
|
||||||
}, plugin.getBootstrap().getScheduler().async())
|
if (ex != null) {
|
||||||
.thenRunAsync(() -> StorageAssistant.save(newGroup, sender, plugin));
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
plugin.getSyncTaskBuffer().requestDirectly();
|
||||||
|
}, plugin.getBootstrap().getScheduler().async());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user