SpongeAPI
                                
                                 SpongeAPI copied to clipboard
                                
                                    SpongeAPI copied to clipboard
                            
                            
                            
                        Permission api - no way to reorder parents
There is no way to reorder parents! Only one way is to get all parents in all contexts, find required context, create mutable copy of parents list, order it in a correct way, clear all parents in a context and then re-ad them in a loop using
addParent(Set<Context> contexts, SubjectReference parent);
Suggestion: add method setParents(Set<Context> contexts, List<SubjectReference>); to set all parents directly.
Why? You can say, that i can just write in first way, but addParent returns CompletableFuture<Boolean>, this means, that this operation should write data to a storage. Many calls may decrease IO performance, also, it prevents implementation to use optimizations for bulk changes.
@lucko
Does the order even matter?
Parents are in List, list is ordered, so, order matters.
3 parents allow permission my.best.perm and third denies it.
How it calculates, what to apply?
It depends on the implementation
Ok. Btw, method to set parents in given context may be useful.
I don't understand what you mean
API has this method: https://github.com/SpongePowered/SpongeAPI/blob/stable-7/src/main/java/org/spongepowered/api/service/permission/SubjectData.java#L182
clearParents(Set<Context> contexts)
But there is no setParents(Set<Context> contexts, List<Subject> parents) method.
It makes sense that if you're using a List, it implies that there's an order, and potentially duplicate entires in said list. If the order is not supposed to matter, or that having duplicate entities is not supposed to happen, then the signature should be changed to use a Set.
This is the point I believe is trying to be made.
Indeed a Set would be a more reasonable way to store parents.
I don't see why a set method accepting the full list is necessary, no such method exists for permissions or options.
Possibly tangentially related to https://github.com/SpongePowered/SpongeAPI/issues/977