Solved NPC skin not loading for fake death

Discussion in 'BungeeCord Plugin Development' started by Nyaruko, May 14, 2017.

  1. I'm trying to achieve a clean death event where the player death animation (player status 3) plays for all clients except the dying client. However, with my current method of spawning an NPC of the player in their place and killing that, the player's skin disappears for the clients on both the NPC and in the tab menu. Here is my code that is being run:

    Code (Text):
    MinecraftServer nmsServer = ((CraftServer) Bukkit.getServer()).getServer();
            WorldServer nmsWorld = ((CraftWorld) currentWorld).getHandle();
         
            EntityPlayer npc = new EntityPlayer(nmsServer, nmsWorld, new GameProfile(deadPlayer.getUniqueId(), deadPlayer.getName()), new PlayerInteractManager(nmsWorld));
         
            npc.setLocation(deadPlayer.getLocation().getX(), deadPlayer.getLocation().getY(), deadPlayer.getLocation().getZ(), deadPlayer.getLocation().getYaw(), deadPlayer.getLocation().getPitch());
            for(Player p : Bukkit.getOnlinePlayers()){
                if(!p.getUniqueId().equals(deadPlayer.getUniqueId())){
                    PlayerConnection connection = ((CraftPlayer) p).getHandle().playerConnection;
                    connection.sendPacket(new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, ((CraftPlayer)deadPlayer).getHandle()));
                    connection.sendPacket(new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, npc));
                    connection.sendPacket(new PacketPlayOutNamedEntitySpawn(npc));
                    connection.sendPacket(new PacketPlayOutEntityStatus(npc, (byte)3));
                }
            }
    This mostly works in terms of the player being killed doesn't have the death screen displayed to them and the killer sees a player with the same name die where the player was, but I can't see why the dying player's skin is unloading, anyone have any ideas on this.
     
  2. electronicboy

    IRC Staff

    Don't create a new GameProfile, but grab the players existing one. It stores the skin texture in there
     
    • Winner Winner x 2
  3. Solved it by combining this with not removing the npc myself. Cheers!