is it possible to listen for a player putting on a helmet

Discussion in 'Plugin Development' started by nrs23, Nov 9, 2013.

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

    nrs23

    Would it be possible to listen for a player putting on a golden helmet then giving them an effect?
     
  2. Offline

    TeeePeee

    I would assume that you would want to InventoryInteractEvent (see APIDocs), however, I haven't tested it.

    In theory, check if the getWhoClicked() is wearing a golden helmet and apply potion if resolves to true. If this doesn't work, perhaps that running a synchronous delayed task of 1-tick would make it work (to allow the event to fire before checking?)
     
  3. Offline

    nrs23

    TeeePeee Sweet thanks, ill test it out
     
  4. Offline

    NinjaWAffles

    I created a little thing that should help you out with your problem. Essentially, I've created a custom event and listened on each possible way a player can put on armor, and then called the event. You can insert these two classes into your project any way you want, and then listen for PlayerArmorChangeEvent and it'll fire whenever someone does it. Right now, it'll fire if someone puts on armor via their inventory, right-clicking on the armor, or putting it on via a dispenser. I've tested it and it works fine. If you find any problems with it, please let me know and I'll update it.

    Gist Link: PlayerArmorChangeEvent Source

    Example:
    Code:Java
    1.  
    2. @EventHandler
    3. public void onArmorChanged(PlayerArmorChangeEvent e)
    4. {
    5. Player player = e.getPlayer();
    6.  
    7. System.out.println(player.getName() + " has changed his armor status!");
    8. }
    9.  
     
    GusGold likes this.
  5. Offline

    GusGold

    NinjaWAffles
    From what I can tell, this doesn't return the armour that is equipped. Can I suggest that as an upcoming feature? other than that, nice job :)
     
  6. Offline

    NinjaWAffles

    I have put up a newer version. It should now be there. And thanks. :)
     
  7. Offline

    GusGold

    NinjaWAffles
    :) While we're on the topic of suggestions, also return the method by which they are equipped? I'll stop bugging you now :p
     
  8. Offline

    NinjaWAffles

    Could you elaborate more on what you mean by that?
     
  9. Offline

    GusGold

    NinjaWAffles
    Whether the player equipped it them self, or if a dispenser did it.
    Just nice to know, and occasionally use information :)
     
  10. Offline

    NinjaWAffles

    Done, sir. ;)
     
    GusGold likes this.
Thread Status:
Not open for further replies.

Share This Page