Search in sources :

Example 1 with IMixinSubject

use of org.spongepowered.common.interfaces.IMixinSubject in project SpongeCommon by SpongePowered.

the class SubjectSettingCallback method test.

@Override
public boolean test(@Nullable PermissionService input) {
    IMixinSubject ref = this.ref.get();
    if (ref == null) {
        // as a listener, and will not be tested again.
        return false;
    }
    // if PS has just been unregistered, ignore the change.
    if (input == null) {
        return true;
    }
    SubjectReference subject;
    // we can skip some unnecessary instance creation this way.
    if (input instanceof SpongePermissionService) {
        SpongePermissionService serv = (SpongePermissionService) input;
        SpongeSubjectCollection collection = serv.get(ref.getSubjectCollectionIdentifier());
        if (ref instanceof User && collection instanceof UserCollection) {
            // GameProfile is already resolved, use it directly
            subject = ((UserCollection) collection).get((GameProfile) ((User) ref).getProfile()).asSubjectReference();
        } else {
            subject = collection.get(((Subject) ref).getIdentifier()).asSubjectReference();
        }
    } else {
        // build a new subject reference using the permission service
        // this doesn't actually load the subject, so it will be lazily init'd when needed.
        subject = input.newSubjectReference(ref.getSubjectCollectionIdentifier(), ((Subject) ref).getIdentifier());
    }
    ref.setSubject(subject);
    return true;
}
Also used : User(org.spongepowered.api.entity.living.player.User) SubjectReference(org.spongepowered.api.service.permission.SubjectReference) SpongeSubjectCollection(org.spongepowered.common.service.permission.base.SpongeSubjectCollection) IMixinSubject(org.spongepowered.common.interfaces.IMixinSubject) Subject(org.spongepowered.api.service.permission.Subject) MixinSubject(org.spongepowered.common.mixin.core.command.MixinSubject) IMixinSubject(org.spongepowered.common.interfaces.IMixinSubject)

Aggregations

User (org.spongepowered.api.entity.living.player.User)1 Subject (org.spongepowered.api.service.permission.Subject)1 SubjectReference (org.spongepowered.api.service.permission.SubjectReference)1 IMixinSubject (org.spongepowered.common.interfaces.IMixinSubject)1 MixinSubject (org.spongepowered.common.mixin.core.command.MixinSubject)1 SpongeSubjectCollection (org.spongepowered.common.service.permission.base.SpongeSubjectCollection)1