// Path: src/main/java/myessentials/exception/FormatException.java
// public class FormatException extends RuntimeException {
// 
//     public FormatException(String message) {
//         super(message);
//     }
// 
// }
// 
// Path: src/main/java/myessentials/utils/ColorUtils.java
// public class ColorUtils {
// 
//     public static final ChatStyle stylePlayer = new ChatStyle().setColor(EnumChatFormatting.WHITE);
//     public static final ChatStyle styleOwner = new ChatStyle().setColor(EnumChatFormatting.RED);
//     public static final ChatStyle styleTown = new ChatStyle().setColor(EnumChatFormatting.GOLD);
//     public static final ChatStyle styleSelectedTown = new ChatStyle().setColor(EnumChatFormatting.GREEN);
//     public static final ChatStyle styleInfoText = new ChatStyle().setColor(EnumChatFormatting.GRAY);
//     public static final ChatStyle styleConfigurableFlag = new ChatStyle().setColor(EnumChatFormatting.GRAY);
//     public static final ChatStyle styleUnconfigurableFlag = new ChatStyle().setColor(EnumChatFormatting.DARK_GRAY);
//     public static final ChatStyle styleValueFalse = new ChatStyle().setColor(EnumChatFormatting.RED);
//     public static final ChatStyle styleValueRegular = new ChatStyle().setColor(EnumChatFormatting.GREEN);
//     public static final ChatStyle styleDescription = new ChatStyle().setColor(EnumChatFormatting.GRAY);
//     public static final ChatStyle styleCoords = new ChatStyle().setColor(EnumChatFormatting.BLUE);
//     public static final ChatStyle styleComma = new ChatStyle().setColor(EnumChatFormatting.WHITE);
//     public static final ChatStyle styleEmpty = new ChatStyle().setColor(EnumChatFormatting.RED);
//     public static final ChatStyle styleAdmin = new ChatStyle().setColor(EnumChatFormatting.RED);
//     public static final ChatStyle styleGroupType = new ChatStyle().setColor(EnumChatFormatting.BLUE);
//     public static final ChatStyle styleGroupText = new ChatStyle().setColor(EnumChatFormatting.GRAY);
//     public static final ChatStyle styleGroupParents = new ChatStyle().setColor(EnumChatFormatting.WHITE);
//     public static final ChatStyle styleGroup = new ChatStyle().setColor(EnumChatFormatting.BLUE);
// 
//     public static final Map<Character, EnumChatFormatting> colorMap = new HashMap<Character, EnumChatFormatting>();
//     static {
//         ColorUtils.colorMap.put('0', EnumChatFormatting.BLACK);
//         ColorUtils.colorMap.put('1', EnumChatFormatting.DARK_BLUE);
//         ColorUtils.colorMap.put('2', EnumChatFormatting.DARK_GREEN);
//         ColorUtils.colorMap.put('3', EnumChatFormatting.DARK_AQUA);
//         ColorUtils.colorMap.put('4', EnumChatFormatting.DARK_RED);
//         ColorUtils.colorMap.put('5', EnumChatFormatting.DARK_PURPLE);
//         ColorUtils.colorMap.put('6', EnumChatFormatting.GOLD);
//         ColorUtils.colorMap.put('7', EnumChatFormatting.GRAY);
//         ColorUtils.colorMap.put('8', EnumChatFormatting.DARK_GRAY);
//         ColorUtils.colorMap.put('9', EnumChatFormatting.BLUE);
//         ColorUtils.colorMap.put('a', EnumChatFormatting.GREEN);
//         ColorUtils.colorMap.put('b', EnumChatFormatting.AQUA);
//         ColorUtils.colorMap.put('c', EnumChatFormatting.RED);
//         ColorUtils.colorMap.put('d', EnumChatFormatting.LIGHT_PURPLE);
//         ColorUtils.colorMap.put('e', EnumChatFormatting.YELLOW);
//         ColorUtils.colorMap.put('f', EnumChatFormatting.WHITE);
//     }
// }


