Solved Packet Player Entity Interact Event

Discussion in 'Spigot Plugin Development' started by blackone1991, Jan 13, 2018.

  1. I have a problem about Packet entity interact. Can I "PlayerInteractEvent" connect to Packet Entity ?
    My real problem is hide Packet NPC for all players and show selected player. Is it possible ?

    Thanks for helping.

    Code (Text):
                    MinecraftServer nmsServer = ((CraftServer) Bukkit.getServer()).getServer();
                    WorldServer nmsWorld = ((CraftWorld) Bukkit.getWorlds().get(0)).getHandle();
                    npc = new EntityPlayer(nmsServer, nmsWorld, new GameProfile(player.getUniqueId(), player.getDisplayName()), new PlayerInteractManager(nmsWorld));
                    npc.setLocation(x, y, z, yaw, pitch);
                    PlayerConnection connection2 = ((CraftPlayer) player).getHandle().playerConnection;
                    connection2.sendPacket(new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, npc));
                    connection2.sendPacket(new PacketPlayOutNamedEntitySpawn(npc));
  2. PlayerInteractEvent won't work. Server doesn't know about the entity you sent to the client.You need to store the entity id you sent in some class. Then You need to add a packet listener on PacketPlayInUseEntity and get id of entity from the packet. ProtocolLib and PacketWrappers will simplify this
    • Useful Useful x 1
  3. Code (Text):
            public void readPacket(Packet<?> packet){
                            int id = (Integer)getValue(packet, "a");
                            System.out.println(getValue(packet, "action").toString() + "- " + id);
    I find this code. It's work but how can I write packet NPC ID ? Any idea ?
  4. Where do you wanna right packet npc id? What exactly do you want and what is your problem?
  5. You can do smth like this
  6. Zenith


    You could use ProtocolLib's packet listener.
    • Agree Agree x 2
  7. I solved problem but I have other questions. How can I equip armor NMS entity ?

    Code (Text):
    npcasd.setEquipment(EnumItemSlot.HEAD, CraftItemStack.asNMSCopy(new ItemStack(Material.DIAMOND_HELMET)));
     PlayerConnection connection2 = ((CraftPlayer) player).getHandle().playerConnection;
    connection2.sendPacket(new PacketPlayOutEntityEquipment());
    If I spawn the npc, the server is kicking me.
  8. You send an empty packet. Use the constructor with args int entityId, slot, ItemStack toEquip
    • Agree Agree x 1
  9. Zenith


    I'd just stick to using ProtocolLib so it's not version dependent. Try this:
    Code (Text):
    public void setEquipment(int entityId, EnumWrappers.ItemSlot slot, ItemStack itemStack) throws InvocationTargetException {
            PacketContainer container = new PacketContainer(PacketType.Play.Server.ENTITY_EQUIPMENT);
            container.getIntegers().write(0, entityId);
            container.getItemSlots().write(0, slot);
            container.getItemModifier().write(0, itemStack);
            for(Player player : Bukkit.getOnlinePlayers()){
                ProtocolLibrary.getProtocolManager().sendServerPacket(player, container);
    • Agree Agree x 2

Share This Page