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;
}
Aggregations