Solved Using ItemStacks in other classes

Discussion in 'Spigot Plugin Development' started by Hampion, Jan 21, 2020.

  1. Hiya,

    Just still doing my very basics and learning spigot / java, I was wondering I am trying to setup and Event for an Item that is obtained with a command.

    What I have setup so far, is just simply the command that runs and gives you the item, and the event that I want the item too run once it is right clicked. However I am not too sure on how you are suppose to use an ItemStack in a completely different class. Thanks!

    I'm not looking to be spoonfed, I just would like a pointer in the right direction as google really couldn't help me.
  2. Listen got player interact event and then check if the item is the same and go from there.
  3. ItemStack has a isSimilar method which you can use for comparison. If your ItemStack isn't changing you could technically define it as a constant and this way use it in all classes, otherwise a option would be to encapsulate it in a object that holds the item(s) for you and use dependency injection to make it accessible where you need it.
    #3 Dexuby, Jan 21, 2020
    Last edited: Jan 21, 2020

  4. Thanks both of you for your help, I have now managed to figure out how to do it <3