Search in sources :

Example 1 with TextColor

use of me.earth.earthhack.impl.util.text.TextColor in project 3arthh4ck by 3arthqu4ke.

the class Media method compile.

/**
 * Creates a regex that matches the name but with all possible
 * colorcodes between the letters. This is important for some
 * chat messages and servers with multiColored names.
 *
 * @param name the name to get a regex from
 * @return a pattern for the name.
 */
private Pattern compile(String name) {
    cache.clear();
    if (name == null) {
        return null;
    }
    StringBuilder regex = new StringBuilder("(?<!").append(TextColor.SECTIONSIGN).append(")(");
    char[] array = name.toCharArray();
    for (int i = 0; i < array.length; i++) {
        char c = array[i];
        regex.append(c);
        if (i != array.length - 1) {
            for (TextColor textColor : TextColor.values()) {
                if (textColor == TextColor.None) {
                    continue;
                }
                String color = textColor.getColor();
                regex.append("[").append(color).append("]").append("*");
            }
        }
    }
    return Pattern.compile(regex.append(")").toString());
}
Also used : TextColor(me.earth.earthhack.impl.util.text.TextColor) RemovingString(me.earth.earthhack.impl.modules.client.autoconfig.RemovingString)

Aggregations

RemovingString (me.earth.earthhack.impl.modules.client.autoconfig.RemovingString)1 TextColor (me.earth.earthhack.impl.util.text.TextColor)1