use of org.cubeengine.butler.alias.AliasCommand in project core by CubeEngine.
the class ContainerCommand method addCommand.
@Override
public boolean addCommand(CommandBase command) {
if (!(command instanceof AliasCommand) && command.getDescriptor() instanceof CubeDescriptor) {
PermissionManager pm = manager.getPermissionManager();
Class owner = getDescriptor().getOwner();
Permission basePerm = pm.getBasePermission(owner);
Permission cmdPerm = pm.getPermission(basePerm.getId() + ".command");
if (cmdPerm == null) {
// TODO Description for BaseCommand Permission
cmdPerm = pm.register(owner, "command", "Allows using all commands for this module", null);
}
// gets the container permission
Permission thisPerm = getDescriptor().registerPermission(pm, cmdPerm);
// register the added cmd permission
((CubeDescriptor) command.getDescriptor()).registerPermission(pm, thisPerm);
}
return super.addCommand(command);
}
use of org.cubeengine.butler.alias.AliasCommand in project core by CubeEngine.
the class CubeCommandManager method addCommand.
@Override
public boolean addCommand(CommandBase command) {
if (command instanceof AliasCommand) {
Set<CommandBase> cmds = commands.computeIfAbsent(((AliasCommand) command).getTarget(), k -> new HashSet<>());
cmds.add(command);
}
if (command.getDescriptor() instanceof CubeDescriptor) {
CubeDescriptor descriptor = (CubeDescriptor) command.getDescriptor();
String name = mm.getModuleName(descriptor.getOwner()).orElse(descriptor.getOwner().getSimpleName());
Permission parent = pm.register(descriptor.getOwner(), "command", "Allows using all commands of " + name, null);
descriptor.registerPermission(pm, parent);
}
boolean b = super.addCommand(command);
if (!(command instanceof AliasCommand) || ((AliasDescriptor) command.getDescriptor()).mainDescriptor().getDispatcher() != this) {
Optional<CommandMapping> mapping = registerSpongeCommand(command.getDescriptor());
if (mapping.isPresent()) {
mappings.put(command, mapping.get());
commandLogger.debug("Registered command: " + mapping.get().getPrimaryAlias());
return b;
}
commandLogger.warn("Command was not registered successfully!");
}
return b;
}
use of org.cubeengine.butler.alias.AliasCommand in project core by CubeEngine.
the class HelpCommand method execute.
@Override
public boolean execute(CommandInvocation invocation) {
if (!(invocation.getCommandSource() instanceof CommandSource)) {
return false;
}
CommandDescriptor descriptor = helpTarget.getDescriptor();
CommandSource sender = (CommandSource) invocation.getCommandSource();
TextFormat formatGray = NONE.color(GRAY);
i18n.send(sender, formatGray, "Description: {input}", i18n.translate(sender, MessageType.NONE, descriptor.getDescription()).toPlain());
List<String> labels = new ArrayList<>(invocation.getLabels());
if (labels.isEmpty()) {
labels.add("");
}
if ("?".equals(labels.get(labels.size() - 1))) {
labels.remove(labels.size() - 1);
}
i18n.send(sender, formatGray, "Usage: {input}", descriptor.getUsage(invocation, labels.toArray(new String[labels.size()])));
sender.sendMessage(Text.of());
if (helpTarget instanceof DispatcherCommand) {
Set<CommandBase> commands = helpTarget.getCommands();
if (!commands.isEmpty() && (commands.size() != 1 || // is Empty ignoring HelpCommand
!(commands.iterator().next() instanceof HelpCommand))) {
i18n.send(sender, NEUTRAL, "The following sub-commands are available:");
sender.sendMessage(Text.of());
commands.stream().filter(command -> !(command instanceof HelpCommand || command instanceof AliasCommand && commands.contains(((AliasCommand) command).getTarget()))).filter(command -> !(command.getDescriptor() instanceof CubeCommandDescriptor && ((CubeCommandDescriptor) command.getDescriptor()).isCheckPerm() && !sender.hasPermission(((CubeCommandDescriptor) command.getDescriptor()).getPermission().getName()))).forEach(command -> sender.sendMessage(Text.of(YELLOW, command.getDescriptor().getName()).toBuilder().onClick(TextActions.runCommand("/" + (String.join(" ", labels) + " " + command.getDescriptor().getName()).trim() + " ?")).append(Text.of(WHITE, ": ", GRAY, i18n.translate(sender, TextFormat.NONE, command.getDescriptor().getDescription()))).build()));
sender.sendMessage(Text.of());
} else if (helpTarget instanceof ParametricContainerCommand) {
i18n.send(sender, MessageType.NEGATIVE, "No actions are available");
sender.sendMessage(Text.of());
}
}
/*
if (descriptor instanceof CubeDescriptor)
{
sender.sendTranslated(GRAY, "Detailed help: {input#link:color=INDIGO}", "http://engine.cubeisland.de/c/" + ((CubeDescriptor)descriptor).getModule().getInformation().getName().toLowerCase() + "/" + StringUtils.implode("/", labels));
}
*/
return true;
}
Aggregations