PocketMine-MP 5.37.4 git-07e225b0bd0d389de8a3d035fbd0ae8730a06053
Loading...
Searching...
No Matches
RegisteredListener.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
24namespace pocketmine\event;
25
28use function in_array;
29
37 public function __construct(
38 private \Closure $handler,
39 private int $priority,
40 private Plugin $plugin,
41 private bool $handleCancelled,
42 private TimingsHandler $timings
43 ){
44 if(!in_array($priority, EventPriority::ALL, true)){
45 throw new \InvalidArgumentException("Invalid priority number $priority");
46 }
47 }
48
52 public function getHandler() : \Closure{
53 return $this->handler;
54 }
55
56 public function getPlugin() : Plugin{
57 return $this->plugin;
58 }
59
60 public function getPriority() : int{
61 return $this->priority;
62 }
63
67 public function callEvent(Event $event) : void{
68 if($event instanceof Cancellable && $event->isCancelled() && !$this->isHandlingCancelled()){
69 return;
70 }
71 $this->timings->startTiming();
72 try{
73 ($this->handler)($event);
74 }finally{
75 $this->timings->stopTiming();
76 }
77 }
78
79 public function isHandlingCancelled() : bool{
80 return $this->handleCancelled;
81 }
82}
__construct(private \Closure $handler, private int $priority, private Plugin $plugin, private bool $handleCancelled, private TimingsHandler $timings)