use of io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel 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()));
}
use of io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel in project Nucleus by NucleusPowered.
the class SetupPermissionsCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
if (args.hasAny(this.withGroupsKey)) {
if (ServiceChangeListener.isOpOnly()) {
// Fail
throw ReturnMessageException.fromKey("args.permissiongroup.noservice");
}
if (args.hasAny(this.acceptGroupKey)) {
setupGroups(src);
} else {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.nucleus.permission.groups.info"));
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.nucleus.permission.groups.info2").toBuilder().onClick(TextActions.runCommand("/nucleus:nucleus setupperms -g -y")).onHover(TextActions.showText(Text.of("/nucleus:nucleus setupperms -g -y"))).build());
}
return CommandResult.success();
}
// The GroupArgument should have already checked for this.
SuggestedLevel sl = args.<SuggestedLevel>getOne(roleKey).get();
Subject group = args.<Subject>getOne(groupKey).get();
boolean reset = args.hasAny("r");
boolean inherit = args.hasAny("i");
setupPerms(src, group, sl, reset, inherit);
return CommandResult.success();
}
use of io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel in project Nucleus by NucleusPowered.
the class NucleusPlugin method registerPermissions.
@Override
protected void registerPermissions() {
Optional<PermissionService> ops = Sponge.getServiceManager().provide(PermissionService.class);
ops.ifPresent(permissionService -> {
Map<String, PermissionInformation> m = this.getPermissionRegistry().getPermissions();
m.entrySet().stream().filter(x -> {
SuggestedLevel lvl = x.getValue().level;
return lvl == SuggestedLevel.ADMIN || lvl == SuggestedLevel.OWNER;
}).filter(x -> x.getValue().isNormal).forEach(k -> permissionService.newDescriptionBuilder(this).assign(PermissionDescription.ROLE_ADMIN, true).description(k.getValue().description).id(k.getKey()).register());
m.entrySet().stream().filter(x -> x.getValue().level == SuggestedLevel.MOD).filter(x -> x.getValue().isNormal).forEach(k -> permissionService.newDescriptionBuilder(this).assign(PermissionDescription.ROLE_STAFF, true).description(k.getValue().description).id(k.getKey()).register());
m.entrySet().stream().filter(x -> x.getValue().level == SuggestedLevel.USER).filter(x -> x.getValue().isNormal).forEach(k -> permissionService.newDescriptionBuilder(this).assign(PermissionDescription.ROLE_USER, true).description(k.getValue().description).id(k.getKey()).register());
});
}
Aggregations