Open FalcoG opened 2 years ago
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.
inventory.addItem(voteItem)
inventory.setItem(invSlot, voteItem)
inventory.setItemInMainHand(voteItem)
https://github.com/customrealms/core/blob/c66d3e4ee0997461df3cbb3cf43e062470a0de57/src/inventory/Inventory.ts#L28-L32
Maybe line 30 needs to be spread?
When attempting to give a player an item by using addItem, it causes a Java error.
Example code to replicate it:
edit: replacing
inventory.addItem(voteItem)
withinventory.setItem(invSlot, voteItem)
doesn't work either (no error) but replacing it withinventory.setItemInMainHand(voteItem)
does work.