Issue Getting Item TypeID on BlockDamagedEvent

Discussion in 'Plugin Development' started by JMEYER, Jan 14, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    JMEYER

    Hey everyone,

    I've been trying to find ways to determine which object a player is using to hit a block. Below is what I believe to be a valid solution:

    Code:
        public void onBlockDamaged(BlockDamagedEvent event) {
            int itemID = event.getPlayer().getItemInHand().getTypeID();
            event.getPlayer().sendMessage("Item ID: " + itemID);
        }

    Unfortunately, each block hit comes with a flurry of unhelpful error messages:

    Code:
          at org.bukkit.ItemStack.setTypeID(ItemStack.java:96)
          at org.bukkit.craftbukkit.CraftItemStack.getType(CraftItemStack.java:21)
    
          at org.bukkit.ItemStack.setTypeID(ItemStack.java:96)
          at org.bukkit.craftbukkit.CraftItemStack.getType(CraftItemStack.java:21)
    
          at org.bukkit.ItemStack.setTypeID(ItemStack.java:96)
          at org.bukkit.craftbukkit.CraftItemStack.getType(CraftItemStack.java:21)
    
     
    Is it something I'm doing wrong or are the errors due to some part of Bukkit that is still in development?

    Many thanks,

    JMEYER

    One final bump before heading off to bed. I can't seem to figure out why this is happening.

    Again, thanks to anyone who can help; this is one of the final hurdles to finishing my plugin, and rigorous testing is to follow.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jan 8, 2016
  2. Offline

    axel3200

    Using the exact same code you used here gave no errors for me. Could you paste the entire error message you're getting?

    Also note: you got the error three times because when you "clicked" once you held down the mouse button long enough to damage the block three times.
     
  3. Offline

    JMEYER

    Thanks for the reply. I figured that has something to do with the multiple errors.

    Unfortunately, that's all I can see in the console. The error appears far more than three times, so it's difficult to see exactly what the error is.

    I will try to take a screenshot of the error when it first appears.

    EDIT:
    My Bukkit must have been outdated. I just updated to the latest version and everything's working fine.

    Thanks for the help!
     
Thread Status:
Not open for further replies.

Share This Page