Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-6676

CLONE - Error While Displaying NPC Skin

    XMLWordPrintable

Details

    • New Feature
    • Status: Closed (View Workflow)
    • Minor
    • Resolution: Duplicate
    • None
    • None
    • CraftBukkit version git-PaperSpigot-"4c7641d" (MC: 1.8.8) (Implementing API version 1.8.8-R0.1-SNAPSHOT)
    • Yes

    Description

      I'm working on a plugin that contains CustomPlayers ( BOTS ) and i have an ISSUE while displaying the skin of the CustomPlayer

      [Player Skin|https://prnt.sc/1foox8w]

      Required Skin: 

      public static GameSelectorNPC createNPC(Player player, World world, Location location) {
          MinecraftServer nmsServer = ((CraftServer) Bukkit.getServer()).getServer();
          WorldServer nmsWorld = ((CraftWorld) world).getHandle();
          GameProfile profile = new GameProfile(UUID.randomUUID(), player.getName());
          PlayerInteractManager interactManager = new PlayerInteractManager(nmsWorld);
          GameSelectorNPC entityPlayer = new GameSelectorNPC(nmsServer, nmsWorld, profile, interactManager);
          entityPlayer.playerConnection = new PlayerConnection(nmsServer, new NetworkManager(EnumProtocolDirection.CLIENTBOUND), entityPlayer);
      
          EntityPlayer craftplayer = ((CraftPlayer) player).getHandle();
          GameProfile playerProfile = craftplayer.getProfile();
          Property property = playerProfile.getProperties().get("textures").iterator().next();
          String texture = property.getValue();
          String signature = property.getSignature();
      
          setSkin(entityPlayer.getBukkitEntity(), texture, signature);
      
          entityPlayer.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
          nmsWorld.addEntity(entityPlayer);
      
          PacketPlayOutPlayerInfo playerInfoAdd = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, entityPlayer);
          PacketPlayOutNamedEntitySpawn namedEntitySpawn = new PacketPlayOutNamedEntitySpawn(entityPlayer);
          PacketPlayOutEntityHeadRotation headRotation = new PacketPlayOutEntityHeadRotation(entityPlayer, (byte) ((location.getYaw() * 256f) / 360f));
          PacketPlayOutPlayerInfo playerInfoRemove = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, entityPlayer);
      
          for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
              PlayerConnection connection = ((CraftPlayer) onlinePlayer).getHandle().playerConnection;
              connection.sendPacket(playerInfoAdd);
              connection.sendPacket(namedEntitySpawn);
              connection.sendPacket(headRotation);
              connection.sendPacket(playerInfoRemove);
          }
          return entityPlayer;
      }
      

      SetSkin Code

      public static void setSkin(Player player, String texture, String signature) {
          EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();
          GameProfile playerProfile = entityPlayer.getProfile();
          playerProfile.getProperties().put("textures", new Property("textures", texture, signature));
          for (Player online : Bukkit.getOnlinePlayers()) {
              online.hidePlayer(player);
              online.showPlayer(player);
          }
      }
      

       
       

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              Al3mid3x Nour Edden
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: