Search in sources :

Example 1 with ViaSubCommand

use of com.viaversion.viaversion.api.command.ViaSubCommand in project ViaVersion by ViaVersion.

the class ViaCommandHandler method showHelp.

/**
 * Shows the ViaVersion help to a sender
 *
 * @param sender The sender to send the help to
 */
@Override
public void showHelp(ViaCommandSender sender) {
    Set<ViaSubCommand> allowed = calculateAllowedCommands(sender);
    if (allowed.isEmpty()) {
        sender.sendMessage(color("&cYou are not allowed to use these commands!"));
        return;
    }
    sender.sendMessage(color("&aViaVersion &c" + Via.getPlatform().getPluginVersion()));
    sender.sendMessage(color("&6Commands:"));
    for (ViaSubCommand cmd : allowed) {
        sender.sendMessage(color(String.format("&2/viaversion %s &7- &6%s", cmd.usage(), cmd.description())));
    }
    allowed.clear();
}
Also used : ViaSubCommand(com.viaversion.viaversion.api.command.ViaSubCommand)

Example 2 with ViaSubCommand

use of com.viaversion.viaversion.api.command.ViaSubCommand in project ViaVersion by ViaVersion.

the class ViaCommandHandler method onTabComplete.

@Override
public List<String> onTabComplete(ViaCommandSender sender, String[] args) {
    Set<ViaSubCommand> allowed = calculateAllowedCommands(sender);
    List<String> output = new ArrayList<>();
    // SubCommands tabcomplete
    if (args.length == 1) {
        if (!args[0].isEmpty()) {
            for (ViaSubCommand sub : allowed) {
                if (sub.name().toLowerCase().startsWith(args[0].toLowerCase(Locale.ROOT))) {
                    output.add(sub.name());
                }
            }
        } else {
            for (ViaSubCommand sub : allowed) {
                output.add(sub.name());
            }
        }
    } else // Let the SubCommand handle it
    if (args.length >= 2) {
        if (getSubCommand(args[0]) != null) {
            ViaSubCommand sub = getSubCommand(args[0]);
            if (!allowed.contains(sub)) {
                return output;
            }
            String[] subArgs = Arrays.copyOfRange(args, 1, args.length);
            List<String> tab = sub.onTabComplete(sender, subArgs);
            Collections.sort(tab);
            return tab;
        }
    }
    return output;
}
Also used : ArrayList(java.util.ArrayList) ViaSubCommand(com.viaversion.viaversion.api.command.ViaSubCommand) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with ViaSubCommand

use of com.viaversion.viaversion.api.command.ViaSubCommand in project ViaVersion by ViaVersion.

the class ViaCommandHandler method onCommand.

@Override
public boolean onCommand(ViaCommandSender sender, String[] args) {
    if (args.length == 0) {
        showHelp(sender);
        return false;
    }
    if (!hasSubCommand(args[0])) {
        sender.sendMessage(color("&cThis command does not exist."));
        showHelp(sender);
        return false;
    }
    ViaSubCommand handler = getSubCommand(args[0]);
    if (!hasPermission(sender, handler.permission())) {
        sender.sendMessage(color("&cYou are not allowed to use this command!"));
        return false;
    }
    String[] subArgs = Arrays.copyOfRange(args, 1, args.length);
    boolean result = handler.execute(sender, subArgs);
    if (!result) {
        sender.sendMessage("Usage: /viaversion " + handler.usage());
    }
    return result;
}
Also used : ViaSubCommand(com.viaversion.viaversion.api.command.ViaSubCommand)

Aggregations

ViaSubCommand (com.viaversion.viaversion.api.command.ViaSubCommand)3 ArrayList (java.util.ArrayList)1 List (java.util.List)1