private void drawColoredText(Graphics2D g, String text, int chatType, int startX, int y) {

        int currentX = startX;

        g.setColor(colorForChatType(chatType));

        Pattern pattern = Pattern.compile("<(.*?)>");
        Matcher matcher = pattern.matcher(text);
        int foundMatches = 0;
        int[] colorIndexes = new int[20];
        Color[] colors = new Color[20];
        int totalSkippedCharacters = 0;
        while (matcher.find()) {
            colorIndexes[foundMatches] = matcher.start() - totalSkippedCharacters;
            totalSkippedCharacters += matcher.group().length();
            colors[foundMatches++] = colorForText(matcher.group().replaceAll("[<>]", ""));
        }
        text = text.replaceAll("<(.*?)>", "");
        int colorIndex = 0;
        for (int i = 0; i < text.length(); i++) {
            char currentChar = text.charAt(i);
            if (foundMatches > 0) {
                if (colorIndexes[colorIndex] == i) {
                    g.setColor(colors[colorIndex++]);
                }
            }
            g.drawString("" + currentChar, currentX, y);
            currentX += WzFont.getStringWidth(g, "" + currentChar);
        }
    }