Can't check to see if a player has a potato in hand

Discussion in 'Plugin Development' started by aman207, May 31, 2014.

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

    aman207

    I made a simple plugin that turns raw food and ore into their corresponding "cooked" version but for some reason I can't get the potato to work.

    From my onCommand class
    Code:java
    1.  
    2. Player player = (Player)sender;
    3. Material item = player.getItemInHand().getType();
    4.  
    5. //...
    6.  
    7. else if (item.name().equals("POTATO"))
    8. {
    9. if(sender.hasPermission("cookit.food.potato"))
    10. {
    11. player.setItemInHand(new ItemStack(Material.BAKED_POTATO, amount));
    12. player.sendMessage(ChatColor.GREEN + "Successfully cooked your Potato(s)!");
    13. }
    14. else
    15. {
    16. noPermission(sender, "potato");
    17. }
    18. }


    I'm missing some other little things but you get the point

    Everything else works but the potato, anybody got an idea on what's wrong?
     
  2. Hmmm.... Try POTATO_ITEM ?
     
    aman207 likes this.
  3. Offline

    aman207

    Ah yes that worked. And you wouldn't happen to know about what the material name for Lapis is would you? I'm not talking about the ore or the block. I know its a dye but I can't seem to find anything related to it in the API at all (other than the block and the ore)
     
  4. Offline

    Kobting

  5. Offline

    aaomidi

    Never, ever, ever, use the name of the Item. Ever.
    Also you need to make sure the Item in the player's Hand isn't null.
     
  6. Offline

    aman207

    Kobting
    That worked. Thanks. (guess I could have searched that myself oopsie)

    aaomidi
    How should I be doing it them?
     
  7. Offline

    Roughbread

    If you do want to check if the item in hand is named - make checks for 'hasItemMeta()' & 'getItemMeta().hasCustomName()' before checking the name.

    Usually check what the item type (Material) is first before checking names anyways.
     
Thread Status:
Not open for further replies.

Share This Page