LuckPerms

LuckPerms

41.4k Downloads

Default group permissions not updating until after restart

bloodmc opened this issue ยท 3 comments

commented

Paper 1.13.2
LP 4.3.99

For some reason, whenever I update the default group permissions in GP it does not always take effect until AFTER I restart server. Here is the code

    public boolean setPermissionValue(PermissionHolder holder, String permission, Tristate value, Set<Context> contexts) {
        DataMutateResult result = null;
        ImmutableContextSet set = ImmutableContextSet.fromEntries(contexts);
        final Node node = GriefDefenderPlugin.getInstance().luckPermsProvider.getLuckPermsApi().getNodeFactory().newBuilder(permission).setValue(value.asBoolean()).withExtraContext(set).build();
        if (value == Tristate.UNDEFINED) {
            result = holder.unsetPermission(node);
        } else {
            result = holder.setPermission(node);
        }
        if (result.wasSuccess()) {
            this.savePermissionHolder(holder);
        }
        return result.wasSuccess();
    }

    public void savePermissionHolder(PermissionHolder holder) {
        if (holder instanceof User) {
            this.luckPermsApi.getUserManager().saveUser((User) holder);
        } else {
            this.luckPermsApi.getGroupManager().saveGroup((Group) holder);
        }
    }

Update: This definitely appears to be a caching issue as I see the json file updates properly but does not always take effect in game until a restart. I remember Sponge had a similar problem in the past and it was fixed.

commented

This is the same issue as #118 which was fixed for Sponge in commit ce42573

commented

I managed to refresh the cache myself which I assume is the correct way to handle caches on Bukkit?

        if (result.wasSuccess()) {
            if (holder instanceof Group) {
                final Group group = (Group) holder;
                group.refreshCachedData();
                for (User user :GriefDefenderPlugin.getInstance().luckPermsProvider.getLuckPermsApi().getUserManager().getLoadedUsers()) {
                    if (user.inheritsGroup(group)) {
                        user.refreshCachedData();
                    }
                }
            }
            this.savePermissionHolder(holder);
        }

The above code solves the issue.

Also, is there a better way to retrieve all online users that inherit a group or do I always have to call getLoadedUsers?

commented

This was fixed previously, I just forgot to close the issue - sorry!