Skip to content

Calling addItem on a player's inventory causes an error #22

@FalcoG

Description

@FalcoG

When attempting to give a player an item by using addItem, it causes a Java error.

[11:18:21 ERROR]: [...] NO METHOD FOUND:
[11:18:21 ERROR]: [...]     org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryPlayer
[11:18:21 ERROR]: [...]     addItem
[11:18:21 ERROR]: [...]      - java.lang.Object[]
[11:18:21 ERROR]: [...] 

Example code to replicate it:

import { PlayerChatEvent, ServerCommands, ServerEvents, Players, ItemStack, Material } from '@customrealms/core'

ServerEvents.register(PlayerChatEvent, event => {
  const player = event.getPlayer()

  const inventory = player.getInventory()
  const invSlot = inventory.firstEmpty()
  if (invSlot === -1) return

  const voteItemMaterial = Material.withName('DIRT')
  if (voteItemMaterial == null) return

  const voteItem = ItemStack.create(voteItemMaterial, 1)
  console.log('give item', voteItemMaterial.getName(), invSlot)
  inventory.addItem(voteItem)
})

edit:
replacing inventory.addItem(voteItem) with inventory.setItem(invSlot, voteItem) doesn't work either (no error) but replacing it with inventory.setItemInMainHand(voteItem) does work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions