(ey chatComponent, int x, int y, int alpha)
| 377 | } |
| 378 | |
| 379 | public static void highlightChatLine(ey chatComponent, int x, int y, int alpha) { |
| 380 | List<String> highlightWords; |
| 381 | boolean onlyWordMatch; |
| 382 | String chatSearchText = MinecraftFactory.getClassProxyCallback().getChatSearchText(); |
| 383 | if (!Strings.isNullOrEmpty(chatSearchText)) { |
| 384 | onlyWordMatch = false; |
| 385 | highlightWords = ImmutableList.of(chatSearchText); |
| 386 | } else { |
| 387 | onlyWordMatch = true; |
| 388 | highlightWords = MinecraftFactory.getClassProxyCallback().getHighlightWords(); |
| 389 | } |
| 390 | if (highlightWords.isEmpty()) { |
| 391 | return; |
| 392 | } |
| 393 | String builder = ""; |
| 394 | for (ey textComponent : chatComponent) { |
| 395 | int currIndex = builder.length(); |
| 396 | String formattingCode = textComponent.b().k(); |
| 397 | String text = textComponent.e(); |
| 398 | builder += formattingCode + text + ChatColor.RESET; |
| 399 | text = ChatColor.stripColor(text.toLowerCase(Locale.ROOT)); |
| 400 | |
| 401 | for (String search : highlightWords) { |
| 402 | search = search.replace("%player%", MinecraftFactory.getVars().getGameProfile().getName()).toLowerCase(Locale.ROOT); |
| 403 | for (int nameIndex = builder.toLowerCase(Locale.ROOT).indexOf(search, currIndex), unformattedIndex = text.indexOf(search); nameIndex != -1 && unformattedIndex != -1; |
| 404 | nameIndex = builder.toLowerCase(Locale.ROOT).indexOf(search, nameIndex + search.length()), unformattedIndex = text.indexOf(search, unformattedIndex + search.length())) { |
| 405 | if (onlyWordMatch) { |
| 406 | if (unformattedIndex > 0) { |
| 407 | char previousChar = Character.toLowerCase(text.charAt(unformattedIndex - 1)); |
| 408 | if ((previousChar >= 'a' && previousChar <= 'z') || (previousChar >= '0' && previousChar <= '9')) { |
| 409 | continue; |
| 410 | } |
| 411 | } |
| 412 | if (unformattedIndex + search.length() < text.length()) { |
| 413 | char nextChar = text.charAt(unformattedIndex + search.length()); |
| 414 | if ((nextChar >= 'a' && nextChar <= 'z') || (nextChar >= '0' && nextChar <= '9')) { |
| 415 | continue; |
| 416 | } |
| 417 | } |
| 418 | } |
| 419 | int offset = MinecraftFactory.getVars().getStringWidth(builder.substring(0, nameIndex)); |
| 420 | int width = MinecraftFactory.getVars().getStringWidth(formattingCode + builder.substring(nameIndex, nameIndex + search.length())); |
| 421 | Gui.drawRect(x + offset, y, x + offset + width, y + MinecraftFactory.getVars().getFontHeight(), 0xffe338 + (Math.min(0x80, alpha) << 24)); |
| 422 | } |
| 423 | } |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | } |
no test coverage detected