Search in sources :

Example 1 with PermissionService

use of org.spongepowered.api.service.permission.PermissionService 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 PermissionService

use of org.spongepowered.api.service.permission.PermissionService 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 PermissionService

use of org.spongepowered.api.service.permission.PermissionService in project Nucleus by NucleusPowered.

the class SetupPermissionsCommand method setupGroups.

private void setupGroups(CommandSource src) throws Exception {
    String ownerGroup = "owner";
    String adminGroup = "admin";
    String modGroup = "mod";
    String defaultGroup = "default";
    MessageProvider messageProvider = Nucleus.getNucleus().getMessageProvider();
    // Create groups
    PermissionService permissionService = Sponge.getServiceManager().provide(PermissionService.class).orElseThrow(() -> ReturnMessageException.fromKey("args.permissiongroup.noservice"));
    // check for admin
    Subject owner = getSubject(ownerGroup, src, permissionService, messageProvider);
    Subject admin = getSubject(adminGroup, src, permissionService, messageProvider);
    Subject mod = getSubject(modGroup, src, permissionService, messageProvider);
    Subject defaults = getSubject(defaultGroup, src, permissionService, messageProvider);
    src.sendMessage(messageProvider.getTextMessageWithFormat("command.nucleus.permission.inherit", adminGroup, ownerGroup));
    owner.getSubjectData().addParent(ImmutableSet.of(), admin.asSubjectReference());
    src.sendMessage(messageProvider.getTextMessageWithFormat("command.nucleus.permission.inherit", modGroup, adminGroup));
    admin.getSubjectData().addParent(ImmutableSet.of(), mod.asSubjectReference());
    src.sendMessage(messageProvider.getTextMessageWithFormat("command.nucleus.permission.inherit", defaultGroup, modGroup));
    mod.getSubjectData().addParent(ImmutableSet.of(), defaults.asSubjectReference());
    src.sendMessage(messageProvider.getTextMessageWithFormat("command.nucleus.permission.perms"));
    setupPerms(src, owner, SuggestedLevel.OWNER, false, false);
    setupPerms(src, admin, SuggestedLevel.ADMIN, false, false);
    setupPerms(src, mod, SuggestedLevel.MOD, false, false);
    setupPerms(src, defaults, SuggestedLevel.USER, false, false);
    src.sendMessage(messageProvider.getTextMessageWithFormat("command.nucleus.permission.completegroups"));
}
Also used : PermissionService(org.spongepowered.api.service.permission.PermissionService) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) Subject(org.spongepowered.api.service.permission.Subject)

Example 4 with PermissionService

use of org.spongepowered.api.service.permission.PermissionService in project SpongeCommon by SpongePowered.

the class MixinDedicatedPlayerList method onCanJoin.

@Inject(method = "canJoin", at = @At("HEAD"), cancellable = true)
private void onCanJoin(GameProfile profile, CallbackInfoReturnable<Boolean> ci) {
    if (!isWhiteListEnabled() || getWhitelistedPlayers().isWhitelisted(profile)) {
        ci.setReturnValue(true);
        return;
    }
    final PermissionService permissionService = Sponge.getServiceManager().provideUnchecked(PermissionService.class);
    final Subject subject = permissionService.getUserSubjects().getSubject(profile.getId().toString()).orElse(permissionService.getDefaults());
    ci.setReturnValue(subject.hasPermission(LoginPermissions.BYPASS_WHITELIST_PERMISSION));
}
Also used : SpongePermissionService(org.spongepowered.common.service.permission.SpongePermissionService) PermissionService(org.spongepowered.api.service.permission.PermissionService) Subject(org.spongepowered.api.service.permission.Subject) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 5 with PermissionService

use of org.spongepowered.api.service.permission.PermissionService in project LanternServer by LanternPowered.

the class DefaultCommandsCollection method load.

