Search in sources :

Example 1 with LanternSubjectCollection

use of org.lanternpowered.server.service.permission.base.LanternSubjectCollection in project LanternServer by LanternPowered.

the class SubjectSettingCallback method apply.

static boolean apply(@Nullable ProxySubject ref, @Nullable PermissionService input) {
    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;
    }
    final SubjectReference subject;
    // we can skip some unnecessary instance creation this way.
    if (input instanceof LanternPermissionService) {
        final LanternPermissionService service = (LanternPermissionService) input;
        final LanternSubjectCollection collection = service.get(ref.getSubjectCollectionIdentifier());
        subject = collection.get(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(), ref.getIdentifier());
    }
    ref.setInternalSubject(subject);
    return true;
}
Also used : LanternPermissionService(org.lanternpowered.server.service.permission.LanternPermissionService) SubjectReference(org.spongepowered.api.service.permission.SubjectReference) LanternSubjectCollection(org.lanternpowered.server.service.permission.base.LanternSubjectCollection)

Aggregations

LanternPermissionService (org.lanternpowered.server.service.permission.LanternPermissionService)1 LanternSubjectCollection (org.lanternpowered.server.service.permission.base.LanternSubjectCollection)1 SubjectReference (org.spongepowered.api.service.permission.SubjectReference)1