use of io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions 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.annotations.command.Permissions in project Nucleus by NucleusPowered.
the class DocGenCache method addCommand.
public void addCommand(final String moduleID, final AbstractCommand<?> abstractCommand) {
if (abstractCommand.getClass().isAnnotationPresent(NoDocumentation.class)) {
return;
}
CommandDoc cmd = new CommandDoc();
String cmdPath = abstractCommand.getCommandPath().replaceAll("\\.", " ");
cmd.setCommandName(cmdPath);
cmd.setAliases(String.join(", ", Lists.newArrayList(abstractCommand.getAliases())));
if (abstractCommand.getRootCommandAliases().length > 0) {
cmd.setRootAliases(String.join(", ", Arrays.asList(abstractCommand.getRootCommandAliases())));
}
cmd.setPermissionbase(abstractCommand.getPermissionHandler().getBase());
Class<? extends AbstractCommand> cac = abstractCommand.getClass();
Permissions s = cac.getAnnotation(Permissions.class);
if (s == null) {
cmd.setDefaultLevel(cac.isAnnotationPresent(NoPermissions.class) ? SuggestedLevel.USER.name() : SuggestedLevel.ADMIN.name());
} else {
cmd.setDefaultLevel(s.suggestedLevel().name());
}
cmd.setModule(moduleID);
if (!cac.isAnnotationPresent(NoModifiers.class)) {
cmd.setCooldown(!cac.isAnnotationPresent(NoCooldown.class));
cmd.setCost(!cac.isAnnotationPresent(NoCost.class));
cmd.setWarmup(!cac.isAnnotationPresent(NoWarmup.class));
}
cmd.setSince(cac.getAnnotation(Since.class));
String desc = abstractCommand.getDescription();
if (!desc.contains(" ")) {
logger.warn("Cannot generate description for: " + abstractCommand.getCommandPath() + ": " + desc);
}
cmd.setOneLineDescription(desc);
String extendedDescription = abstractCommand.getExtendedDescription().replace("\n", "|br|").replace("\"", """);
if (!extendedDescription.isEmpty()) {
cmd.setExtendedDescription(extendedDescription);
}
List<PermissionDoc> lp = new ArrayList<>();
abstractCommand.getPermissionHandler().getSuggestedPermissions().forEach((k, v) -> lp.add(addPermissionDocs(moduleID, k, v)));
cmd.setPermissions(lp);
cmd.setUsageString(abstractCommand.getUsageString(Sponge.getServer().getConsole()));
cmd.setSubcommands(abstractCommand.getChildrenUsage(Sponge.getServer().getConsole()).map(Text::toPlain).orElse(""));
cmd.setSimpleUsage(abstractCommand.getSimpleUsage(Sponge.getServer().getConsole()));
// Essentials
EssentialsEquivalent ee = abstractCommand.getClass().getAnnotation(EssentialsEquivalent.class);
if (ee != null) {
List<String> ss = Arrays.asList(ee.value());
cmd.setEssentialsEquivalents(ss);
cmd.setEssNotes(ee.notes());
cmd.setExactEssEquiv(ee.isExact());
EssentialsDoc doc = new EssentialsDoc();
doc.setEssentialsCommands(ss);
int i = cmdPath.lastIndexOf(" ");
String c;
if (i > -1) {
c = cmdPath.substring(0, i) + " ";
} else {
c = "";
}
List<String> a = Lists.newArrayList(abstractCommand.getAliases()).stream().map(x -> c + x).collect(Collectors.toList());
if (abstractCommand.getRootCommandAliases().length > 0) {
a.addAll(Arrays.asList(abstractCommand.getRootCommandAliases()));
}
doc.setNucleusEquiv(a);
doc.setExact(ee.isExact());
doc.setNotes(ee.notes());
essentialsDocs.add(doc);
}
commandDocs.add(cmd);
}
Aggregations