Search in sources :

Example 1 with ProtocolManager

use of com.comphenix.protocol.ProtocolManager in project AuthMeReloaded by AuthMe.

the class InventoryPacketAdapter method sendBlankInventoryPacket.

public void sendBlankInventoryPacket(Player player) {
    ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
    PacketContainer inventoryPacket = protocolManager.createPacket(PacketType.Play.Server.WINDOW_ITEMS);
    inventoryPacket.getIntegers().write(0, PLAYER_INVENTORY);
    int inventorySize = CRAFTING_SIZE + ARMOR_SIZE + MAIN_SIZE + HOTBAR_SIZE;
    ItemStack[] blankInventory = new ItemStack[inventorySize];
    Arrays.fill(blankInventory, new ItemStack(Material.AIR));
    //old minecraft versions
    StructureModifier<ItemStack[]> itemArrayModifier = inventoryPacket.getItemArrayModifier();
    if (itemArrayModifier.size() > 0) {
        itemArrayModifier.write(0, blankInventory);
    } else {
        //minecraft versions above 1.11
        StructureModifier<List<ItemStack>> itemListModifier = inventoryPacket.getItemListModifier();
        itemListModifier.write(0, Arrays.asList(blankInventory));
    }
    try {
        protocolManager.sendServerPacket(player, inventoryPacket, false);
    } catch (InvocationTargetException invocationExc) {
        ConsoleLogger.logException("Error during sending blank inventory", invocationExc);
    }
}
Also used : PacketContainer(com.comphenix.protocol.events.PacketContainer) ProtocolManager(com.comphenix.protocol.ProtocolManager) List(java.util.List) ItemStack(org.bukkit.inventory.ItemStack) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

ProtocolManager (com.comphenix.protocol.ProtocolManager)1 PacketContainer (com.comphenix.protocol.events.PacketContainer)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 List (java.util.List)1 ItemStack (org.bukkit.inventory.ItemStack)1