aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/kr/syeyoung/dungeonsguide/cosmetics
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/kr/syeyoung/dungeonsguide/cosmetics')
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/cosmetics/CosmeticsManager.java74
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/cosmetics/CustomNetworkPlayerInfo.java65
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/cosmetics/CustomPacketPlayerListItem.java39
3 files changed, 160 insertions, 18 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/CosmeticsManager.java b/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/CosmeticsManager.java
index d7c8114f..05e66046 100644
--- a/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/CosmeticsManager.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/CosmeticsManager.java
@@ -20,16 +20,23 @@ package kr.syeyoung.dungeonsguide.cosmetics;
import com.google.gson.JsonPrimitive;
import kr.syeyoung.dungeonsguide.DungeonsGuide;
+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 net.minecraft.client.Minecraft;
+import net.minecraft.client.network.NetHandlerPlayClient;
+import net.minecraft.client.network.NetworkPlayerInfo;
+import net.minecraft.network.play.server.S38PacketPlayerListItem;
+import net.minecraft.scoreboard.ScorePlayerTeam;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
+import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
+import net.minecraftforge.fml.relauncher.ReflectionHelper;
import org.json.JSONArray;
import org.json.JSONObject;
@@ -93,25 +100,41 @@ public class CosmeticsManager implements StompMessageHandler {
ActiveCosmetic activeCosmetic = new ActiveCosmetic();
activeCosmetic.setActivityUID(UUID.fromString(jsonObject.getString("activityUID")));
activeCosmetic.setPlayerUID(UUID.fromString(jsonObject.getString("playerUID")));
- activeCosmetic.setCosmeticData(UUID.fromString(jsonObject.getString("cosmeticUID")));
- activeCosmetic.setUsername(jsonObject.getString("username"));
+ if (jsonObject.isNull("cosmeticUID")) {
+ ActiveCosmetic activeCosmetic1 = activeCosmeticMap.remove(activeCosmetic.getActivityUID());
- ActiveCosmetic previousThing = activeCosmeticMap.get(activeCosmetic.getActivityUID());
- activeCosmeticMap.put(activeCosmetic.getActivityUID(), activeCosmetic);
+ List<ActiveCosmetic> activeCosmetics = activeCosmeticByPlayer.computeIfAbsent(activeCosmetic.getPlayerUID(), a-> new ArrayList<>());
+ activeCosmetics.remove(activeCosmetic1);
- CosmeticData cosmeticData = cosmeticDataMap.get(activeCosmetic.getCosmeticData());
- if (cosmeticData != null) {
- List<ActiveCosmetic> cosmeticsByTypeList = activeCosmeticByType.computeIfAbsent(cosmeticData.getCosmeticType(), a-> new ArrayList<>());
- cosmeticsByTypeList.add(activeCosmetic);
- cosmeticsByTypeList.remove(previousThing);
- }
- List<ActiveCosmetic> activeCosmetics = activeCosmeticByPlayer.computeIfAbsent(activeCosmetic.getPlayerUID(), a-> new ArrayList<>());
- activeCosmetics.add(activeCosmetic);
- activeCosmetics.remove(previousThing);
+ activeCosmetics = activeCosmeticByPlayerNameLowerCase.computeIfAbsent(activeCosmetic.getUsername().toLowerCase(), a-> new ArrayList<>());
+ activeCosmetics.remove(activeCosmetic1);
+
+ CosmeticData cosmeticData = cosmeticDataMap.get(activeCosmetic.getCosmeticData());
+ if (cosmeticData != null) {
+ List<ActiveCosmetic> cosmeticsByTypeList = activeCosmeticByType.computeIfAbsent(cosmeticData.getCosmeticType(), a-> new ArrayList<>());
+ cosmeticsByTypeList.remove(activeCosmetic1);
+ }
+ } else {
+ activeCosmetic.setCosmeticData(UUID.fromString(jsonObject.getString("cosmeticUID")));
+ activeCosmetic.setUsername(jsonObject.getString("username"));
+
+ ActiveCosmetic previousThing = activeCosmeticMap.get(activeCosmetic.getActivityUID());
+ activeCosmeticMap.put(activeCosmetic.getActivityUID(), activeCosmetic);
+
+ CosmeticData cosmeticData = cosmeticDataMap.get(activeCosmetic.getCosmeticData());
+ if (cosmeticData != null) {
+ List<ActiveCosmetic> cosmeticsByTypeList = activeCosmeticByType.computeIfAbsent(cosmeticData.getCosmeticType(), a-> new ArrayList<>());
+ cosmeticsByTypeList.add(activeCosmetic);
+ cosmeticsByTypeList.remove(previousThing);
+ }
+ List<ActiveCosmetic> activeCosmetics = activeCosmeticByPlayer.computeIfAbsent(activeCosmetic.getPlayerUID(), a-> new ArrayList<>());
+ activeCosmetics.add(activeCosmetic);
+ activeCosmetics.remove(previousThing);
- activeCosmetics = activeCosmeticByPlayerNameLowerCase.computeIfAbsent(activeCosmetic.getUsername().toLowerCase(), a-> new ArrayList<>());
- activeCosmetics.add(activeCosmetic);
- activeCosmetics.remove(previousThing);
+ activeCosmetics = activeCosmeticByPlayerNameLowerCase.computeIfAbsent(activeCosmetic.getUsername().toLowerCase(), a-> new ArrayList<>());
+ activeCosmetics.add(activeCosmetic);
+ activeCosmetics.remove(previousThing);
+ }
} else if (destination.equals("/user/queue/reply/user.perms")) {
@@ -276,13 +299,28 @@ public class CosmeticsManager implements StompMessageHandler {
}
if (prefix != null) {
- preRank += prefix.getData()+" ";
+ preRank += prefix.getData().replace("&", "§")+" ";
}
if (color != null) {
- last = color.getData() + last;
+ last = color.getData().replace("&", "§") + last;
}
}
clientChatReceivedEvent.message = new ChatComponentText(preRank + rank + last);
}
+
+
+ @SubscribeEvent
+ public void onTabList(PlayerListItemPacketEvent packetPlayerListItem) {
+ S38PacketPlayerListItem asd = packetPlayerListItem.getPacketPlayerListItem();
+ if (asd.getAction() == S38PacketPlayerListItem.Action.ADD_PLAYER) {
+ if (Minecraft.getMinecraft().getNetHandler() == null) return;
+
+ Map<UUID, NetworkPlayerInfo> playerInfoMap = ReflectionHelper.getPrivateValue(NetHandlerPlayClient.class, Minecraft.getMinecraft().getNetHandler(), "playerInfoMap", "field_147310_i","i");
+ for (S38PacketPlayerListItem.AddPlayerData entry : asd.getEntries()) {
+ playerInfoMap.remove(entry.getProfile().getId());
+ playerInfoMap.put(entry.getProfile().getId(), new CustomNetworkPlayerInfo(entry));
+ }
+ }
+ }
}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/CustomNetworkPlayerInfo.java b/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/CustomNetworkPlayerInfo.java
new file mode 100644
index 00000000..ea2cb205
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/CustomNetworkPlayerInfo.java
@@ -0,0 +1,65 @@
+/*
+ * 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 com.mojang.authlib.GameProfile;
+import kr.syeyoung.dungeonsguide.DungeonsGuide;
+import kr.syeyoung.dungeonsguide.utils.TextUtils;
+import net.minecraft.client.network.NetworkPlayerInfo;
+import net.minecraft.network.play.server.S38PacketPlayerListItem;
+import net.minecraft.scoreboard.ScorePlayerTeam;
+import net.minecraft.util.ChatComponentText;
+import net.minecraft.util.IChatComponent;
+
+import java.util.List;
+
+public class CustomNetworkPlayerInfo extends NetworkPlayerInfo {
+ public CustomNetworkPlayerInfo(GameProfile p_i46294_1_) {
+ super(p_i46294_1_);
+ }
+
+ public CustomNetworkPlayerInfo(S38PacketPlayerListItem.AddPlayerData p_i46295_1_) {
+ super(p_i46295_1_);
+ }
+
+ 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 = s;
+ }
+ List<ActiveCosmetic> activeCosmetics = DungeonsGuide.getDungeonsGuide().getCosmeticsManager().getActiveCosmeticByPlayerNameLowerCase().get(TextUtils.stripColor(actualName).toLowerCase());
+
+
+
+ if (activeCosmetics == null) return super.getDisplayName();
+ CosmeticData color=null;
+ for (ActiveCosmetic activeCosmetic : activeCosmetics) {
+ CosmeticData cosmeticData = DungeonsGuide.getDungeonsGuide().getCosmeticsManager().getCosmeticDataMap().get(activeCosmetic.getCosmeticData());
+ if (cosmeticData.getCosmeticType().equals("color")) color = cosmeticData;
+ }
+
+ if (color != null) semi_name = semi_name.replace(actualName, color.getData()+actualName);
+
+ return new ChatComponentText(semi_name);
+ }
+}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/CustomPacketPlayerListItem.java b/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/CustomPacketPlayerListItem.java
new file mode 100644
index 00000000..2f957c42
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/CustomPacketPlayerListItem.java
@@ -0,0 +1,39 @@
+/*
+ * 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 kr.syeyoung.dungeonsguide.events.PlayerListItemPacketEvent;
+import net.minecraft.network.Packet;
+import net.minecraft.network.play.INetHandlerPlayClient;
+import net.minecraft.network.play.server.S38PacketPlayerListItem;
+import net.minecraftforge.common.MinecraftForge;
+
+public class CustomPacketPlayerListItem extends S38PacketPlayerListItem {
+ public CustomPacketPlayerListItem(S38PacketPlayerListItem packet) {
+ super(packet.getAction());
+ getEntries().addAll(packet.getEntries());
+ }
+
+ @Override
+ public void processPacket(INetHandlerPlayClient handler) {
+ super.processPacket(handler);
+
+ MinecraftForge.EVENT_BUS.post(new PlayerListItemPacketEvent(this));
+ }
+}