MCPcopy Create free account
hub / github.com/5zig/The-5zig-Mod / highlightChatLine

Method highlightChatLine

Minecraft-Utils/1.10.2/src/Gui2ndChat.java:372–418  ·  view source on GitHub ↗
(ey chatComponent, int x, int y, int alpha)

Source from the content-addressed store, hash-verified

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

Callers 1

drawMethod · 0.95

Calls 15

getClassProxyCallbackMethod · 0.95
stripColorMethod · 0.95
getVarsMethod · 0.95
drawRectMethod · 0.95
isEmptyMethod · 0.80
getChatSearchTextMethod · 0.65
getHighlightWordsMethod · 0.65
getGameProfileMethod · 0.65
getStringWidthMethod · 0.65
getFontHeightMethod · 0.65
lengthMethod · 0.45

Tested by

no test coverage detected