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