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]
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); } }
- clones
-
SPIGOT-6675 Error While Displaying NPC Skin
- Closed