Giving A Player An Item


#1

Hi! How could I give a player an itemstack? (without using commands in code)


#2
Itemstack item;
Player player;
player.getInventory().offer(item);

#3
// ItemStack item; Player player;
InventoryTransactionResult res = player.getInventory().query(QueryOperationTypes.INVENTORY_TYPE.of(MainPlayerInventory.class)).offer(item);
if (!res.getRejectedItems().isEmpty()) {
    Item entity = (Item) player.getWorld().createEntity(EntityTypes.ITEM, player.getPosition());
    entity.offer(Keys.REPRESENTED_ITEM, item);
    player.getWorld().spawnEntity(entity);
}