/** * Applies the size filter * * @param sb message to filter * @param front true if apply front sizer, false for back sizer * @param player whether or not it is for a player */ private void filterSizer(StringBuilder sb, boolean front, boolean player) { Pattern regex = front ? EXPAND_FRONT : EXPAND_BACK; Matcher match = regex.matcher(sb); int size = sb.length(); while (match.find()) { int playerSize = Integer.parseInt(match.group(2)); int consoleSize = Integer.parseInt(match.group(3)); String string = match.group(1); if (player) { sb.replace( match.start() + sb.length() - size, match.end(), (TextSizer.measureString(string) > playerSize - 2 ? string : TextSizer.expand(string, playerSize, front))); } else { sb.replace( match.start() + sb.length() - size, match.end(), (string.length() > consoleSize ? string : TextSizer.expandConsole(string, consoleSize, front))); } } }