Search in sources :

Example 1 with SpongePermissionService

use of org.spongepowered.common.service.permission.SpongePermissionService in project SpongeCommon by SpongePowered.

the class MixinDedicatedPlayerList method onBypassPlayerLimit.

@Inject(method = "bypassesPlayerLimit", at = @At("HEAD"), cancellable = true)
private void onBypassPlayerLimit(GameProfile profile, CallbackInfoReturnable<Boolean> ci) {
    final PermissionService permissionService = Sponge.getServiceManager().provideUnchecked(PermissionService.class);
    final Subject subject = permissionService.getUserSubjects().getSubject(profile.getId().toString()).orElse(permissionService.getDefaults());
    final Tristate tristate = subject.getPermissionValue(SubjectData.GLOBAL_CONTEXT, LoginPermissions.BYPASS_PLAYER_LIMIT_PERMISSION);
    // if we are still using the default permission service
    if (tristate == Tristate.UNDEFINED && permissionService instanceof SpongePermissionService) {
        return;
    }
    ci.setReturnValue(tristate.asBoolean());
}
Also used : SpongePermissionService(org.spongepowered.common.service.permission.SpongePermissionService) PermissionService(org.spongepowered.api.service.permission.PermissionService) Tristate(org.spongepowered.api.util.Tristate) SpongePermissionService(org.spongepowered.common.service.permission.SpongePermissionService) Subject(org.spongepowered.api.service.permission.Subject) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 2 with SpongePermissionService

use of org.spongepowered.common.service.permission.SpongePermissionService in project SpongeCommon by SpongePowered.

the class MixinServerCommandManager method registerDefaultPermissions.

private void registerDefaultPermissions(Game game, MinecraftCommandWrapper cmd) {
    Optional<PermissionService> perms = game.getServiceManager().provide(PermissionService.class);
    if (perms.isPresent()) {
        PermissionService service = perms.get();
        int opLevel = cmd.getPermissionLevel();
        if (opLevel == -1) {
            return;
        }
        if (service instanceof SpongePermissionService) {
            ((SpongePermissionService) service).getGroupForOpLevel(opLevel).getTransientSubjectData().setPermission(SubjectData.GLOBAL_CONTEXT, cmd.getCommandPermission(), Tristate.TRUE);
        } else if (opLevel == 0) {
            service.getDefaults().getTransientSubjectData().setPermission(SubjectData.GLOBAL_CONTEXT, cmd.getCommandPermission(), Tristate.TRUE);
        }
    }
}
Also used : SpongePermissionService(org.spongepowered.common.service.permission.SpongePermissionService) PermissionService(org.spongepowered.api.service.permission.PermissionService) SpongePermissionService(org.spongepowered.common.service.permission.SpongePermissionService)

Example 3 with SpongePermissionService

use of org.spongepowered.common.service.permission.SpongePermissionService in project SpongeVanilla by SpongePowered.

the class SpongeVanilla method initialize.

public void initialize() {
    this.registry.init();
    if (!this.game.getServiceManager().provide(PermissionService.class).isPresent()) {
        SpongePermissionService service = new SpongePermissionService(this.game);
        this.game.getServiceManager().setProvider(this, PermissionService.class, service);
    }
    SpongeCraftingRecipeRegistry.getInstance().disableRegistrations();
    SpongeImpl.postState(GameState.INITIALIZATION, SpongeEventFactory.createGameInitializationEvent(Sponge.getCauseStackManager().getCurrentCause()));
    this.registry.postInit();
    SpongeImpl.postState(GameState.POST_INITIALIZATION, SpongeEventFactory.createGamePostInitializationEvent(Sponge.getCauseStackManager().getCurrentCause()));
    this.logger.info("Successfully loaded and initialized plugins.");
    SpongeImpl.postState(GameState.LOAD_COMPLETE, SpongeEventFactory.createGameLoadCompleteEvent(Sponge.getCauseStackManager().getCurrentCause()));
}
Also used : SpongePermissionService(org.spongepowered.common.service.permission.SpongePermissionService)

Example 4 with SpongePermissionService

use of org.spongepowered.common.service.permission.SpongePermissionService in project SpongeForge by SpongePowered.

the class SpongeMod method onInitialization.

@Subscribe
public void onInitialization(FMLInitializationEvent event) {
    try {
        SpongeImpl.getRegistry().init();
        if (!this.game.getServiceManager().provide(PermissionService.class).isPresent()) {
            final SpongePermissionService service = new SpongePermissionService(this.game);
            this.game.getServiceManager().setProvider(this, PermissionService.class, service);
        }
    } catch (Throwable t) {
        this.controller.errorOccurred(this, t);
    }
}
Also used : SpongePermissionService(org.spongepowered.common.service.permission.SpongePermissionService) Subscribe(com.google.common.eventbus.Subscribe)

Aggregations

SpongePermissionService (org.spongepowered.common.service.permission.SpongePermissionService)4 PermissionService (org.spongepowered.api.service.permission.PermissionService)2 Subscribe (com.google.common.eventbus.Subscribe)1 Subject (org.spongepowered.api.service.permission.Subject)1 Tristate (org.spongepowered.api.util.Tristate)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1