|
29 | 29 | import codes.biscuit.skyblockaddons.misc.scheduler.Scheduler; |
30 | 30 | import codes.biscuit.skyblockaddons.misc.scheduler.SkyblockRunnable; |
31 | 31 | import codes.biscuit.skyblockaddons.utils.*; |
32 | | -import codes.biscuit.skyblockaddons.utils.objects.IntPair; |
33 | 32 | import com.google.common.collect.Sets; |
34 | 33 | import com.google.common.math.DoubleMath; |
35 | 34 | import lombok.Getter; |
36 | | -import lombok.Setter; |
37 | 35 | import net.minecraft.block.Block; |
38 | 36 | import net.minecraft.block.BlockPrismarine; |
39 | 37 | import net.minecraft.block.BlockStone; |
|
43 | 41 | import net.minecraft.client.audio.SoundCategory; |
44 | 42 | import net.minecraft.client.entity.EntityOtherPlayerMP; |
45 | 43 | import net.minecraft.client.entity.EntityPlayerSP; |
46 | | -import net.minecraft.client.gui.GuiPlayerTabOverlay; |
47 | 44 | import net.minecraft.client.gui.inventory.GuiChest; |
48 | | -import net.minecraft.client.network.NetHandlerPlayClient; |
49 | 45 | import net.minecraft.client.network.NetworkPlayerInfo; |
50 | 46 | import net.minecraft.client.settings.KeyBinding; |
51 | 47 | import net.minecraft.entity.Entity; |
52 | 48 | import net.minecraft.entity.item.EntityArmorStand; |
53 | | -import net.minecraft.entity.monster.EntityBlaze; |
54 | 49 | import net.minecraft.entity.monster.EntityEnderman; |
55 | 50 | import net.minecraft.entity.monster.EntityMagmaCube; |
56 | 51 | import net.minecraft.entity.monster.EntitySlime; |
|
64 | 59 | import net.minecraft.item.EnumDyeColor; |
65 | 60 | import net.minecraft.item.ItemStack; |
66 | 61 | import net.minecraft.nbt.NBTTagCompound; |
67 | | -import net.minecraft.scoreboard.ScorePlayerTeam; |
68 | 62 | import net.minecraft.util.*; |
69 | | -import net.minecraft.world.WorldSettings; |
70 | 63 | import net.minecraftforge.client.event.ClientChatReceivedEvent; |
71 | 64 | import net.minecraftforge.client.event.GuiScreenEvent; |
72 | 65 | import net.minecraftforge.client.event.sound.PlaySoundEvent; |
|
79 | 72 | import net.minecraftforge.event.entity.player.AttackEntityEvent; |
80 | 73 | import net.minecraftforge.event.entity.player.ItemTooltipEvent; |
81 | 74 | import net.minecraftforge.event.entity.player.PlayerInteractEvent; |
82 | | -import net.minecraftforge.event.world.ChunkEvent; |
83 | 75 | import net.minecraftforge.fml.common.eventhandler.EventPriority; |
84 | 76 | import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; |
85 | 77 | import net.minecraftforge.fml.common.gameevent.InputEvent; |
@@ -114,6 +106,8 @@ public class PlayerListener { |
114 | 106 | private static final Pattern NEXT_TIER_PET_PROGRESS = Pattern.compile("Next tier: (?<total>[0-9,]+)/.*"); |
115 | 107 | private static final Pattern MAXED_TIER_PET_PROGRESS = Pattern.compile(".*: (?<total>[0-9,]+)"); |
116 | 108 | private static final Pattern SPIRIT_SCEPTRE_MESSAGE_PATTERN = Pattern.compile("Your (?:Implosion|Spirit Sceptre) hit (?<hitEnemies>[0-9]+) enem(?:y|ies) for (?<dealtDamage>[0-9]{1,3}(?:,[0-9]{3})*(?:\\.[0-9]+)*) damage\\."); |
| 109 | + private static final Pattern PROFILE_TYPE_SYMBOL = Pattern.compile("(?i)§[0-9A-FK-ORZ][♲Ⓑ]"); |
| 110 | + private static final Pattern NETHER_FACTION_SYMBOL = Pattern.compile("(?i)§[0-9A-FK-ORZ][⚒ቾ]"); |
117 | 111 |
|
118 | 112 | private static final Set<String> SOUP_RANDOM_MESSAGES = new HashSet<>(Arrays.asList("I feel like I can fly!", "What was in that soup?", |
119 | 113 | "Hmm… tasty!", "Hmm... tasty!", "You can now fly for 2 minutes.", "Your flight has been extended for 2 extra minutes.", |
@@ -174,7 +168,7 @@ public class PlayerListener { |
174 | 168 | private final ActionBarParser actionBarParser = new ActionBarParser(); |
175 | 169 |
|
176 | 170 | // For caching for the PROFILE_TYPE_IN_CHAT feature, saves the last MAX_SIZE names. |
177 | | - private final LinkedHashMap<String, String> namesWithType = new LinkedHashMap<String, String>(){ |
| 171 | + private final LinkedHashMap<String, String> namesWithSymbols = new LinkedHashMap<String, String>(){ |
178 | 172 | private final int MAX_SIZE = 80; |
179 | 173 |
|
180 | 174 | protected boolean removeEldestEntry(Map.Entry<String, String> eldest) |
@@ -380,46 +374,7 @@ public void onChatReceive(ClientChatReceivedEvent e) { |
380 | 374 | // Tries to check if a message is from a player to add the player profile icon |
381 | 375 | } else if (main.getConfigValues().isEnabled(Feature.PLAYER_SYMBOLS_IN_CHAT) && |
382 | 376 | unformattedText.contains(":")) { |
383 | | - // For some reason guild chat messages still contain color codes in the unformatted text |
384 | | - String username = TextUtils.stripColor(unformattedText.split(":")[0]); |
385 | | - // Remove chat channel prefix |
386 | | - if(username.contains(">")){ |
387 | | - username = username.substring(username.indexOf('>')+1); |
388 | | - } |
389 | | - // Remove rank prefix and guild rank suffix if exists |
390 | | - username = TextUtils.trimWhitespaceAndResets(username.replaceAll("\\[[^\\[\\]]*\\]","")); |
391 | | - // Check if stripped username is a real username or the player |
392 | | - if (TextUtils.isUsername(username) || username.equals("**MINECRAFTUSERNAME**")) { |
393 | | - EntityPlayer chattingPlayer = Minecraft.getMinecraft().theWorld.getPlayerEntityByName(username); |
394 | | - // Put player in cache if found nearby |
395 | | - if(chattingPlayer != null) { |
396 | | - namesWithType.put(username, chattingPlayer.getDisplayName().getSiblings().get(0).getUnformattedText()); |
397 | | - } |
398 | | - // Otherwise search in tablist |
399 | | - else { |
400 | | - Collection<NetworkPlayerInfo> networkPlayerInfos = Minecraft.getMinecraft().thePlayer.sendQueue.getPlayerInfoMap(); |
401 | | - String finalUsername = username; |
402 | | - Optional<NetworkPlayerInfo> result = networkPlayerInfos.stream().filter(npi -> npi.getDisplayName() != null).filter(npi -> TextUtils.stripUsername(npi.getDisplayName().getUnformattedText()).equals(finalUsername)).findAny(); |
403 | | - // Put in cache if found |
404 | | - if(result.isPresent()){ |
405 | | - namesWithType.put(username, result.get().getDisplayName().getFormattedText()); |
406 | | - } |
407 | | - } |
408 | | - // Check cache regardless if found nearby |
409 | | - if(namesWithType.containsKey(username)){ |
410 | | - IChatComponent oldMessage = e.message; |
411 | | - String newName = namesWithType.get(username); |
412 | | - if(main.getConfigValues().isDisabled(Feature.SHOW_PROFILE_TYPE)){ |
413 | | - newName = newName.replaceAll("(?i) *(§[0-9a-fk-orz])*[♲Ⓑ](§[0-9a-fk-orz])*",""); |
414 | | - } |
415 | | - if(main.getConfigValues().isDisabled(Feature.SHOW_NETHER_FACTION)){ |
416 | | - newName = newName.replaceAll("(?i) *(§[0-9a-fk-orz])*[⚒ቾ](§[0-9a-fk-orz])*",""); |
417 | | - } |
418 | | - newName = newName.replaceAll("(?i) *(§[0-9a-fk-orz])*\\[[^\\[\\]]*\\](§[0-9a-fk-orz])*", ""); // Soopyv2 compatibility |
419 | | - e.message = new ChatComponentText(formattedText.replace(username, newName)); |
420 | | - e.message.setChatStyle(oldMessage.getChatStyle()); |
421 | | - } |
422 | | - } |
| 377 | + playerSymbolsDisplay(e, unformattedText); |
423 | 378 | } |
424 | 379 |
|
425 | 380 | if (main.getConfigValues().isEnabled(Feature.NO_ARROWS_LEFT_ALERT)) { |
@@ -510,6 +465,64 @@ public void onChatReceive(ClientChatReceivedEvent e) { |
510 | 465 | } |
511 | 466 | } |
512 | 467 |
|
| 468 | + private void playerSymbolsDisplay(ClientChatReceivedEvent e, String unformattedText) { |
| 469 | + // For some reason guild chat messages still contain color codes in the unformatted text |
| 470 | + String username = TextUtils.stripColor(unformattedText.split(":")[0]); |
| 471 | + // Remove chat channel prefix |
| 472 | + if(username.contains(">")){ |
| 473 | + username = username.substring(username.indexOf('>')+1); |
| 474 | + } |
| 475 | + // Remove rank prefix and guild rank suffix if exists |
| 476 | + username = TextUtils.trimWhitespaceAndResets(username.replaceAll("\\[[^\\[\\]]*\\]","")); |
| 477 | + // Check if stripped username is a real username or the player |
| 478 | + if (TextUtils.isUsername(username) || username.equals("**MINECRAFTUSERNAME**")) { |
| 479 | + EntityPlayer chattingPlayer = Minecraft.getMinecraft().theWorld.getPlayerEntityByName(username); |
| 480 | + // Put player in cache if found nearby |
| 481 | + if(chattingPlayer != null) { |
| 482 | + namesWithSymbols.put(username, chattingPlayer.getDisplayName().getSiblings().get(0).getUnformattedText()); |
| 483 | + } |
| 484 | + // Otherwise search in tablist |
| 485 | + else { |
| 486 | + Collection<NetworkPlayerInfo> networkPlayerInfos = Minecraft.getMinecraft().thePlayer.sendQueue.getPlayerInfoMap(); |
| 487 | + String finalUsername = username; |
| 488 | + Optional<NetworkPlayerInfo> result = networkPlayerInfos.stream().filter(npi -> npi.getDisplayName() != null).filter(npi -> TextUtils.stripUsername(npi.getDisplayName().getUnformattedText()).equals(finalUsername)).findAny(); |
| 489 | + // Put in cache if found |
| 490 | + if(result.isPresent()){ |
| 491 | + namesWithSymbols.put(username, result.get().getDisplayName().getFormattedText()); |
| 492 | + } |
| 493 | + } |
| 494 | + // Check cache regardless if found nearby |
| 495 | + if(namesWithSymbols.containsKey(username)){ |
| 496 | + IChatComponent oldMessage = e.message; |
| 497 | + String usernameWithSymbols = namesWithSymbols.get(username); |
| 498 | + String suffix = " "; |
| 499 | + if(main.getConfigValues().isEnabled(Feature.SHOW_PROFILE_TYPE)){ |
| 500 | + Matcher m = PROFILE_TYPE_SYMBOL.matcher(usernameWithSymbols); |
| 501 | + if(m.find()){ |
| 502 | + suffix+=m.group(0); |
| 503 | + } |
| 504 | + } |
| 505 | + if(main.getConfigValues().isEnabled(Feature.SHOW_NETHER_FACTION)){ |
| 506 | + Matcher m = NETHER_FACTION_SYMBOL.matcher(usernameWithSymbols); |
| 507 | + if(m.find()){ |
| 508 | + suffix+=m.group(0); |
| 509 | + } |
| 510 | + } |
| 511 | + if(!suffix.equals(" ")) { |
| 512 | + String finalSuffix = suffix; |
| 513 | + String finalUsername = username; |
| 514 | + TextUtils.recursiveTransformChatComponent(oldMessage, component -> { |
| 515 | + if (component instanceof ChatComponentText & ((ChatComponentText)component).text.contains(finalUsername)) { |
| 516 | + ChatComponentText textComponent = (ChatComponentText) component; |
| 517 | + textComponent.text = textComponent.text.replace(finalUsername, finalUsername + finalSuffix); |
| 518 | + } |
| 519 | + } |
| 520 | + ); |
| 521 | + } |
| 522 | + } |
| 523 | + } |
| 524 | + } |
| 525 | + |
513 | 526 | /** |
514 | 527 | * Acts as a callback to set the actionbar message after other mods have a chance to look at the message |
515 | 528 | */ |
|
0 commit comments