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

Method highlightChatLine

Minecraft-Utils/1.13/src/Gui2ndChat.java:367–413  ·  view source on GitHub ↗
(ij chatComponent, int x, int y, int alpha)

Source from the content-addressed store, hash-verified

365 }
366
367 public static void highlightChatLine(ij chatComponent, int x, int y, int alpha) {
368 List<String> highlightWords;
369 boolean onlyWordMatch;
370 String chatSearchText = MinecraftFactory.getClassProxyCallback().getChatSearchText();
371 if (!Strings.isNullOrEmpty(chatSearchText)) {
372 onlyWordMatch = false;
373 highlightWords = ImmutableList.of(chatSearchText);
374 } else {
375 onlyWordMatch = true;
376 highlightWords = MinecraftFactory.getClassProxyCallback().getHighlightWords();
377 }
378 if (highlightWords.isEmpty()) {
379 return;
380 }
381 String builder = "";
382 for (ij textComponent : chatComponent) {
383 int currIndex = builder.length();
384 String formattingCode = textComponent.b().k();
385 String text = textComponent.d();
386 builder += formattingCode + text + ChatColor.RESET;
387 text = ChatColor.stripColor(text.toLowerCase(Locale.ROOT));
388
389 for (String search : highlightWords) {
390 search = search.replace("%player%", MinecraftFactory.getVars().getGameProfile().getName()).toLowerCase(Locale.ROOT);
391 for (int nameIndex = builder.toLowerCase(Locale.ROOT).indexOf(search, currIndex), unformattedIndex = text.indexOf(search); nameIndex != -1 && unformattedIndex != -1;
392 nameIndex = builder.toLowerCase(Locale.ROOT).indexOf(search, nameIndex + search.length()), unformattedIndex = 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}

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