Cancelling PlayerDamageEvent on two different plugins

Discussion in 'Plugin Development' started by OshaGoro, May 26, 2020.

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

    OshaGoro

    Hey all,

    Say I have two different plugins, A and B, which both have a listener for PlayerDamageEvent. Plugin A has an EventPriority of LOW and Plugin B has an EventPriority of HIGH. This means that plugin A's eventhandler will run before plugin B's I believe.

    I want plugin A to have it's eventhandler run and do its thing (say for example it sets the damage to 10), but after A has finished, I would like to choose whether plugin B's PlayerDamageEvent handler will run. Calling event.setCancelled(true) in Plugin A will cancel the event altogether I believe (player won't take any damage at all).

    Is there a way to do this by any chance or any suggestions to do this? Thanks!
     
  2. Offline

    KarimAKL

    @OshaGoro You just have to not do anything if it's cancelled. I believe this can be achieved by two ways.
    1. Set "ignoreCancelled" to "true" in your EventHandler annotation.
    2. Return if the event is cancelled by checking for Cancellable#isCancelled().

    I've never tested it but, i'd think it's the other way around. Higher priority means it runs first.
     
  3. Offline

    caderapee

    @OshaGoro https://bukkit.gamepedia.com/Event_API_Reference#Event_Priorities
    EventPriority.HIGHEST has the last word on an event.


    When, you cancel an event, bukkit will keep testing others plugins with this event, it's why u can add in parameter to @eventHandler, 'ignoreCancelled'.

    You can use event.isCancelled() for see if an another plugin has cancelled it, then use a condition for see if you run your code or not.
     
    KarimAKL likes this.
Thread Status:
Not open for further replies.

Share This Page