diff options
author | syeyoung <cyong06@naver.com> | 2021-07-12 00:04:29 +0900 |
---|---|---|
committer | syeyoung <cyong06@naver.com> | 2021-07-12 00:04:29 +0900 |
commit | 0508914bfe927cdeb8efd148e99e5290eb01fe51 (patch) | |
tree | fc6ec6c5c2cd3774cb3f990a027921a3ec188b44 /src/main/java/kr/syeyoung/dungeonsguide/cosmetics | |
parent | f8ad8cce99560e8991ceca7a0937e4a144ed0937 (diff) | |
download | Skyblock-Dungeons-Guide-0508914bfe927cdeb8efd148e99e5290eb01fe51.tar.gz Skyblock-Dungeons-Guide-0508914bfe927cdeb8efd148e99e5290eb01fe51.tar.bz2 Skyblock-Dungeons-Guide-0508914bfe927cdeb8efd148e99e5290eb01fe51.zip |
better cosmetics
Diffstat (limited to 'src/main/java/kr/syeyoung/dungeonsguide/cosmetics')
7 files changed, 618 insertions, 90 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/CosmeticsManager.java b/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/CosmeticsManager.java index faa41214..f208ac74 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/CosmeticsManager.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/CosmeticsManager.java @@ -20,20 +20,22 @@ package kr.syeyoung.dungeonsguide.cosmetics; import com.google.gson.JsonPrimitive; import kr.syeyoung.dungeonsguide.DungeonsGuide; +import kr.syeyoung.dungeonsguide.cosmetics.chatreplacers.*; import kr.syeyoung.dungeonsguide.events.PlayerListItemPacketEvent; import kr.syeyoung.dungeonsguide.events.StompConnectedEvent; import kr.syeyoung.dungeonsguide.stomp.*; import kr.syeyoung.dungeonsguide.utils.TextUtils; import lombok.Getter; +import lombok.Setter; import net.minecraft.client.Minecraft; import net.minecraft.client.network.NetHandlerPlayClient; import net.minecraft.client.network.NetworkPlayerInfo; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.network.play.server.S38PacketPlayerListItem; import net.minecraft.scoreboard.ScorePlayerTeam; -import net.minecraft.util.ChatComponentText; -import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.*; import net.minecraftforge.client.event.ClientChatReceivedEvent; +import net.minecraftforge.common.ForgeHooks; import net.minecraftforge.event.entity.player.PlayerEvent; import net.minecraftforge.fml.common.eventhandler.Event; import net.minecraftforge.fml.common.eventhandler.EventPriority; @@ -231,100 +233,26 @@ public class CosmeticsManager implements StompMessageHandler { requestActiveCosmetics(); requestPerms(); } - - // §9Party §8> §a[VIP§6+§a] syeyoung§f: ty - // §2Guild > §a[VIP§6+§a] syeyoung §3[Vet]§f - // §dTo §r§a[VIP§r§6+§r§a] SlashSlayer§r§7: §r§7what§r - // §dFrom §r§a[VIP§r§6+§r§a] SlashSlayer§r§7: §r§7?§r - // §7Rock_Bird§7§r§7: SELLING 30 DIAMOD BLOCK /p me§r - // §b[MVP§c+§b] Probutnoobgamer§f: quitting skyblock! highe - // §r§bCo-op > §a[VIP§6+§a] syeyoung§f: §rwhat§r - - public static String substitute(String str) { - str = str.replace("{HYPIXEL_RANKED_NAME}", "{ANY_COLOR}(?:\\[[a-zA-Z\\+§0-9]+\\] )?{MC_NAME}"); - str = str.replace("{HYPIXEL_RANKED_NAME_PAT}", "({ANY_COLOR}(?:\\[[a-zA-Z\\+§0-9]+\\] )?)({MC_NAME})"); - str = str.replace("{ISLAND_VISITOR}", "(?:§r§a\\[✌\\] )"); - str = str.replace("{RANK}", "(?:{ANY_COLOR}\\[[a-zA-Z0-9_ ]+\\] )"); - str = str.replace("{MC_NAME}", "[a-zA-Z0-9_]+"); - str = str.replace("{ANY_COLOR}", "(?:§[a-zA-Z0-9])*"); - return str; + @Getter @Setter + private static Set<IChatReplacer> iChatReplacers = new HashSet<>(); + static { + iChatReplacers.add(new ChatReplacerViewProfile()); + iChatReplacers.add(new ChatReplacerSocialOptions()); + iChatReplacers.add(new ChatReplacerCoop()); + iChatReplacers.add(new ChatReplacerMessage()); + iChatReplacers.add(new ChatReplacerChatByMe()); } - private static final Pattern PARTY_MSG = Pattern.compile(substitute("§r§9P(?:arty)? §8> {HYPIXEL_RANKED_NAME_PAT}({ANY_COLOR}): (.+)")); - private static final Pattern GUILD_MSG = Pattern.compile(substitute("§r§2G(?:uild)? > {HYPIXEL_RANKED_NAME_PAT}((?: {ANY_COLOR}\\[.+\\])?{ANY_COLOR}): (.+)")); - private static final Pattern CHAT_MSG = Pattern.compile(substitute("({ISLAND_VISITOR}?{RANK}?){HYPIXEL_RANKED_NAME_PAT}({ANY_COLOR}): (.+)")); - private static final Pattern COOP_MSG = Pattern.compile(substitute("§r§bCo-op > {HYPIXEL_RANKED_NAME_PAT}({ANY_COLOR}): (.+)")); - private static final Pattern DM_TO = Pattern.compile(substitute("§dTo §r{HYPIXEL_RANKED_NAME_PAT}§r§7: (.+)")); - private static final Pattern DM_FROM = Pattern.compile(substitute("§dFrom §r{HYPIXEL_RANKED_NAME_PAT}§r§7: (.+)")); - @SubscribeEvent(priority = EventPriority.LOWEST) public void onChat(ClientChatReceivedEvent clientChatReceivedEvent) { - Matcher m; - String msg = clientChatReceivedEvent.message.getFormattedText(); - boolean match = false; - String preRank = ""; - String rank = ""; - String last = ""; - String nickname = ""; - if ((m = PARTY_MSG.matcher(msg)).matches()) { - match = true; - nickname = m.group(2); - preRank = "§r§9Party §8> "; - rank = m.group(1); - last = m.group(2)+m.group(3)+": "+m.group(4); - } else if ((m = GUILD_MSG.matcher(msg)).matches()) { - match = true; - nickname = m.group(2); - preRank = "§r§2Guild > "; - rank = m.group(1); - last = m.group(2)+m.group(3)+": "+m.group(4); - } else if ((m = CHAT_MSG.matcher(msg)).matches()) { - match = true; - nickname = m.group(3); - preRank = m.group(1); - rank = m.group(2); - last = m.group(3)+m.group(4)+": "+m.group(5); - } else if ((m = COOP_MSG.matcher(msg)).matches()) { - match = true; - nickname = m.group(2); - preRank = "§r§bCo-op > "; - rank = m.group(1); - last = m.group(2)+m.group(3)+": "+m.group(4); - } else if ((m = DM_TO.matcher(msg)).matches()) { - match = true; - nickname = m.group(2); - preRank = "§dTo §r"; - rank = m.group(1); - last = m.group(2)+"§r§7: "+m.group(3); - } else if ((m = DM_FROM.matcher(msg)).matches()) { - match = true; - nickname = m.group(2); - preRank = "§dFrom §r"; - rank = m.group(1); - last = m.group(2)+"§r§7: "+m.group(3); - } - - if (!match) return; - - List<ActiveCosmetic> activeCosmetics = activeCosmeticByPlayerNameLowerCase.get(nickname.toLowerCase()); - if (activeCosmetics != null) { - CosmeticData prefix = null, color =null; - for (ActiveCosmetic activeCosmetic : activeCosmetics) { - CosmeticData cosmeticData = cosmeticDataMap.get(activeCosmetic.getCosmeticData()); - if (cosmeticData == null) continue; - if (cosmeticData.getCosmeticType().equals("prefix")) prefix = cosmeticData; - if (cosmeticData.getCosmeticType().equals("color")) color = cosmeticData; - } - - if (prefix != null) { - preRank += prefix.getData().replace("&", "§")+" "; - } - if (color != null) { - last = color.getData().replace("&", "§") + last; + if (clientChatReceivedEvent.type == 2) return; + for (IChatReplacer iChatReplacer : iChatReplacers) { + if (iChatReplacer.isAcceptable(clientChatReceivedEvent)) { + System.out.println("Chosen "+iChatReplacer); + iChatReplacer.translate(clientChatReceivedEvent, this); + return; } } - - clientChatReceivedEvent.message = new ChatComponentText(preRank + rank + last); } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/IChatReplacer.java b/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/IChatReplacer.java new file mode 100644 index 00000000..b2bcfc0e --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/IChatReplacer.java @@ -0,0 +1,26 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.cosmetics; + +import net.minecraftforge.client.event.ClientChatReceivedEvent; + +public interface IChatReplacer { + boolean isAcceptable(ClientChatReceivedEvent event); + void translate(ClientChatReceivedEvent event, CosmeticsManager cosmeticsManager); +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/chatreplacers/ChatReplacerChatByMe.java b/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/chatreplacers/ChatReplacerChatByMe.java new file mode 100644 index 00000000..28fb861e --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/chatreplacers/ChatReplacerChatByMe.java @@ -0,0 +1,105 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.cosmetics.chatreplacers; + +import kr.syeyoung.dungeonsguide.cosmetics.ActiveCosmetic; +import kr.syeyoung.dungeonsguide.cosmetics.CosmeticData; +import kr.syeyoung.dungeonsguide.cosmetics.CosmeticsManager; +import kr.syeyoung.dungeonsguide.cosmetics.IChatReplacer; +import kr.syeyoung.dungeonsguide.utils.TextUtils; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.ChatStyle; +import net.minecraft.util.IChatComponent; +import net.minecraft.util.Tuple; +import net.minecraftforge.client.event.ClientChatReceivedEvent; + +import java.util.ArrayList; +import java.util.List; + +public class ChatReplacerChatByMe implements IChatReplacer { + @Override + public boolean isAcceptable(ClientChatReceivedEvent event) { + for (IChatComponent sibling : event.message.getSiblings()) { + if (sibling.getUnformattedTextForChat().startsWith(": ")) return true; + } + return false; + } + + @Override + public void translate(ClientChatReceivedEvent event, CosmeticsManager cosmeticsManager) { + List<Tuple<IChatComponent, IChatComponent>> replaceMents = new ArrayList<>(); + List<IChatComponent> iChatComponents = new ArrayList<>( event.message.getSiblings() ); + List<IChatComponent> hasMsg = new ArrayList<>(); + for (IChatComponent sibling : iChatComponents) { + if (sibling.getUnformattedTextForChat().startsWith(": ")) break; + hasMsg.add(sibling); + } + iChatComponents.removeAll(hasMsg); + + ChatComponentText chatComponents = new ChatComponentText(""); + chatComponents.getSiblings().addAll(hasMsg); + ChatStyle origStyle = hasMsg.get(0).getChatStyle(); + String name = chatComponents.getFormattedText(); + + + String[] splited = name.split(" "); + String actualName = splited[splited.length-1]; + + List<ActiveCosmetic> cDatas = cosmeticsManager.getActiveCosmeticByPlayerNameLowerCase().get(TextUtils.stripColor(actualName).toLowerCase()); + if (cDatas == null || splited.length > 2) return; + CosmeticData color=null, prefix=null; + for (ActiveCosmetic activeCosmetic : cDatas) { + CosmeticData cosmeticData = cosmeticsManager.getCosmeticDataMap().get(activeCosmetic.getCosmeticData()); + if (cosmeticData !=null && cosmeticData.getCosmeticType().equals("color")) { + color = cosmeticData; + } else if (cosmeticData != null && cosmeticData.getCosmeticType().equals("prefix")) { + prefix = cosmeticData; + } + } + + String building = ""; + if (prefix != null) building += prefix.getData().replace("&", "§") + " "; + if (splited.length == 2) building += splited[0] +" "; + + if (color != null) { + String nick = splited[1]; + building += color.getData().replace("&","§"); + boolean foundLegitChar = false; + boolean foundColor = false; + for (char c : nick.toCharArray()) { + if (foundColor) { + foundColor = false; continue; + } + if (c == '§' && !foundLegitChar) foundColor = true; + else { + foundLegitChar = true; + building += c; + } + } + } else { + building += splited[1] ; + } + + ChatComponentText chatComponents1 = new ChatComponentText(building); + chatComponents1.setChatStyle(origStyle); + event.message.getSiblings().clear(); + event.message.getSiblings().add(chatComponents1); + event.message.getSiblings().addAll(iChatComponents); + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/chatreplacers/ChatReplacerCoop.java b/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/chatreplacers/ChatReplacerCoop.java new file mode 100644 index 00000000..91bb58b6 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/chatreplacers/ChatReplacerCoop.java @@ -0,0 +1,121 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.cosmetics.chatreplacers; + +import kr.syeyoung.dungeonsguide.cosmetics.ActiveCosmetic; +import kr.syeyoung.dungeonsguide.cosmetics.CosmeticData; +import kr.syeyoung.dungeonsguide.cosmetics.CosmeticsManager; +import kr.syeyoung.dungeonsguide.cosmetics.IChatReplacer; +import kr.syeyoung.dungeonsguide.utils.TextUtils; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.ChatStyle; +import net.minecraft.util.IChatComponent; +import net.minecraft.util.Tuple; +import net.minecraftforge.client.event.ClientChatReceivedEvent; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class ChatReplacerCoop implements IChatReplacer { + @Override + public boolean isAcceptable(ClientChatReceivedEvent event) { + for (IChatComponent sibling : event.message.getSiblings()) { + if (sibling.getUnformattedTextForChat().startsWith("§bCo-op > ")) return true; + } + return false; + } + + @Override + public void translate(ClientChatReceivedEvent event, CosmeticsManager cosmeticsManager) { + List<Tuple<IChatComponent, IChatComponent>> replaceMents = new ArrayList<>(); + List<IChatComponent> iChatComponents = new ArrayList<>( event.message.getSiblings() ); + IChatComponent sibling = iChatComponents.get(0); iChatComponents.remove(sibling); + + + String[] splitInto = sibling.getUnformattedTextForChat().split(" "); + int lastValidNickname = -1; + int lastprefix = -1; + for (int i = 0; i < splitInto.length; i++) { + String s = TextUtils.stripColor(splitInto[i]); + char c = s.charAt(0); + if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || ('0' <= c && c <= '9') || c == '_' || c == '-') { + lastValidNickname = i; + } + } + if (lastValidNickname == -1) return; + + if (lastValidNickname -1 >= 0 && TextUtils.stripColor(splitInto[lastValidNickname - 1]).charAt(0) == '[') lastprefix = lastValidNickname -1; + else lastprefix = lastValidNickname; + + + List<ActiveCosmetic> cDatas = cosmeticsManager.getActiveCosmeticByPlayerNameLowerCase().get(TextUtils.stripColor(splitInto[lastValidNickname].substring(0, splitInto[lastValidNickname].length()-1)).toLowerCase()); + + if (cDatas == null) return; + + CosmeticData color = null, prefix = null; + for (ActiveCosmetic activeCosmetic : cDatas) { + CosmeticData cosmeticData = cosmeticsManager.getCosmeticDataMap().get(activeCosmetic.getCosmeticData()); + if (cosmeticData != null && cosmeticData.getCosmeticType().equals("color")) { + color = cosmeticData; + } else if (cosmeticData != null && cosmeticData.getCosmeticType().equals("prefix")) { + prefix = cosmeticData; + } + } + + String building = ""; + for (int i = 0; i < lastprefix; i++) { + building += splitInto[i] +" "; + } + if (prefix != null) building += prefix.getData().replace("&", "§") + " "; + for (int i = lastprefix; i < lastValidNickname; i++) { + building += splitInto[i] +" "; + } + if (color != null) { + String nick = splitInto[lastValidNickname]; + building += color.getData().replace("&","§"); + boolean foundLegitChar = false; + boolean foundColor = false; + for (char c : nick.toCharArray()) { + if (foundColor) { + foundColor = false; continue; + } + if (c == '§' && !foundLegitChar) foundColor = true; + else { + foundLegitChar = true; + building += c; + } + } + building += " "; + } else { + building += splitInto[lastValidNickname] + " "; + } + for (int i = lastValidNickname+1; i<splitInto.length; i++) { + building += splitInto[i] + " "; + } + if (sibling.getUnformattedTextForChat().charAt(sibling.getUnformattedText().length()-1) != ' ') + building = building.substring(0, building.length() - 1); + + ChatComponentText chatComponents1 = new ChatComponentText(building); + chatComponents1.setChatStyle(sibling.getChatStyle()); + event.message.getSiblings().clear(); + event.message.getSiblings().add(chatComponents1); + event.message.getSiblings().addAll(iChatComponents); + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/chatreplacers/ChatReplacerMessage.java b/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/chatreplacers/ChatReplacerMessage.java new file mode 100644 index 00000000..14c2bd11 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/chatreplacers/ChatReplacerMessage.java @@ -0,0 +1,107 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.cosmetics.chatreplacers; + +import kr.syeyoung.dungeonsguide.cosmetics.ActiveCosmetic; +import kr.syeyoung.dungeonsguide.cosmetics.CosmeticData; +import kr.syeyoung.dungeonsguide.cosmetics.CosmeticsManager; +import kr.syeyoung.dungeonsguide.cosmetics.IChatReplacer; +import kr.syeyoung.dungeonsguide.utils.TextUtils; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.ChatStyle; +import net.minecraft.util.IChatComponent; +import net.minecraft.util.Tuple; +import net.minecraftforge.client.event.ClientChatReceivedEvent; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class ChatReplacerMessage implements IChatReplacer { + @Override + public boolean isAcceptable(ClientChatReceivedEvent event) { + for (IChatComponent sibling : event.message.getSiblings()) { + if (sibling.getChatStyle() != null && sibling.getChatStyle().getChatClickEvent() != null && sibling.getChatStyle().getChatClickEvent().getValue().startsWith("/msg")) return true; + } + return false; + } + + @Override + public void translate(ClientChatReceivedEvent event, CosmeticsManager cosmeticsManager) { + List<Tuple<IChatComponent, IChatComponent>> replaceMents = new ArrayList<>(); + List<IChatComponent> iChatComponents = new ArrayList<>( event.message.getSiblings() ); + List<IChatComponent> hasMsg = new ArrayList<>(); + for (IChatComponent sibling : iChatComponents) { + if (sibling.getChatStyle() != null && sibling.getChatStyle().getChatClickEvent() != null && sibling.getChatStyle().getChatClickEvent().getValue().startsWith("/msg")) { + hasMsg.add(sibling); + } + } + iChatComponents.removeAll(hasMsg); + + ChatComponentText chatComponents = new ChatComponentText(""); + chatComponents.getSiblings().addAll(hasMsg); + ChatStyle origStyle = hasMsg.get(0).getChatStyle(); + String name = chatComponents.getFormattedText(); + + + String[] splited = name.split(" "); + String actualName = splited[splited.length-1]; + + List<ActiveCosmetic> cDatas = cosmeticsManager.getActiveCosmeticByPlayerNameLowerCase().get(TextUtils.stripColor(actualName).toLowerCase()); + if (cDatas == null || splited.length > 2) return; + CosmeticData color=null, prefix=null; + for (ActiveCosmetic activeCosmetic : cDatas) { + CosmeticData cosmeticData = cosmeticsManager.getCosmeticDataMap().get(activeCosmetic.getCosmeticData()); + if (cosmeticData !=null && cosmeticData.getCosmeticType().equals("color")) { + color = cosmeticData; + } else if (cosmeticData != null && cosmeticData.getCosmeticType().equals("prefix")) { + prefix = cosmeticData; + } + } + + String building = ""; + if (prefix != null) building += prefix.getData().replace("&", "§") + " "; + if (splited.length == 2) building += splited[0] +" "; + + if (color != null) { + String nick = splited[1]; + building += color.getData().replace("&","§"); + boolean foundLegitChar = false; + boolean foundColor = false; + for (char c : nick.toCharArray()) { + if (foundColor) { + foundColor = false; continue; + } + if (c == '§' && !foundLegitChar) foundColor = true; + else { + foundLegitChar = true; + building += c; + } + } + } else { + building += splited[1] ; + } + + ChatComponentText chatComponents1 = new ChatComponentText(building); + chatComponents1.setChatStyle(origStyle); + event.message.getSiblings().clear(); + event.message.getSiblings().add(chatComponents1); + event.message.getSiblings().addAll(iChatComponents); + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/chatreplacers/ChatReplacerSocialOptions.java b/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/chatreplacers/ChatReplacerSocialOptions.java new file mode 100644 index 00000000..62e8e0af --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/chatreplacers/ChatReplacerSocialOptions.java @@ -0,0 +1,117 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.cosmetics.chatreplacers; + +import kr.syeyoung.dungeonsguide.cosmetics.ActiveCosmetic; +import kr.syeyoung.dungeonsguide.cosmetics.CosmeticData; +import kr.syeyoung.dungeonsguide.cosmetics.CosmeticsManager; +import kr.syeyoung.dungeonsguide.cosmetics.IChatReplacer; +import kr.syeyoung.dungeonsguide.utils.TextUtils; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.IChatComponent; +import net.minecraft.util.Tuple; +import net.minecraftforge.client.event.ClientChatReceivedEvent; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class ChatReplacerSocialOptions implements IChatReplacer { + @Override + public boolean isAcceptable(ClientChatReceivedEvent event) { + if (event.message.getChatStyle() != null && event.message.getChatStyle().getChatClickEvent() != null && event.message.getChatStyle().getChatClickEvent().getValue().startsWith("/socialoptions")) return true; + return false; + } + + @Override + public void translate(ClientChatReceivedEvent event, CosmeticsManager cosmeticsManager) { + if (event.message.getChatStyle() != null && event.message.getChatStyle().getChatClickEvent() != null && event.message.getChatStyle().getChatClickEvent().getValue().startsWith("/socialoptions")) { + String username = event.message.getChatStyle().getChatClickEvent().getValue().split(" ")[1]; + List<ActiveCosmetic> cDatas = cosmeticsManager.getActiveCosmeticByPlayerNameLowerCase().get(username.toLowerCase()); + + if (cDatas != null) { + CosmeticData color=null, prefix=null; + for (ActiveCosmetic activeCosmetic : cDatas) { + CosmeticData cosmeticData = cosmeticsManager.getCosmeticDataMap().get(activeCosmetic.getCosmeticData()); + if (cosmeticData !=null && cosmeticData.getCosmeticType().equals("color")) { + color = cosmeticData; + } else if (cosmeticData != null && cosmeticData.getCosmeticType().equals("prefix")) { + prefix = cosmeticData; + } + } + + String[] splitInto = event.message.getUnformattedTextForChat().split(" "); + int lastValidNickname = -1; + int lastprefix = -1; + for (int i = 0; i < splitInto.length; i++) { + String s = splitInto[i]; + if (s.startsWith("§7")) s = s.substring(2); + char c = s.charAt(0); + if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || ('0' <= c && c <= '9') || c == '_' || c == '-') { + lastValidNickname = i; + } + } + if (lastValidNickname == -1) return; + + if (lastValidNickname -1 >= 0 && TextUtils.stripColor(splitInto[lastValidNickname - 1]).charAt(0) == '[') lastprefix = lastValidNickname -1; + else lastprefix = lastValidNickname; + + String building = ""; + for (int i = 0; i < lastprefix; i++) { + building += splitInto[i] +" "; + } + if (prefix != null) building += prefix.getData().replace("&", "§") + " "; + for (int i = lastprefix; i < lastValidNickname; i++) { + building += splitInto[i] +" "; + } + if (color != null) { + String nick = splitInto[lastValidNickname]; + building += color.getData().replace("&","§"); + boolean foundLegitChar = false; + boolean foundColor = false; + for (char c : nick.toCharArray()) { + if (foundColor) { + foundColor = false; continue; + } + if (c == '§' && !foundLegitChar) foundColor = true; + else { + foundLegitChar = true; + building += c; + } + } + building += " "; + } else { + building += splitInto[lastValidNickname] + " "; + } + for (int i = lastValidNickname+1; i<splitInto.length; i++) { + building += splitInto[i] + " "; + } + if (event.message.getUnformattedTextForChat().charAt(event.message.getUnformattedTextForChat().length()-1) != ' ') + building = building.substring(0, building.length() - 1); + + ChatComponentText newChatCompText = new ChatComponentText(building); + newChatCompText.setChatStyle(event.message.getChatStyle()); + newChatCompText.getSiblings().addAll(event.message.getSiblings()); + + event.message = newChatCompText; + } + } + + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/chatreplacers/ChatReplacerViewProfile.java b/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/chatreplacers/ChatReplacerViewProfile.java new file mode 100644 index 00000000..abd399e3 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/chatreplacers/ChatReplacerViewProfile.java @@ -0,0 +1,124 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.cosmetics.chatreplacers; + +import kr.syeyoung.dungeonsguide.cosmetics.ActiveCosmetic; +import kr.syeyoung.dungeonsguide.cosmetics.CosmeticData; +import kr.syeyoung.dungeonsguide.cosmetics.CosmeticsManager; +import kr.syeyoung.dungeonsguide.cosmetics.IChatReplacer; +import kr.syeyoung.dungeonsguide.utils.TextUtils; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.IChatComponent; +import net.minecraft.util.Tuple; +import net.minecraftforge.client.event.ClientChatReceivedEvent; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class ChatReplacerViewProfile implements IChatReplacer { + @Override + public boolean isAcceptable(ClientChatReceivedEvent event) { + System.out.println(event.message); + for (IChatComponent sibling : event.message.getSiblings()) { + if (sibling.getChatStyle() != null && sibling.getChatStyle().getChatClickEvent() != null && sibling.getChatStyle().getChatClickEvent().getValue().startsWith("/viewprofile")) return true; + } + return false; + } + + @Override + public void translate(ClientChatReceivedEvent event, CosmeticsManager cosmeticsManager) { + List<Tuple<IChatComponent, IChatComponent>> replaceMents = new ArrayList<>(); + for (IChatComponent sibling : event.message.getSiblings()) { + if (sibling.getChatStyle() != null && sibling.getChatStyle().getChatClickEvent() != null && sibling.getChatStyle().getChatClickEvent().getValue().startsWith("/viewprofile")) { + String uid = sibling.getChatStyle().getChatClickEvent().getValue().split(" ")[1]; + List<ActiveCosmetic> cDatas = cosmeticsManager.getActiveCosmeticByPlayer().get(UUID.fromString(uid)); + + if (cDatas != null) { + CosmeticData color=null, prefix=null; + for (ActiveCosmetic activeCosmetic : cDatas) { + CosmeticData cosmeticData = cosmeticsManager.getCosmeticDataMap().get(activeCosmetic.getCosmeticData()); + if (cosmeticData !=null && cosmeticData.getCosmeticType().equals("color")) { + color = cosmeticData; + } else if (cosmeticData != null && cosmeticData.getCosmeticType().equals("prefix")) { + prefix = cosmeticData; + } + } + + String[] splitInto = sibling.getUnformattedTextForChat().split(" "); + int lastValidNickname = -1; + int lastprefix = -1; + for (int i = 0; i < splitInto.length; i++) { + String s = TextUtils.stripColor(splitInto[i]); + char c = s.charAt(0); + if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || ('0' <= c && c <= '9') || c == '_' || c == '-') { + lastValidNickname = i; + } + } + if (lastValidNickname == -1) continue; + + if (lastValidNickname -1 >= 0 && TextUtils.stripColor(splitInto[lastValidNickname - 1]).charAt(0) == '[') lastprefix = lastValidNickname -1; + else lastprefix = lastValidNickname; + + String building = ""; + for (int i = 0; i < lastprefix; i++) { + building += splitInto[i] +" "; + } + if (prefix != null) building += prefix.getData().replace("&", "§") + " "; + for (int i = lastprefix; i < lastValidNickname; i++) { + building += splitInto[i] +" "; + } + if (color != null) { + String nick = splitInto[lastValidNickname]; + building += color.getData().replace("&","§"); + boolean foundLegitChar = false; + boolean foundColor = false; + for (char c : nick.toCharArray()) { + if (foundColor) { + foundColor = false; continue; + } + if (c == '§' && !foundLegitChar) foundColor = true; + else { + foundLegitChar = true; + building += c; + } + } + building += " "; + } else { + building += splitInto[lastValidNickname] + " "; + } + for (int i = lastValidNickname+1; i<splitInto.length; i++) { + building += splitInto[i] + " "; + } + if (sibling.getUnformattedTextForChat().charAt(sibling.getUnformattedText().length()-1) != ' ') + building = building.substring(0, building.length() - 1); + + ChatComponentText newChatCompText = new ChatComponentText(building); + newChatCompText.setChatStyle(sibling.getChatStyle()); + replaceMents.add(new Tuple<>(sibling, newChatCompText)); + } + } + } + + for (Tuple<IChatComponent, IChatComponent> replaceMent : replaceMents) { + int index = event.message.getSiblings().indexOf(replaceMent.getFirst()); + event.message.getSiblings().set(index, replaceMent.getSecond()); + } + } +} |