1.8.8 ItemSlot Packet in Crafting

Discussion in 'Spigot Plugin Development' started by MateoxPL, Mar 31, 2020.

  1. Hello
    I have problem with code. Meanly server send packet only to legs slot but i don't know how to I can send item to crafting slots

    This is code:
    Code (Text):
    public final class Main extends JavaPlugin implements Listener {

        private static ProtocolManager protocolManager;
       
        @EventHandler
        public void onJoin(PlayerJoinEvent event){
            event.getPlayer().removeAchievement(Achievement.OPEN_INVENTORY);
        }    
               
        @Override
        public void onEnable() {
            protocolManager = ProtocolLibrary.getProtocolManager();
            getServer().getPluginManager().registerEvents(this, this);
        }

        @EventHandler
        public void onInventoryOpenEvent(PlayerAchievementAwardedEvent event){
            if(event.getAchievement().equals(Achievement.OPEN_INVENTORY)){
                event.setCancelled(true);
                Player player = event.getPlayer();  
               
                PacketContainer packetContainer = protocolManager.createPacket(PacketType.Play.Server.ENTITY_EQUIPMENT);
                packetContainer.getItemSlots().write(0, ItemSlot.HEAD);
                packetContainer.getItemModifier().write(0, new ItemStack(Material.WOOL, 1));
                packetContainer.getIntegers().write(0, player.getEntityId());

            try {
                protocolManager.sendServerPacket(player, packetContainer);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }
    }