Test if block id (item id) is valid?

Discussion in 'Plugin Development' started by Plague, Jan 16, 2011.

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

    Plague

    Is there a function like isValidItemId() or something? if I want to let users to type in IDs manually, I have to test it otherwise the client goes down on null exception.
     
  2. Offline

    xpansive

    Just surround it with a try/catch block
     
  3. Offline

    Plague

    Does not help. The problem is that I create a stack of items with an nonexistant ID and put it into a player's directory. Now the server does not care, why should it, that the player has 64 items of item ID 26, it's all perfectly valid. But when the client tries to assign an icon to it, it segfaults because it does not know what to do with item ID 26...

    I can of course test the ID by hand, but that's really not a clean way.
     
  4. Offline

    xpansive

    No clue how to do it, then. I think there was a isValidItem function in hmod, we really need one in bukkit.
     
  5. Offline

    Raphfrk

    if( Material.getMaterial(id) == null ) {
    <invalid id>
    } else {
    <valid id>
    }
     
  6. Offline

    Plague

    Yesss!

    Thanks, man :)
     
  7. Offline

    PatPeter

    And to test for a valid durability it would be:
    Code:
    if (Material.getMaterial(id) != null && 0 <= data && data <= Material.getMaterial(id).getMaxDurability()) {
    <valid>
    } else {
    <invalid>
    }
     
  8. Offline

    chasechocolate

    You do realize this thread is over 1 year old...
     
  9. Offline

    md_5

    PatPeter please look at the post date before posting next time :p
     
Thread Status:
Not open for further replies.

Share This Page