From 6e5f013c6e27a7f806cdb0de5a4c35e20d484d5c Mon Sep 17 00:00:00 2001 From: syeyoung Date: Tue, 24 Aug 2021 16:29:19 +0900 Subject: Optimzied Network Player Info --- .../cosmetics/CustomNetworkPlayerInfo.java | 55 ++++++++++++++++++---- 1 file changed, 46 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/CustomNetworkPlayerInfo.java b/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/CustomNetworkPlayerInfo.java index 4bfa775a..cfbf1fc0 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/CustomNetworkPlayerInfo.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/CustomNetworkPlayerInfo.java @@ -36,23 +36,60 @@ public class CustomNetworkPlayerInfo extends NetworkPlayerInfo { public CustomNetworkPlayerInfo(S38PacketPlayerListItem.AddPlayerData p_i46295_1_) { super(p_i46295_1_); + setDisplayName(super.getDisplayName()); } - public IChatComponent getDisplayName() - { - String semi_name = super.getDisplayName() != null ? super.getDisplayName().getFormattedText() : ScorePlayerTeam.formatPlayerName(super.getPlayerTeam(), super.getGameProfile().getName()); - String actualName = ""; - for (String s : semi_name.split(" ")) { - if (TextUtils.stripColor(s).startsWith("[")) continue; - actualName = TextUtils.stripColor(s); + private IChatComponent displayName; + private String playernameLowercase; + private String unformatted; + private String actualName; + @Override + public void setDisplayName(IChatComponent displayNameIn) { + displayName = displayNameIn; + if (displayName == null) { + playernameLowercase = null; + unformatted = null; + return; + } + + unformatted = displayName.getUnformattedText(); + + + actualName = ""; + for (String s : unformatted.split(" ")) { + String strippped = TextUtils.stripColor(s); + if (strippped.startsWith("[")) continue; + actualName = strippped; break; } - List activeCosmetics = DungeonsGuide.getDungeonsGuide().getCosmeticsManager().getActiveCosmeticByPlayerNameLowerCase().get(actualName.toLowerCase()); + playernameLowercase = actualName.toLowerCase(); + } + public IChatComponent getDisplayName() + { + + String semi_name; + String actualName; + List activeCosmetics; + if (playernameLowercase != null) { + activeCosmetics = DungeonsGuide.getDungeonsGuide().getCosmeticsManager().getActiveCosmeticByPlayerNameLowerCase().get(playernameLowercase); + semi_name = unformatted; + actualName = this.actualName; + } else { + semi_name = ScorePlayerTeam.formatPlayerName(super.getPlayerTeam(), super.getGameProfile().getName()); + actualName = ""; + for (String s : semi_name.split(" ")) { + String strippped = TextUtils.stripColor(s); + if (strippped.startsWith("[")) continue; + actualName = strippped; + break; + } + activeCosmetics = DungeonsGuide.getDungeonsGuide().getCosmeticsManager().getActiveCosmeticByPlayerNameLowerCase().get(actualName.toLowerCase()); + } - if (activeCosmetics == null) return super.getDisplayName(); + if (activeCosmetics == null) return displayName; CosmeticData color=null; for (ActiveCosmetic activeCosmetic : activeCosmetics) { CosmeticData cosmeticData = DungeonsGuide.getDungeonsGuide().getCosmeticsManager().getCosmeticDataMap().get(activeCosmetic.getCosmeticData()); -- cgit