Search in sources :

Example 1 with Debug

use of github.scarsz.discordsrv.Debug in project DiscordSRV by Scarsz.

the class CommandDebugger method execute.

@Command(commandNames = { "debugger" }, helpMessage = "A toggleable timings-like command to dump debug information to bin.scarsz.me", permission = "discordsrv.debug")
public static void execute(CommandSender sender, String[] args) {
    List<String> arguments = new ArrayList<>(Arrays.asList(args));
    String subCommand;
    if (arguments.isEmpty()) {
        subCommand = "start";
    } else {
        subCommand = arguments.remove(0);
    }
    boolean upload = false;
    if (subCommand.equalsIgnoreCase("start") || subCommand.equalsIgnoreCase("on")) {
        Set<String> validArguments = new HashSet<>();
        for (String argument : arguments) {
            boolean anyValid = false;
            for (Debug value : Debug.values()) {
                if (value.matches(argument)) {
                    anyValid = true;
                    break;
                }
            }
            if (!anyValid) {
                sender.sendMessage(ChatColor.RED + "Invalid debug category: " + ChatColor.DARK_RED + argument);
                continue;
            }
            validArguments.add(argument);
        }
        if (validArguments.isEmpty()) {
            DiscordSRV.getPlugin().getDebuggerCategories().add(Debug.UNCATEGORIZED.name());
        } else {
            DiscordSRV.getPlugin().getDebuggerCategories().addAll(validArguments);
        }
        sender.sendMessage(ChatColor.DARK_AQUA + "Debugger enabled, use " + ChatColor.GRAY + "/discordsrv debugger stop " + ChatColor.DARK_AQUA + "to stop debugging or " + ChatColor.GRAY + "/discordsrv debugger upload " + ChatColor.DARK_AQUA + "to stop debugging and generate a debug report");
        return;
    } else if (subCommand.equalsIgnoreCase("stop") || subCommand.equalsIgnoreCase("off") || (upload = subCommand.equalsIgnoreCase("upload"))) {
        DiscordSRV.getPlugin().getDebuggerCategories().clear();
        if (upload) {
            CommandDebug.execute(sender, arguments.toArray(new String[0]));
        } else {
            sender.sendMessage(ChatColor.DARK_AQUA + "Debugger disabled");
        }
        return;
    }
    sender.sendMessage(ChatColor.RED + "Invalid subcommand " + ChatColor.DARK_RED + subCommand);
}
Also used : Debug(github.scarsz.discordsrv.Debug)

Aggregations

Debug (github.scarsz.discordsrv.Debug)1