/** * 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))); } } }
/** * Applies the break filter * * @param sb message to filter */ private void filterBreak(StringBuilder sb) { int index = sb.indexOf("{break}"); if (index >= 0) { sb.delete(index, index + 7); String without = sb.toString(); int size = TextSizer.measureString(without); for (int i = 0; i < (320 - size) / 6; i++) { sb.insert(index, '-'); } } }