package com.nincraft.ninbot.command.util;

import com.nincraft.ninbot.Ninbot;
import com.nincraft.ninbot.command.AbstractCommand;
import com.nincraft.ninbot.util.MessageUtils;
import com.nincraft.ninbot.util.Reference;
import lombok.Getter;
import net.dv8tion.jda.core.entities.MessageChannel;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;

public class CommandParser {

    @Getter
    private static final CommandParser instance = new CommandParser();
    @Getter
    private Map<String, AbstractCommand> commandHashMap;

    public CommandParser() {
        commandHashMap = new HashMap<>();
    }

    public void parseEvent(MessageReceivedEvent event) {
        String message = event.getMessage().getContent();
        if (StringUtils.isNotBlank(message)) {
            AbstractCommand command = commandHashMap.get(getCommand(message));
            if (command != null) {
                try {
                    command.execute(event);
                } catch (Exception e) {
                    MessageUtils.sendMessage(getChannel(Reference.OCW_DEBUG_CHANNEL), e.toString() +
                            "\n" + e.getStackTrace()[0].toString());
                }
            } else {
                MessageUtils.reactUnknownResponse(event.getMessage());
            }
        }
    }

    private MessageChannel getChannel(String channel) {
        return Ninbot.getJda().getGuildById(Reference.OCW_SERVER_ID).getTextChannelById(channel);
    }

    private String getCommand(String message) {
        String[] splitMessage = message.split(" ");
        if (splitMessage.length > 1) {
            return splitMessage[1] != null ? splitMessage[1].toLowerCase() : StringUtils.EMPTY;
        }
        return null;
    }

    public void addCommand(String commandName, AbstractCommand command) {
        commandHashMap.put(commandName, command);
    }
}

@@ -234,16 +234,51 @@
 Getter;%0A
+import lombok.extern.log4j.Log4j2;%0A
 import n
@@ -482,16 +482,24 @@
 l.Map;%0A%0A
+@Log4j2%0A
 public c
@@ -1129,24 +1129,106 @@
 eption e) %7B%0A
+                    log.error(%22Error executing command %22 + command.getName(), e);%0A
             

Add logging