Solved Send a message when a player has no armour equipped.

Discussion in 'Plugin Development' started by racoonsru1e, Jan 4, 2015.

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

    racoonsru1e

    Code:
            @EventHandler
            public void eventInventoryClose(final InventoryCloseEvent event){
                final Player player = (Player) event.getPlayer();
                final PlayerInventory inventory = event.getPlayer().getInventory();
                if(inventory.getHelmet() == null
                        || inventory.getChestplate() == null
                        || inventory.getLeggings() == null
                        || inventory.getBoots() == null){
                                ((Player)event.getPlayer()).sendMessage("Armor Set: None");
                            }
                        }
    This is not working. I can't seem to find a reason why.
     
  2. Offline

    1Rogue

    Looks fine to me, show where you are registering it.
     
  3. Offline

    racoonsru1e

    What do you mean?
     
  4. Offline

    IZeusI

    Show the top part of the class file, and the top part of the main class file too.
     
  5. Offline

    timtower Administrator Administrator Moderator

  6. Offline

    macboinc

    Don't use null for Armor, use Material.AIR.
     
    GrandmaJam likes this.
  7. @racoonsru1e Your checking if one is null, do && not ||

    && = and
    || = or
     
  8. Offline

    racoonsru1e

    I want it to send a message when they have an incomplete set on as well...

    Here is the full class: http://pastebin.com/zdb2ypPH
     
    Last edited by a moderator: Jan 4, 2015
  9. Offline

    _Cookie_

    Why not just

    if(p.getInventory().getArmourContents() == null){

    }
     
    GrandmaJam likes this.
  10. Offline

    racoonsru1e

    If I did that, then if the player takes only one, two or three pieces of their armour off, it will not send them a message.

    EDIT: I did try it but it did not work for some reason...

    Created a separate event handler with the exact same code that I started with in it and tested it. For some reason it worked. Thanks for all the help anyway!

    Solved.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 31, 2016
Thread Status:
Not open for further replies.

Share This Page