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);
}
}
Aggregations