#cast an ItemStack to a custom class

1 messages · Page 1 of 1 (latest)

white hazel
#

Hey, I try to cast an class that extends the ItemStack class but when I try to cast it I got this error java class org.bukkit.inventory.ItemStack cannot be cast to class fr.thesky.weit.CustomItem (org.bukkit.inventory.ItemStack is in unnamed module of loader java.net.URLClassLoader @18769467; fr.thesky.weit.CustomItem is in unnamed module of loader org.bukkit.plugin.java.PluginClassLoader @3d8c590e)

flat juniper
#

Correct

#

An item from the server will never be an instance of your custom class

white hazel
#

so how can I do?

flat juniper
#

You aren’t meant to extend Bukkit classes

#

What do you need this custom class for

white hazel
#

it just add a simple way to edit and set an PersistantDataContainer

flat juniper
#

Well you don’t need a custom class for that

#

Just make some methods that take in an itemstack

white hazel
#

yes but how? I add it to another class and I give the itemstack to the methods all times?

flat juniper
#

What?

white hazel
#

like an java public class foo { public static void edit(ItemStack stack) { ... } }

flat juniper
#

Mhm

#

You could even make them static if they are just utility methods