aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/chatreplacers/ChatReplacerViewProfile.java
diff options
context:
space:
mode:
authorsyeyoung <cyong06@naver.com>2021-07-12 00:04:29 +0900
committersyeyoung <cyong06@naver.com>2021-07-12 00:04:29 +0900
commit0508914bfe927cdeb8efd148e99e5290eb01fe51 (patch)
treefc6ec6c5c2cd3774cb3f990a027921a3ec188b44 /src/main/java/kr/syeyoung/dungeonsguide/cosmetics/chatreplacers/ChatReplacerViewProfile.java
parentf8ad8cce99560e8991ceca7a0937e4a144ed0937 (diff)
downloadSkyblock-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/chatreplacers/ChatReplacerViewProfile.java')
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/cosmetics/chatreplacers/ChatReplacerViewProfile.java124
1 files changed, 124 insertions, 0 deletions
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());
+ }
+ }
+}