#you can't just cast a map to an

1 messages · Page 1 of 1 (latest)

short raft
#

which line

#

Map<Player, ItemStack> playerItemStackMap = itemInSlot;

playerItemInSlotMap.put(player, (ItemStack) itemInSlot);

oak mist
#

second one, you're casting it there

short raft
#

itemInSlot is an ItemStack

oak mist
#

then you can't assign it to a map var

short raft
#

when i dont cast it i get

'put(org.bukkit.entity.Player, org.bukkit.inventory.ItemStack)' in 'java.util.Map' cannot be applied to '(org.bukkit.entity.Player, java.util.Map<org.bukkit.entity.Player,org.bukkit.inventory.ItemStack>)'

oak mist
#

yes, because that code doesn't make sense

short raft
#

when i cast it it fixes the error

oak mist
#

it will throw on runtime

short raft
#

so is Map<Player, ItemStack> playerItemStackMap = itemInSlot; correct?

oak mist
#

no

#

you can't assign an ItemStack to a Map variable

short raft
#

why not

#

its a player variable

oak mist
#

an itemstack is not a map

#

they are incompatible types

short raft
oak mist
#

java.util.Map

short raft
#

because afaik. a map is just hashmap so i can set player's variables seperately

oak mist
#

a map is an abstraction of a key-value store, HashMap is an implementation of it, ItemStack is neither, hence you can't assign it to that variable

short raft
#

so how do i set the player variable to the itemstack

oak mist
#

you want to put the itemstack into the player's inventory?

short raft
#

no

#

its a shop plugin. but i had the issue of multiple people using it would casue mixing variables

#

hense im making them per player

oak mist
#

I don't know the rest of your code, so I don't know what you're trying to do

short raft
#

I can share the code however it's extensive

#

~750 lines

#

Or i can share just the method im using i guess

oak mist
#

no idea what you're doing with the maps, but Map<Player, ItemStack> playerItemStackMap = itemInSlot; is invalid if itemInSlot is an ItemStack