[Solved] What the hell????? getHeldItemSlot()

Discussion in 'Spigot Plugin Development' started by gogobebe2, May 9, 2015.

Thread Status:
Not open for further replies.
  1. [​IMG]
    Lol what?
    Code (Text):
    Inventory inventory = player.getInventory()
    Then when I call
    Code (Text):
    , it doesn't work.
    Then when I try do it all in one with:
    Code (Text):
    , it does.
    What the hell?
    Here are my import statements:

    Code (Text):
    import com.gmail.gogobebe2.bountyhead.BountyHead;
    import net.ess3.api.MaxMoneyException;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.SkullMeta;

    import java.math.BigDecimal;
    This small thing isn't urgent because I can just use the full line, but I want to know why.
    #1 gogobebe2, May 9, 2015
    Last edited: May 9, 2015
  2. gigosaurus


    Simple really, getHeldItemSlot() is a method in PlayerInventory, not Inventory.

    Code (Java):
    PlayerInventory inventory = player.getInventory();
    • Agree Agree x 1
    • Winner Winner x 1
  3. gigosaurus


    Clear enough for you now? [​IMG]
    • Funny Funny x 2
  4. I'm assuming he doesn't use IntelliJ and doesn't know how errors are dictated in the IDE (or is possibly asking for errors in console) :p
  5. I see that.
    But does your IDE give you an error?

    Eclipse > Hover over error > error shown?

    I don't use IntelliJ.

    Anyways, OP, what @gigosaurus said is correct.
    #6 Coltll, May 9, 2015
    Last edited: May 9, 2015
  6. gigosaurus


    lol I saw his profile pic and just felt the need to do that.
    Should've gone to specsavers.
    • Funny Funny x 2
  7. The error when you hover over is: "cannot resolved method getHeldItemSlot()"
    Ohhhh. Seems to work now. Thanks babe. *kiss*
  8. You point inventory to player.getInventory(). Why do you call the method again 4 and 5 lines later?

    -- This isn't a method in the Inventory class as far as I can see.

    final int AMOUNT;
    -- Remove this.

    -- Do you want NullPointerExceptions. This is how you get null pointer exceptions.
  9. Mate calm down ahahhaha. I know how to program. I just did that to show that it isn't working.

    "You point inventory to player.getInventory(). Why do you call the method again 4 and 5 times later?"
    Read my thread and maybe you'll see why.

    getHeldItemSlot() is certainly a method.

    final int AMOUNT is used later in the code. Calm down.

    if (player.getInventory.getItemInHand().getType.equals(Material.SKULL_ITEM))
    I was just doing this to show that the getItemInHand() method doesn't work in a Inventory object but does work in a PlayerInventory object. I will do if != null. That snippet of code was purely to demonstrate the getHeldItemSlot() being undefined as Inventory object.

    The saltyness and arogance is strong in this one.
  10. yes, it is, in the PlayerInventory class.
    You were attempting to call it from an instance of Inventory, not PlayerInventory.
    • Agree Agree x 1
  11. Exactly. Now that the problem was solved by @gigosaurus, everything is good and no worries. Thanks for clearing this small issue up you 2.
    Is there a function somewhere here to mark this thread as solved? Or do I just put "[Solved]" infront of it?
Thread Status:
Not open for further replies.