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

Method highlightChatLine

Minecraft-Utils/1.12/src/Gui2ndChat.java:369–415  ·  view source on GitHub ↗
(hh chatComponent, int x, int y, int alpha)

Source from the content-addressed store, hash-verified

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

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
kMethod · 0.45

Tested by

no test coverage detected