Inventory Contains

Discussion in 'Spigot Plugin Development' started by ItsWill, Jun 22, 2015.

  1. Hey! I'm trying to make is so if the player doesn't have a Wood Hoe, and doesn't have a certain display name it will give them a Wood Hoe. Any thoughts?
    This is the start of my code, checking if the inventory contains a wood hoe, but I don't know how to check for the display name. Thanks
    PHP:
                                if (!(player.getInventory().contains(Material.WOOD_HOE)));
                                player.getInventory().addItem(WoodHoe);
    I have identified the ItemStack and everything.
     
  2. Well, what have you tried? We're not just gonna give you the code, spoonfeeding doesn't help anyone.
    Player#getDisplayName() will get you the display name, then just compare that to a string?
     
  3. Psuedo-code maybe?
     
  4. To check for display name:
    e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase("Display Name")
     
  5. Lol, didn't need to be spoonfeed but thanks!
     
  6. That doesn't work since that's checking for PlayerInteractEvent I think.
     
  7. Why wouldn't it work? I see no problem with it.
     
  8. Because e isn't identified, i'm not using an event.
     
  9. Code (Text):
                                if (!(player.getInventory().contains(Material.WOOD_HOE && event.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase("Wood Hoe"))));
    It doesn't allow && statements :/
     
  10. Wait, sorry because if(! Sorry for wasting my time, mind bl
    sorry for wasting your time i realize now.
     
  11. Well that's because you're not formatting it right...
    If you want to use && in if statements then it goes like this:
    Code (Text):
    if(boolean && boolean) {

        //stuff goes here

    }
     
  12. I will help here:
    Code (Text):
    if(player.getInventory().contains(Material.WOOD_HOE))
    {
    -FIND THE ITEM-
    if(item.hasItemMeta())
        if(item.getItemMeta().hasDisplayName())
            if(item.getItemMeta().getDisplayName().toLowerCase().equals("Name")
                break;
    [If not, give item =)]
    }