package valandur.webapi.cache.command;

import org.spongepowered.api.command.CommandMapping;
import org.spongepowered.api.text.Text;
import valandur.webapi.api.cache.command.ICachedCommand;
import valandur.webapi.cache.CachedObject;

import static valandur.webapi.command.CommandSource.instance;

public class CachedCommand extends CachedObject implements ICachedCommand {

    private String name;
    @Override
    public String getName() {
        return name;
    }

    private String description;
    @Override
    public String getDescription() {
        return description;
    }

    private String[] aliases;
    @Override
    public String[] getAliases() {
        return aliases;
    }

    private String usage;
    @Override
    public String getUsage() {
        return usage;
    }

    private String help;
    @Override
    public String getHelp() {
        return help;
    }


    public CachedCommand(CommandMapping cmd) {
        super(null);

        this.name = cmd.getPrimaryAlias();
        this.aliases = cmd.getAllAliases().toArray(new String[cmd.getAllAliases().size()]);
        try {
            this.usage = cmd.getCallable().getUsage(instance).toPlain();
        } catch (Exception ignored) {}
        this.description = cmd.getCallable().getShortDescription(instance).orElse(Text.EMPTY).toPlain();
        this.help = cmd.getCallable().getHelp(instance).orElse(Text.EMPTY).toPlain();
    }

    @Override
    public String getLink() {
        return "/api/cmd/" + name;
    }
}

@@ -1189,43 +1189,8 @@
     
-    %7D catch (Exception ignored) %7B%7D%0A
     
@@ -1282,32 +1282,36 @@
 PTY).toPlain();%0A
+    
         this.hel
@@ -1376,24 +1376,63 @@
 .toPlain();%0A
+        %7D catch (Exception ignored) %7B%7D%0A
     %7D%0A%0A    @

Fix NPE when caching commands