Check if player has diamondarmour

Discussion in 'Plugin Development' started by n31ln3t, Apr 10, 2013.

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

    n31ln3t

    Hey, I know how to check players inventories to see if they have something, but I don't know how to check players armour slots, I've tried to use if(inventory.getHelmet()==diamondhelmet) but that doesn't seem to return true or false if the player has the diamondhelmet itemstack in his helmet slot.

    This is my current code:
    if(!(inventory.contains(320)) && !(inventory.contains(276))){

    player.sendMessage("You already have kit standard.");



    }
     
  2. Offline

    Terradominik

    you have to change that to if(inventory.getHelmet().getType == Material.DIAMOND_HELMET)
     
  3. Offline

    n31ln3t

    Thanks, what does getType() do?
     
  4. Offline

    stuntguy3000

    getType essentially gets the type, or in this case Material..DIAMOND_HELMET

    Technically, it should be getMaterial not to confuse ^.^
     
  5. Offline

    n31ln3t

    If there a way to check if helmet == a specific itemstack I created? Or do I just replace Material.diamondhelmet with my itemstack's name?
     
  6. Offline

    stuntguy3000

    Not sure..
     
  7. Offline

    n31ln3t

    Guys, none of this is working!

    Here is my code:
    if(inventory.contains(320) && inventory.contains(276)){
    if(inventory.getHelmet().getType() == Material.DIAMOND_HELMET && inventory.getChestplate().getType() == Material.DIAMOND_CHESTPLATE && inventory.getLeggings().getType() == Material.DIAMOND_LEGGINGS && inventory.getBoots().getType()== Material.DIAMOND_BOOTS){
    player.sendMessage(ChatColor.RED+"You already this kit!");
    }
    }else{
    Kit="Standard";
    player.sendMessage(ChatColor.GOLD+"Kit set to: "+Kit);
    }
     
  8. Offline

    stuntguy3000

    Define not working. Whats not working?
     
  9. Offline

    poo2thegeek

    So I assume you want to check if the player has got all of the items that they get from a kit? If so, then I would make a method similar to this:

    Code:
    public boolean hasKit(ItemStack[] kit){
        for(int i=0; i<kit.length; i++){
            if(!player.getInventory().contains(kit[i]) return false;
        }
        return true;
    }
    You give the kit as an argument. It then goes goes through each item in the kit- and checks weather or not the player has that item. If they don't, then that means they don't have that kit. If they do, then it will continue on. If their inventory contains all the items in the kit ItemStack[] then the method will return true.
    I assume this will work, but I haven't tested it.
     
  10. Offline

    n31ln3t

    This won't check if the players inventory returns or false if they have diamond armour on. Any ideas on how I could get this fixed?

    Thanks for your help,
    Neil.

    That code up there doesn't return true or false if player has those items.

    Thanks for your help,
    Neil.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  11. Offline

    n31ln3t

    Guys, I still need help, for example:

    if(inventory.getHelmet()==MATERIAL.IRON_HELMET){
    player.sendMessage("You have an iron helmet");
    }

    It doesn't say you have an iron helmet.

    Ok, I finally got this working!!

    Although, when player clicks on the sign, it gives him the stuff,
    but you can't see it, the players inventory needs to update on his screen, it updates by eating, or falling down from a height, is there a way I could make it so when I give the kit to the person with the stuff, I can update it so they can see it.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  12. Offline

    ConflictRealms

    or falling down from a height

    Thats strange.. never have had that update a inventory before
    but its player.updateInventory();
     
  13. Use item.equals(yourItem), that compares the type, data value, amount, display name and any other stuff that makes an item unique.

    There's also item.isSimilar(item) which does the exact same thing as equals() except it ignores stack amounts, useful in certain situations.

    If you've used player.getInventory().addItem() then it should've updated the inventory, but if player.updateInventory() helps you then by all means, use it :p
     
  14. Offline

    n31ln3t

    Are you sure it's player.updateInventory(); ?
    It says: Add @suppresswarnings deprecation to onPlayerIntecact.

    Should I add the @supresswarning to onPlayerInterect or is it inventory.updateInventory();


    EDIT: THANKS I LOVE YOU (No gayness intended) IT WORKED!
     
  15. Offline

    ConflictRealms

    Its deprecated because Bukkit is automatically updating inventory's when you add items like Digi said above. But test inventory.updateInventory();
     
  16. Offline

    n31ln3t

    Thanks, you've just saved me hours of headaches!
     
  17. n31ln3t
    Yes it's been deprecated for a long time, I belive it's the only method in Bukkit that you can ignore its deprecated status since I haven't seen anything that would fix the cases where it's required... so yeah, ignore deprecated status on it... but only for this one, if you see other deprecated methods/classes try to find the non-deprecated versions of them. (e.g. PlayerChatEvent is deprecated and replaced by AsyncPlayerChatEvent)
     
Thread Status:
Not open for further replies.

Share This Page