How to call an item stack from a differant method?

Discussion in 'Spigot Plugin Development' started by pondamo, Jun 25, 2015.

  1. I have two methods, one that holds the crafting recipe for Item1 and and event that is supposed to be called once the item is dropped. How would I check if the item being dropped is Item1 though. The code that I have for that is this:
    Code (Text):
    if (!(e.getItemDrop().getItemStack().equals(Item1))) {
    But it says that Item1 cannot be resolved to a variable.
     
  2. You do understand what "equals" means in Java context?
    And by the fact that you don't know what that error means, I assume you're pretty new to Java/Programming.
    You did not declare the variable "Item1" (which by the way should be called "item1", because of the Java conventions) anywhere before that line of code.
     
  3. I know what the error means, but I have declared the variable from a previous method (A method for a custom crafting recipe for Item1) and yes I know what equals means. What im trying to find out though is how do I call the variable/itemstack from the recipe method.
     
  4. You should really consider to consult some basic Java tutorials first, because you really lack some needed knowledge here.
    You do not "call" a variable from another method. Either the variable is defined global or you return the variable from the method.
    If you don't know what I'm speaking about, look at my first sentence.
     
  5. Hex

    Hex
    IRC Staff

    Pass it as an argument. However, that's a really bad design decision. I hate to sound like that, but this is pretty basic java that you should know before you start making plugins. In this case, item1 should be a field of a class (hopefully with a more intuitive name) that is accessed by both methods.