package valandur.webapi.cache;

import com.fasterxml.jackson.annotation.JsonProperty;
import org.spongepowered.api.command.CommandMapping;
import valandur.webapi.misc.WebAPICommandSource;

import java.util.Optional;

public class CachedCommand extends CachedObject {

    @JsonProperty
    public String name;

    @JsonProperty
    public String description;

    public Object[] aliases;
    public String usage;
    public String help;


    public static CachedCommand copyFrom(CommandMapping cmd) {
        CachedCommand cache = new CachedCommand();

        cache.name = cmd.getPrimaryAlias();
        cache.aliases = cmd.getAllAliases().toArray();
        cache.usage = cmd.getCallable().getUsage(WebAPICommandSource.instance).toPlain();
        cache.description = cmd.getCallable().getShortDescription(WebAPICommandSource.instance).orElse(null).toPlain();
        cache.help = cmd.getCallable().getHelp(WebAPICommandSource.instance).orElse(null).toPlain();

        return cache;
    }

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

@@ -132,16 +132,56 @@
 apping;%0A
+import org.spongepowered.api.text.Text;%0A
 import v
@@ -873,36 +873,42 @@
 nstance).orElse(
-null
+Text.EMPTY
 ).toPlain();%0A   
@@ -992,12 +992,18 @@
 lse(
-null
+Text.EMPTY
 ).to

Fix commands without descriptions causing crash on plugin load