Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Accurately check if event is cancelled

Comments in 'Plugin Development' started by wolfdale, Sep 17, 2015.

  1. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    I notice that if i cancel an event in a plugin, the other plugins wont get that the event is cancelled.
    For example in simpleauth, when players are not logged in, the placing and breaking of blocks are cancelled
    But in my plugin:
    Code:
    public function onBreak(BlockBreakEvent $event) {
        if ($event->isCancelled()) return;
        //code
    }
    Even if the event is cancelled, the code below still runs, how to accurately check if event is cancelled?
  2. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    You have to change the priority of your event listener.
    Lower priority get called earlier, Higher priority called later.

    Actually, if you want to be compatible with SimpleAuth the best way to do it is to create a permission. SimpleAuth takes away all permissions, so in your event listener you check if the player has that permission. If they don't have the permission they are not authenticated yet.
    wolfdale likes this.
  3. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    PHP:
    /**
    * @priority high
    * @ignoreCancelled false
    */
    wolfdale likes this.
  4. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    For now, i call SimpleAuth to check if player have logged in
    Do i put this infront of the function?
    I tried putting it like this, but the code below still runs
    PHP:
    /**
    * @priority high
    * @ignoreCancelled false
    */
    public function onBreak(BlockBreakEvent $event) {
        if (
    $event->isCancelled()) return;
        
    //code
    }
  5. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    That is PHP docs, nothing to do with the real code.
  6. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    Yes, because listeners are fired according to priority, from low to high. SimpleAuth is priority MONITOR so it gets fired last. That's why if you expect SimpleAuth to cancel things, you need to use permissions.
  7. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    PHP:
    EventPriority::LOWEST => [],
    EventPriority::LOW => [],
    EventPriority::NORMAL => [],
    EventPriority::HIGH => [],
    EventPriority::HIGHEST => [],
    EventPriority::MONITOR => []
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Yep, and this is a really bad thing that @shoghicp should not have done. https://github.com/PocketMine/SimpleAuth/issues/79

Share This Page

Advertisement