Skip to content

Commit

Permalink
cosmetics.
Browse files Browse the repository at this point in the history
  • Loading branch information
syeyoung committed May 8, 2021
1 parent 5d1d86d commit 293bb4f
Show file tree
Hide file tree
Showing 10 changed files with 225 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import kr.syeyoung.dungeonsguide.utils.MapUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.network.NetworkPlayerInfo;
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
import net.minecraft.util.ChatComponentText;
Expand Down Expand Up @@ -367,6 +368,10 @@ public void handle(StompInterface stompInterface, StompPayload stompPayload) {

}
}).build());
} else if (args[0].equals("echo")) {
for (NetworkPlayerInfo networkPlayerInfo : Minecraft.getMinecraft().getNetHandler().getPlayerInfoMap()) {
System.out.println(networkPlayerInfo);
}
} else {
sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §e/dg §7-§fOpens configuration gui"));
sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §e/dg gui §7-§fOpens configuration gui"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,23 @@

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;

Expand Down Expand Up @@ -93,25 +100,41 @@ public void handle(StompInterface stompInterface, StompPayload stompPayload) {
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")) {
Expand Down Expand Up @@ -276,13 +299,28 @@ public void onChat(ClientChatReceivedEvent clientChatReceivedEvent) {
}

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));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@
import io.netty.channel.ChannelPromise;
import kr.syeyoung.dungeonsguide.SkyblockStatus;
import kr.syeyoung.dungeonsguide.DungeonsGuide;
import kr.syeyoung.dungeonsguide.cosmetics.CustomPacketPlayerListItem;
import kr.syeyoung.dungeonsguide.events.PlayerInteractEntityEvent;
import kr.syeyoung.dungeonsguide.events.PlayerListItemPacketEvent;
import kr.syeyoung.dungeonsguide.events.TitleEvent;
import kr.syeyoung.dungeonsguide.features.FeatureRegistry;
import net.minecraft.client.Minecraft;
import net.minecraft.network.Packet;
import net.minecraft.network.play.client.C02PacketUseEntity;
import net.minecraft.network.play.server.S04PacketEntityEquipment;
import net.minecraft.network.play.server.S38PacketPlayerListItem;
import net.minecraft.network.play.server.S45PacketTitle;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
Expand All @@ -55,7 +58,11 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
if (packet instanceof S45PacketTitle) {
MinecraftForge.EVENT_BUS.post(new TitleEvent((S45PacketTitle) packet));
}
if (packet instanceof S38PacketPlayerListItem) {
packet = new CustomPacketPlayerListItem((S38PacketPlayerListItem) packet);
}
super.channelRead(ctx, packet);

}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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.events;

import lombok.AllArgsConstructor;
import lombok.Data;
import net.minecraft.network.play.server.S38PacketPlayerListItem;
import net.minecraftforge.fml.common.eventhandler.Event;

@Data
@AllArgsConstructor
public class PlayerListItemPacketEvent extends Event {
private S38PacketPlayerListItem packetPlayerListItem;
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public String getEditRoute(final GuiConfig config) {
"§dFrom §r§r§a[RANK§r§6+§r§a] %prefix%%name%§r§7: §r§7TEST§r",
"§r§b[RANK§c+§b] %prefix%%name%§f: TEST",
"§r§bCo-op > §r§a[RANK§6+§a] %prefix%%name%§f: §rTEST§r"
}, a -> (a+"Color "+(a.equals("§z") ? "(Rainbow on sba)" : ""))));
}, a -> (a.replace("&", "§")+"Color "+(a.replace("&", "§").equals("§z") ? "(Rainbow on sba)" : ""))));
return "base." + getKey();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public String getEditRoute(final GuiConfig config) {
"§dFrom §r%prefix% §r§a[RANK§r§6+§r§a] %name%§r§7: §r§7TEST§r",
"§r%prefix% §b[RANK§c+§b] %name%§f: TEST",
"§r§bCo-op > §r%prefix% §a[RANK§6+§a] %name%§f: §rTEST§r"
}, a->a));
}, a->a.replace("&", "§")));
return "base." + getKey();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void render(int absMousex, int absMousey, int relMousex0, int relMousey0,
GlStateManager.pushMatrix();
GlStateManager.translate(6,17,0);
for (int i = 0; i < previews.length; i++) {
fr.drawString(previews[i].replace("%name%", Minecraft.getMinecraft().getSession().getUsername()).replace("%prefix%", prefix), 0, i*fr.FONT_HEIGHT, -1);
fr.drawString(previews[i].replace("%name%", Minecraft.getMinecraft().getSession().getUsername()).replace("%prefix%", prefix.replace("&", "§")), 0, i*fr.FONT_HEIGHT, -1);
}
GlStateManager.popMatrix();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@
import io.github.moulberry.hychat.HyChat;
import io.github.moulberry.hychat.chat.ChatManager;
import io.github.moulberry.hychat.gui.GuiChatBox;
import kr.syeyoung.dungeonsguide.DungeonsGuide;
import kr.syeyoung.dungeonsguide.config.guiconfig.ConfigPanelCreator;
import kr.syeyoung.dungeonsguide.config.guiconfig.FeatureEditPane;
import kr.syeyoung.dungeonsguide.config.guiconfig.GuiConfig;
import kr.syeyoung.dungeonsguide.config.guiconfig.PanelDefaultParameterConfig;
import kr.syeyoung.dungeonsguide.cosmetics.ActiveCosmetic;
import kr.syeyoung.dungeonsguide.cosmetics.CosmeticData;
import kr.syeyoung.dungeonsguide.features.FeatureParameter;
import kr.syeyoung.dungeonsguide.features.FeatureRegistry;
import kr.syeyoung.dungeonsguide.features.SimpleFeature;
Expand Down Expand Up @@ -245,7 +248,23 @@ private void render(Rectangle popupRect, ScaledResolution scaledResolution, int
GlStateManager.color(1, 1, 1, 1.0F);
if (fakePlayer != null) {
GuiInventory.drawEntityOnScreen(45, 150, 60, -(mouseX - popupRect.x - 75), 0, fakePlayer);
fr.drawString(fakePlayer.getName(), (90 - fr.getStringWidth(fakePlayer.getName())) / 2, 15, 0xFFEFFF00);

String toDraw = fakePlayer.getName();
List<ActiveCosmetic> activeCosmetics = DungeonsGuide.getDungeonsGuide().getCosmeticsManager().getActiveCosmeticByPlayer().get(UUID.fromString(TextUtils.insertDashUUID(playerProfile.get().getMemberUID())));
CosmeticData prefix = null, color = null;
if (activeCosmetics != null) {
for (ActiveCosmetic activeCosmetic : activeCosmetics) {
CosmeticData cosmeticData = DungeonsGuide.getDungeonsGuide().getCosmeticsManager().getCosmeticDataMap().get(activeCosmetic.getCosmeticData());
if (cosmeticData != null) {
if (cosmeticData.getCosmeticType().equals("prefix")) prefix = cosmeticData;
if (cosmeticData.getCosmeticType().equals("color")) color = cosmeticData;
}
}
}
toDraw = (color == null ? "§e" : color.getData().replace("&", "§"))+toDraw;
if (prefix != null) toDraw = prefix.getData().replace("&", "§") + " "+toDraw;

fr.drawString(toDraw, (90 - fr.getStringWidth(toDraw)) / 2, 15, -1);

ItemStack toHover = null;
if (relX > 20 && relX < 70) {
Expand Down

0 comments on commit 293bb4f

Please sign in to comment.