Solved Listening to armor

Discussion in 'Plugin Development' started by Dave Nathanael, Jul 23, 2016.

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

    Dave Nathanael

    Hello, Bukkit Forums!

    I am trying to make an armor set plugin that gives certain effect if a player uses a certain number of armor amount with the same name (if player have 4 armor with the name: Bukkit Newbie, the player will get speed III potion effect). To do this I don't set up a scheduler and check every seconds, but I listen to the events that are possible for a player to equip/unequip armor. I listen to PlayerInteractEvent, InventoryClickEvent, BlockDispenseEvent, PlayerJoinEvent, ItemBreakEvent, and PlayerDeathEvent. Although not all of it have been checked, but I have some problems already.

    For example the PlayerInteractEvent, when I right-click with my hand holding a certain armor, I call a method to check my current equipped armorset. For example by the time I press the dispenser's button, I have 3 pieces of that Bukkit Newbie set already. The last piece is inside the dispenser, and when I pressed the button, I expect the code to check my armorset with the last piece is on me already. But what happened is the code ran and checked my armorset before the last piece is equipped. The same with InventoryClickEvent, if my current helmet slot is empty (it makes the event.getCurrentItem() is null) and I have the last piece of the set in my cursor, it still checked as the helmet slot is empty, not filled with the item in my cursor because it run before the item get in the slot.

    I have tried the ArmorEquipEvent library that're posted in spigot forums, but it didn't worked as planned, have some error on my console and the same problem I describe above. So I tried to figured it out myself.

    Anyone have an idea on how to do this? That would help me a lot!
    Thanks in advance! :D

    My current listener class: http://pastebin.com/3QPtvaS2
     
    vanhienblog likes this.
  2. @Dave Nathanael
    As you have noticed, all events are fired before the action happens, this is so you can cancel them. What you can do is schedule a BukkitRunnable to run your code 1 tick later.
     
  3. Offline

    Dave Nathanael

    @AlvinB
    Ah I see, yeah I can try that. Is he scheduleSyncDelayedTask is the right one to use? I'll try it tomorrow! Thanks alot, Alvin! :D
     
  4. Offline

    Dave Nathanael

  5. @Dave Nathanael
    If your problem has been resolved, please mark the thread as such :)
     
  6. Offline

    Dave Nathanael

    @AlvinB
    Oops, sorry, forgot to do that, got too excited on coding xD Thanks!
     
Thread Status:
Not open for further replies.

Share This Page