use of org.cubeengine.butler.CommandInvocation in project core by CubeEngine.
the class ConversationCommand method onChatHandler.
@Listener
public void onChatHandler(MessageChannelEvent.Chat event, @First Player player) {
if (this.hasUser(player)) {
player.sendMessage(Text.of(DARK_PURPLE, "[", WHITE, getDescriptor().getName(), DARK_PURPLE, "] ", WHITE, event.getMessage()));
Text message = event.getRawMessage();
// TODO
CommandInvocation invocation = newInvocation(player, message.toPlain());
this.execute(invocation);
event.setCancelled(true);
}
}
use of org.cubeengine.butler.CommandInvocation 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;
}
use of org.cubeengine.butler.CommandInvocation in project core by CubeEngine.
the class ProxyCallable method process.
@Override
public CommandResult process(CommandSource source, String arguments) throws CommandException {
try {
CommandInvocation invocation = newInvocation(source, arguments.isEmpty() ? alias : alias + " " + arguments);
long delta = System.currentTimeMillis();
boolean ran;
try (Timing timing = Timings.ofStart(manager.getPlugin(), "CE Command Execute " + alias);
Summary.Timer t = commandTimeSummary.startTimer()) {
ran = manager.execute(invocation);
}
delta = System.currentTimeMillis() - delta;
if (// third of a tick
delta > 1000 / 20 / 3) {
logger.warn("Command Execute Timing: {} {} | {}ms ({}%)", this.alias, arguments, delta, delta * 100 / (1000 / 20));
}
manager.logExecution(source, ran, alias, arguments);
return CommandResult.success();
} catch (Exception e) {
logger.error(e, "An Unknown Exception occurred while executing a command! Command: {}", alias + " " + arguments);
return CommandResult.empty();
}
}
use of org.cubeengine.butler.CommandInvocation in project core by CubeEngine.
the class EnchantmentParser method suggest.
@Override
public List<String> suggest(Class clazz, CommandInvocation invocation) {
CommandSource sender = (CommandSource) invocation.getCommandSource();
ItemStack item = sender instanceof Player ? ((Player) sender).getItemInHand(HandTypes.MAIN_HAND).orElse(null) : null;
String token = invocation.currentToken();
return Sponge.getRegistry().getAllOf(EnchantmentType.class).stream().filter(e -> item == null || e.canBeAppliedToStack(item)).map(e -> e.getTranslation().get().replace(" ", "")).filter(name -> name.toLowerCase().startsWith(token.toLowerCase())).collect(Collectors.toList());
}
Aggregations