public void load() {
    final Multimap<PluginContainer, CommandProvider> commandProviders = HashMultimap.create();
    // Minecraft Commands
    commandProviders.put(this.minecraft, new CommandBan());
    commandProviders.put(this.minecraft, new CommandBanIp());
    commandProviders.put(this.minecraft, new CommandBorder());
    commandProviders.put(this.minecraft, new CommandDeop());
    commandProviders.put(this.minecraft, new CommandDifficulty());
    commandProviders.put(this.minecraft, new CommandGameMode());
    commandProviders.put(this.minecraft, new CommandGameRule());
    commandProviders.put(this.minecraft, new CommandHelp());
    commandProviders.put(this.minecraft, new CommandKick());
    commandProviders.put(this.minecraft, new CommandListBans());
    commandProviders.put(this.minecraft, new CommandListPlayers());
    commandProviders.put(this.minecraft, new CommandMe());
    commandProviders.put(this.minecraft, new CommandOp());
    commandProviders.put(this.minecraft, new CommandPardon());
    commandProviders.put(this.minecraft, new CommandPardonIp());
    commandProviders.put(this.minecraft, new CommandParticle());
    commandProviders.put(this.implementation, new CommandParticleEffect());
    commandProviders.put(this.minecraft, new CommandPlaySound());
    commandProviders.put(this.minecraft, new CommandSay());
    commandProviders.put(this.minecraft, new CommandScoreboard());
    commandProviders.put(this.implementation, new CommandSetData());
    commandProviders.put(this.minecraft, new CommandSetIdleTimeout());
    commandProviders.put(this.minecraft, new CommandSetSpawn());
    commandProviders.put(this.minecraft, new CommandStop());
    commandProviders.put(this.minecraft, new CommandStopSound());
    commandProviders.put(this.minecraft, new CommandTeleport());
    commandProviders.put(this.minecraft, new CommandTell());
    commandProviders.put(this.minecraft, new CommandTime());
    commandProviders.put(this.minecraft, new CommandTitle());
    commandProviders.put(this.minecraft, new CommandToggleDownfall());
    commandProviders.put(this.minecraft, new CommandTp());
    commandProviders.put(this.implementation, new CommandVersion());
    commandProviders.put(this.minecraft, new CommandWeather());
    commandProviders.put(this.minecraft, new CommandWhitelist());
    // Testing Commands
    commandProviders.put(this.implementation, new CommandOpenTestContainer());
    for (Map.Entry<PluginContainer, CommandProvider> entry : commandProviders.entries()) {
        final PluginContainer plugin = entry.getKey();
        this.commandManager.register(plugin, entry.getValue().buildSpecFor(plugin), entry.getValue().getAliases());
    }
    final PermissionService permissionService = this.permissionService.get();
    if (permissionService instanceof LanternPermissionService) {
        final LanternPermissionService lanternPermissionService = (LanternPermissionService) permissionService;
        // noinspection Convert2streamapi
        for (Map.Entry<PluginContainer, CommandProvider> entry : commandProviders.entries()) {
            entry.getValue().getOpPermissionLevel().ifPresent(level -> lanternPermissionService.getGroupForOpLevel(level).getSubjectData().setPermission(SubjectData.GLOBAL_CONTEXT, entry.getValue().getPermissionFor(entry.getKey()), Tristate.TRUE));
        }
    } else {
        // noinspection Convert2streamapi
        for (Map.Entry<PluginContainer, CommandProvider> entry : commandProviders.entries()) {
            if (entry.getValue().getOpPermissionLevel().orElse(0) == 0) {
                permissionService.getDefaults().getTransientSubjectData().setPermission(SubjectData.GLOBAL_CONTEXT, entry.getValue().getPermissionFor(entry.getKey()), Tristate.TRUE);
            }
        }
    }
}
Also used : LanternPermissionService(org.lanternpowered.server.service.permission.LanternPermissionService) PermissionService(org.spongepowered.api.service.permission.PermissionService) CommandOpenTestContainer(org.lanternpowered.server.command.test.CommandOpenTestContainer) PluginContainer(org.spongepowered.api.plugin.PluginContainer) LanternPermissionService(org.lanternpowered.server.service.permission.LanternPermissionService) Map(java.util.Map)

Aggregations

PermissionService (org.spongepowered.api.service.permission.PermissionService)10 Nullable (javax.annotation.Nullable)4 Subject (org.spongepowered.api.service.permission.Subject)4 IOException (java.io.IOException)3 List (java.util.List)3 Map (java.util.Map)3 Optional (java.util.Optional)3 Sponge (org.spongepowered.api.Sponge)3 Text (org.spongepowered.api.text.Text)3 Lists (com.google.common.collect.Lists)2 Maps (com.google.common.collect.Maps)2 Reloadable (io.github.nucleuspowered.nucleus.internal.interfaces.Reloadable)2 PermissionInformation (io.github.nucleuspowered.nucleus.internal.permissions.PermissionInformation)2 SuggestedLevel (io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel)2 Instant (java.time.Instant)2 Set (java.util.Set)2 CauseStack (org.lanternpowered.server.event.CauseStack)2 LanternPermissionService (org.lanternpowered.server.service.permission.LanternPermissionService)2 Keys (org.spongepowered.api.data.key.Keys)2 Cause (org.spongepowered.api.event.cause.Cause)2