import myessentials.exception.FormatException;
import myessentials.utils.ColorUtils;
import net.minecraft.event.HoverEvent;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChatStyle;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IChatComponent;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
        return message;
    }

    private void addComponent(Iterator args) {
        // TODO: Instead of %s use other identifiers for lists of elements or container (maybe)

        Object currArg = args.next();
        if (currArg instanceof IChatFormat) {
            buffer.appendSibling(((IChatFormat) currArg).toChatMessage());
        } else if (currArg instanceof IChatComponent) {
            buffer.appendSibling((IChatComponent) currArg);
        } else if (currArg instanceof ChatComponentContainer) {
            resetBuffer();
            for (IChatComponent message : (ChatComponentContainer) currArg) {
                this.appendSibling(message);
            }
        }
    }

    private void processComponent(String componentString, Iterator args) {
        String[] parts = componentString.split("\\|", 2);

        if (parts.length == 2) {
            if (parts[0].contains("N")) {
                resetBuffer();
            }
            buffer.appendSibling(createComponent(parts, args));
        } else if (parts.length == 1 && parts[0].equals("%s")){
            addComponent(args);
        } else {
// Path: src/main/java/myessentials/exception/FormatException.java
// public class FormatException extends RuntimeException {
// 
//     public FormatException(String message) {
//         super(message);
//     }
// 
// }
// 
// Path: src/main/java/myessentials/utils/ColorUtils.java
// public class ColorUtils {
// 
//     public static final ChatStyle stylePlayer = new ChatStyle().setColor(EnumChatFormatting.WHITE);
//     public static final ChatStyle styleOwner = new ChatStyle().setColor(EnumChatFormatting.RED);
//     public static final ChatStyle styleTown = new ChatStyle().setColor(EnumChatFormatting.GOLD);
//     public static final ChatStyle styleSelectedTown = new ChatStyle().setColor(EnumChatFormatting.GREEN);
//     public static final ChatStyle styleInfoText = new ChatStyle().setColor(EnumChatFormatting.GRAY);
//     public static final ChatStyle styleConfigurableFlag = new ChatStyle().setColor(EnumChatFormatting.GRAY);
//     public static final ChatStyle styleUnconfigurableFlag = new ChatStyle().setColor(EnumChatFormatting.DARK_GRAY);
//     public static final ChatStyle styleValueFalse = new ChatStyle().setColor(EnumChatFormatting.RED);
//     public static final ChatStyle styleValueRegular = new ChatStyle().setColor(EnumChatFormatting.GREEN);
//     public static final ChatStyle styleDescription = new ChatStyle().setColor(EnumChatFormatting.GRAY);
//     public static final ChatStyle styleCoords = new ChatStyle().setColor(EnumChatFormatting.BLUE);
//     public static final ChatStyle styleComma = new ChatStyle().setColor(EnumChatFormatting.WHITE);
//     public static final ChatStyle styleEmpty = new ChatStyle().setColor(EnumChatFormatting.RED);
//     public static final ChatStyle styleAdmin = new ChatStyle().setColor(EnumChatFormatting.RED);
//     public static final ChatStyle styleGroupType = new ChatStyle().setColor(EnumChatFormatting.BLUE);
//     public static final ChatStyle styleGroupText = new ChatStyle().setColor(EnumChatFormatting.GRAY);
//     public static final ChatStyle styleGroupParents = new ChatStyle().setColor(EnumChatFormatting.WHITE);
//     public static final ChatStyle styleGroup = new ChatStyle().setColor(EnumChatFormatting.BLUE);
// 
//     public static final Map<Character, EnumChatFormatting> colorMap = new HashMap<Character, EnumChatFormatting>();
//     static {
//         ColorUtils.colorMap.put('0', EnumChatFormatting.BLACK);
//         ColorUtils.colorMap.put('1', EnumChatFormatting.DARK_BLUE);
//         ColorUtils.colorMap.put('2', EnumChatFormatting.DARK_GREEN);
//         ColorUtils.colorMap.put('3', EnumChatFormatting.DARK_AQUA);
//         ColorUtils.colorMap.put('4', EnumChatFormatting.DARK_RED);
//         ColorUtils.colorMap.put('5', EnumChatFormatting.DARK_PURPLE);
//         ColorUtils.colorMap.put('6', EnumChatFormatting.GOLD);
//         ColorUtils.colorMap.put('7', EnumChatFormatting.GRAY);
//         ColorUtils.colorMap.put('8', EnumChatFormatting.DARK_GRAY);
//         ColorUtils.colorMap.put('9', EnumChatFormatting.BLUE);
//         ColorUtils.colorMap.put('a', EnumChatFormatting.GREEN);
//         ColorUtils.colorMap.put('b', EnumChatFormatting.AQUA);
//         ColorUtils.colorMap.put('c', EnumChatFormatting.RED);
//         ColorUtils.colorMap.put('d', EnumChatFormatting.LIGHT_PURPLE);
//         ColorUtils.colorMap.put('e', EnumChatFormatting.YELLOW);
//         ColorUtils.colorMap.put('f', EnumChatFormatting.WHITE);
//     }
// }


// Path: src/main/java/myessentials/chat/api/ChatComponentFormatted.java
import myessentials.exception.FormatException;
import myessentials.utils.ColorUtils;
import net.minecraft.event.HoverEvent;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChatStyle;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IChatComponent;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;

        return message;
    }

    private void addComponent(Iterator args) {
        // TODO: Instead of %s use other identifiers for lists of elements or container (maybe)

        Object currArg = args.next();
        if (currArg instanceof IChatFormat) {
            buffer.appendSibling(((IChatFormat) currArg).toChatMessage());
        } else if (currArg instanceof IChatComponent) {
            buffer.appendSibling((IChatComponent) currArg);
        } else if (currArg instanceof ChatComponentContainer) {
            resetBuffer();
            for (IChatComponent message : (ChatComponentContainer) currArg) {
                this.appendSibling(message);
            }
        }
    }

    private void processComponent(String componentString, Iterator args) {
        String[] parts = componentString.split("\\|", 2);

        if (parts.length == 2) {
            if (parts[0].contains("N")) {
                resetBuffer();
            }
            buffer.appendSibling(createComponent(parts, args));
        } else if (parts.length == 1 && parts[0].equals("%s")){
            addComponent(args);
        } else {
            throw new FormatException("Format " + componentString + " is not valid. Valid format: {modifiers|text}");