Change Skin of an EntityPlayer

Discussion in 'Spigot Plugin Development' started by _xXProDudeXx_, May 3, 2017.

  1. Hello Spigotiers!

    As the title says, I want to change the skin of an EntityPlayer. Here is my Current Code:

    Code (Text):
     @Override
        public void spawn(@Nonnull Player p) {
            player.setInvisible(visible);

            player.setLocation(location.getX(), location.getY(), location.getZ(), location.getPitch(), location.getYaw());
            sendSpawnPacket(p);
        }

        @Override
        public void sendSpawnPacket(@Nonnull Player p) {
            PlayerConnection c = ((CraftPlayer) p).getHandle().playerConnection;

            PacketPlayOutNamedEntitySpawn namedEntityPacket = new PacketPlayOutNamedEntitySpawn(player);
            PacketPlayOutPlayerInfo infoPacket = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, player);

            c.sendPacket(namedEntityPacket);
            c.sendPacket(infoPacket);
        }
    I know it is not highly efficient but that doesn't matter at the moment.

    I got absolutely no clue about what to do to change a skin, can you guys help me out??

    Kind regards

    ~Wouter
     
  2. Send the info packet before "spawning" the player.
     
    • Useful Useful x 1
  3. @ysl3000 alright changed that, does that actually make a lot of sense?
     
  4. Yep, if you check the packet that spawns the player entity, you will see that it's quite empty, and a lot of information seems to be missing. That info is sent along with the tab list packet.

    The skin data should be stored on the player's game profile properties, and is sent along the tab list packet. You can either force change the game profile's skin, or change the value directly on the packet before sending it.
     
    • Informative Informative x 1