Checking armor contents onMoveEvent

Discussion in 'Plugin Development' started by tidalyt, Feb 1, 2017.

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

    tidalyt

    Hey, so im currently making a plugin where if your wearing DiamondBoots with the name "StrongBoots" you get unlimted strength 2, problem is even when you take boots off you still have unlimited strength 2.
    What Im trying to do is onMoveEvent check if player is still wearing boots with DisplayName StrongBoots

    Code:
         /* 91: */  @EventHandler
         public void onPlayerMove(PlayerMoveEvent e) {
             Player p = e.getPlayer();
             if(p.getInventory().getBoots().getItemMeta().hasDisplayName("Strong Boots"));
    But I get error
    Any help is appreciated.
     
  2. Offline

    ipodtouch0218

    @tidalyt
    hasDisplayName returns a boolean if it has a custom name. Use "getCustomName" and .equals(String) to test the custom name itself.
     
  3. Offline

    Drkmaster83

    Also, be wary, because if the player isn't wearing anything in that slot, or if they are and the item isn't named, you'll get a NullPointerException (either the item is null or the itemmeta is null, or the name on the item is null).
     
  4. Offline

    tidalyt

    Yes I have this now, how do I fix this issue?
    @Drkmaster83
    @ipodtouch0218
     
    Last edited: Feb 4, 2017
  5. Offline

    Disgastings

    Correct me if i'm wrong but i would do
    if (item.getTypeID() == 0) {
     
  6. Offline

    Zombie_Striker

    @Disgastings
    Ids are deprecated. Don't use ids. Instead, check material types.

    BTW: If an item is equal to 0 (air), then the item will be null, meaning you should nullcheck instead of checking the type.
     
  7. Offline

    Drkmaster83

    You must check if their boots are air, then if their boots .hasItemMeta(), then if their boots' itemmeta .hasDisplayName(), then you can do what you were doing.
     
  8. Offline

    MaxFireIce

    Check if the armor contents are null, and check your boolean that .hasDisplayName() has
     
Thread Status:
Not open for further replies.

Share This Page