Search in sources :

Example 1 with SubjectData

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

the class SetupPermissionsCommand method setupPerms.

private void setupPerms(CommandSource src, Subject group, SuggestedLevel level, boolean reset, boolean inherit) throws Exception {
    if (inherit && level.getLowerLevel() != null) {
        setupPerms(src, group, level.getLowerLevel(), reset, inherit);
    }
    Set<Context> globalContext = Sets.newHashSet();
    SubjectData data = group.getSubjectData();
    Set<String> definedPermissions = data.getPermissions(ImmutableSet.of()).keySet();
    Logger logger = Nucleus.getNucleus().getLogger();
    MessageProvider messageProvider = Nucleus.getNucleus().getMessageProvider();
    // Register all the permissions, but only those that have yet to be assigned.
    permissionRegistry.getPermissions().entrySet().stream().filter(x -> x.getValue().level == level).filter(x -> reset || !definedPermissions.contains(x.getKey())).forEach(x -> {
        logger.info(messageProvider.getMessageWithFormat("command.nucleus.permission.added", x.getKey(), group.getIdentifier()));
        data.setPermission(globalContext, x.getKey(), Tristate.TRUE);
    });
    src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.nucleus.permission.complete", level.toString().toLowerCase(), group.getIdentifier()));
}
Also used : CommandContext(org.spongepowered.api.command.args.CommandContext) Context(org.spongepowered.api.service.context.Context) RegisterCommand(io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand) NonnullByDefault(org.spongepowered.api.util.annotation.NonnullByDefault) ArgumentParseException(org.spongepowered.api.command.args.ArgumentParseException) CommandArgs(org.spongepowered.api.command.args.CommandArgs) GenericArguments(org.spongepowered.api.command.args.GenericArguments) PermissionService(org.spongepowered.api.service.permission.PermissionService) RunAsync(io.github.nucleuspowered.nucleus.internal.annotations.RunAsync) PermissionRegistry(io.github.nucleuspowered.nucleus.internal.PermissionRegistry) CommandContext(org.spongepowered.api.command.args.CommandContext) Text(org.spongepowered.api.text.Text) SuggestedLevel(io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel) Permissions(io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions) ServiceChangeListener(io.github.nucleuspowered.nucleus.internal.permissions.ServiceChangeListener) Subject(org.spongepowered.api.service.permission.Subject) Nullable(javax.annotation.Nullable) NoModifiers(io.github.nucleuspowered.nucleus.internal.annotations.command.NoModifiers) SubjectData(org.spongepowered.api.service.permission.SubjectData) CommandResult(org.spongepowered.api.command.CommandResult) TextActions(org.spongepowered.api.text.action.TextActions) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) Nucleus(io.github.nucleuspowered.nucleus.Nucleus) CommandSource(org.spongepowered.api.command.CommandSource) Context(org.spongepowered.api.service.context.Context) Sponge(org.spongepowered.api.Sponge) Set(java.util.Set) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) CommandElement(org.spongepowered.api.command.args.CommandElement) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Tristate(org.spongepowered.api.util.Tristate) List(java.util.List) AbstractCommand(io.github.nucleuspowered.nucleus.internal.command.AbstractCommand) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) Optional(java.util.Optional) Collections(java.util.Collections) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) SubjectData(org.spongepowered.api.service.permission.SubjectData) Logger(org.slf4j.Logger)

Aggregations

ImmutableSet (com.google.common.collect.ImmutableSet)1 Sets (com.google.common.collect.Sets)1 Nucleus (io.github.nucleuspowered.nucleus.Nucleus)1 PermissionRegistry (io.github.nucleuspowered.nucleus.internal.PermissionRegistry)1 RunAsync (io.github.nucleuspowered.nucleus.internal.annotations.RunAsync)1 NoModifiers (io.github.nucleuspowered.nucleus.internal.annotations.command.NoModifiers)1 Permissions (io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions)1 RegisterCommand (io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand)1 AbstractCommand (io.github.nucleuspowered.nucleus.internal.command.AbstractCommand)1 ReturnMessageException (io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException)1 MessageProvider (io.github.nucleuspowered.nucleus.internal.messages.MessageProvider)1 ServiceChangeListener (io.github.nucleuspowered.nucleus.internal.permissions.ServiceChangeListener)1 SuggestedLevel (io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel)1 Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Nullable (javax.annotation.Nullable)1 Logger (org.slf4j.Logger)1