[closed] [fixt]ChestPlate Checker

Discussion in 'Plugin Development' started by gamemakertim, Jun 30, 2012.

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

    gamemakertim

    Hey bukkit people :)

    I want, i a player weare a DIAMON_CHESTPLATE that it return; (Void) and that it disapeard...
    but if i were nothing, ore something else (like Lether) then that it not creash...

    Has some one a code?
    Code:
    if(player.getInventory().getChestplate().equals(new ItemStack(Material.DIAMOND_CHESTPLATE))){
        /*do something*/
    }
    doesnt work ... if a player doesn't were a chestplate


    Srry 4 my bad english, I am a Dutchie :D
     
  2. Offline

    Neodork

    Code:java
    1. if(player.getInventory().getChestplate().getType().equals(DIAMOND_CHESTPLATE){
    2. /*do something*/
    3. }


    Should work, didn't test it though.
     
  3. reverste operants of the equals methode, so replace
    player.getInventory().getChestplate() -> new ItemStack(Material.DIAMOND_CHESTPLATE)
    new ItemStack(Material.DIAMOND_CHESTPLATE) -> player.getInventory().getChestplate()

    EDIT, also comparing the item type if faster, than creating an item stack, and compare than, do
    Code:java
    1.  
    2. if(player.getInventory().getChestplate() == null) return;
    3. if(player.getInventory().getChestplate().getType() == Material.DIAMOND_CHESTPLATE)
    4. {
    5. }
     
Thread Status:
Not open for further replies.

Share This Page