mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-14 06:14:52 +00:00
Key the skin overlay packet on UUID so it isn't dropped for unloaded players
This commit is contained in:
1 parent
4a52690d99
commit
795464fb81
3 files changed
+21
-13
No files matched your search
+12
-9
@@ -8,24 +8,24 @@ import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumDataPacket;
|
||||
import kamkeel.npcs.util.ByteBufUtils;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.client.NoppesUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class PlayerUpdateSkinOverlaysPacket extends AbstractPacket {
|
||||
public static final String packetName = "Data|PlayerUpdateSkinOverlays";
|
||||
|
||||
private String playerName;
|
||||
private String playerUUID;
|
||||
private NBTTagCompound compound;
|
||||
|
||||
public PlayerUpdateSkinOverlaysPacket() {
|
||||
}
|
||||
|
||||
public PlayerUpdateSkinOverlaysPacket(String playerName, NBTTagCompound compound) {
|
||||
this.playerName = playerName;
|
||||
public PlayerUpdateSkinOverlaysPacket(UUID playerUUID, NBTTagCompound compound) {
|
||||
this.playerUUID = playerUUID == null ? "" : playerUUID.toString();
|
||||
this.compound = compound;
|
||||
}
|
||||
|
||||
@@ -41,18 +41,21 @@ public final class PlayerUpdateSkinOverlaysPacket extends AbstractPacket {
|
||||
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
ByteBufUtils.writeString(out, this.playerName);
|
||||
ByteBufUtils.writeString(out, this.playerUUID);
|
||||
ByteBufUtils.writeNBT(out, this.compound);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
String playerName = ByteBufUtils.readString(in);
|
||||
String uuid = ByteBufUtils.readString(in);
|
||||
NBTTagCompound nbt = ByteBufUtils.readNBT(in);
|
||||
EntityPlayer sendingPlayer = Minecraft.getMinecraft().theWorld.getPlayerEntityByName(playerName);
|
||||
if (sendingPlayer != null) {
|
||||
NoppesUtil.updateSkinOverlayData(sendingPlayer, nbt);
|
||||
if (uuid == null || uuid.isEmpty())
|
||||
return;
|
||||
|
||||
try {
|
||||
NoppesUtil.updateSkinOverlayData(UUID.fromString(uuid), nbt);
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -38,6 +38,7 @@ import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.Vector;
|
||||
|
||||
public class NoppesUtil {
|
||||
@@ -51,11 +52,15 @@ public class NoppesUtil {
|
||||
}
|
||||
|
||||
public static void updateSkinOverlayData(EntityPlayer player, NBTTagCompound compound) {
|
||||
updateSkinOverlayData(player.getUniqueID(), compound);
|
||||
}
|
||||
|
||||
public static void updateSkinOverlayData(UUID playerUUID, NBTTagCompound compound) {
|
||||
HashMap<Integer, SkinOverlay> skinOverlays = new HashMap<>();
|
||||
HashMap<Integer, SkinOverlay> oldOverlays = new HashMap<>();
|
||||
NBTTagList skinOverlayList = compound.getTagList("SkinOverlayData", 10);
|
||||
if (ClientCacheHandler.skinOverlays.containsKey(player.getUniqueID())) {
|
||||
oldOverlays = ClientCacheHandler.skinOverlays.get(player.getUniqueID());
|
||||
if (ClientCacheHandler.skinOverlays.containsKey(playerUUID)) {
|
||||
oldOverlays = ClientCacheHandler.skinOverlays.get(playerUUID);
|
||||
}
|
||||
|
||||
for (int i = 0; i < skinOverlayList.tagCount(); i++) {
|
||||
@@ -66,7 +71,7 @@ public class NoppesUtil {
|
||||
}
|
||||
skinOverlays.put(tagID, overlay);
|
||||
}
|
||||
ClientCacheHandler.skinOverlays.put(player.getUniqueID(), skinOverlays);
|
||||
ClientCacheHandler.skinOverlays.put(playerUUID, skinOverlays);
|
||||
}
|
||||
|
||||
public static void clickSound() {
|
||||
|
||||
@@ -60,7 +60,7 @@ public class DataSkinOverlays implements IOverlayHandler {
|
||||
if (parent instanceof PlayerData && ((PlayerData) parent).player != null) {
|
||||
NBTTagCompound compound = this.writeToNBT(new NBTTagCompound());
|
||||
((PlayerData) parent).player.getEntityData().setTag("SkinOverlayData", compound.getTagList("SkinOverlayData", 10));
|
||||
PacketHandler.Instance.sendToAll(new PlayerUpdateSkinOverlaysPacket(((PlayerData) parent).player.getCommandSenderName(), compound));
|
||||
PacketHandler.Instance.sendToAll(new PlayerUpdateSkinOverlaysPacket(((PlayerData) parent).player.getUniqueID(), compound));
|
||||
} else if (parent instanceof EntityNPCInterface) {
|
||||
((EntityNPCInterface) parent).updateClient = true;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user