Implemented event handler inheritance, allow registering handlers for any valid event (#1792)

* Event handlers always handle subclass events. public static $handlerList no longer required.
* Removed $handlerList declarations
* HandlerList cleanup: Removed HandlerList->handlers and related bake methods
* Removed obsolete Event->getHandlers()
* EventPriority: Added fromString()
* PluginManager: throw exceptions on registering handlers with invalid priorities

This allows specifying a handler of `EntityDamageEvent` which will handle any instanceof it (as per current behaviour), AND also now allows specifying a handler specifically for `EntityDamageByEntityEvent`, which only handles `EntityDamageEvent`.

This was not previously possible due to limitations in the way handlers were registered.

Abstract events may not be handled unless they declare the `@allowHandle` PhpDoc tag.
This commit is contained in:
SOFe
2018-03-21 01:05:09 +08:00
committed by Dylan K. Taylor
parent 1648fff916
commit 49fbbea7bf
106 changed files with 204 additions and 363 deletions

View File

@ -28,14 +28,6 @@ namespace pocketmine\event;
abstract class Event{ abstract class Event{
/**
* Any callable event must declare the static variable
*
* public static $handlerList = null;
*
* Not doing so will deny the proper event initialization
*/
/** @var string|null */ /** @var string|null */
protected $eventName = null; protected $eventName = null;
/** @var bool */ /** @var bool */
@ -75,16 +67,4 @@ abstract class Event{
/** @var Event $this */ /** @var Event $this */
$this->isCancelled = $value; $this->isCancelled = $value;
} }
/**
* @return HandlerList
*/
public function getHandlers() : HandlerList{
if(static::$handlerList === null){
static::$handlerList = new HandlerList();
}
return static::$handlerList;
}
} }

View File

@ -33,6 +33,15 @@ namespace pocketmine\event;
* MONITOR events should not change the event outcome or contents * MONITOR events should not change the event outcome or contents
*/ */
abstract class EventPriority{ abstract class EventPriority{
public const ALL = [
self::LOWEST,
self::LOW,
self::NORMAL,
self::HIGH,
self::HIGHEST,
self::MONITOR
];
/** /**
* Event call is of very low importance and should be ran first, to allow * Event call is of very low importance and should be ran first, to allow
* other plugins to further customise the outcome * other plugins to further customise the outcome
@ -43,7 +52,8 @@ abstract class EventPriority{
*/ */
public const LOW = 4; public const LOW = 4;
/** /**
* Event call is neither important or unimportant, and may be ran normally * Event call is neither important or unimportant, and may be ran normally.
* This is the default priority.
*/ */
public const NORMAL = 3; public const NORMAL = 3;
/** /**
@ -62,4 +72,20 @@ abstract class EventPriority{
*/ */
public const MONITOR = 0; public const MONITOR = 0;
/**
* @param string $name
*
* @return int
*
* @throws \InvalidArgumentException
*/
public static function fromString(string $name) : int{
$name = strtoupper($name);
$const = self::class . "::" . $name;
if($name !== "ALL" and \defined($const)){
return \constant($const);
}
throw new \InvalidArgumentException("Unable to resolve priority \"$name\"");
}
} }

View File

@ -24,38 +24,22 @@ declare(strict_types=1);
namespace pocketmine\event; namespace pocketmine\event;
use pocketmine\plugin\Plugin; use pocketmine\plugin\Plugin;
use pocketmine\plugin\PluginManager;
use pocketmine\plugin\RegisteredListener; use pocketmine\plugin\RegisteredListener;
class HandlerList{ class HandlerList{
/** /**
* @var RegisteredListener[] * @var HandlerList[] classname => HandlerList
*/
private $handlers = null;
/**
* @var RegisteredListener[][]
*/
private $handlerSlots = [];
/**
* @var HandlerList[]
*/ */
private static $allLists = []; private static $allLists = [];
public static function bakeAll(){
foreach(self::$allLists as $h){
$h->bake();
}
}
/** /**
* Unregisters all the listeners * Unregisters all the listeners
* If a Plugin or Listener is passed, all the listeners with that object will be removed * If a Plugin or Listener is passed, all the listeners with that object will be removed
* *
* @param Plugin|Listener|null $object * @param Plugin|Listener|null $object
*/ */
public static function unregisterAll($object = null){ public static function unregisterAll($object = null) : void{
if($object instanceof Listener or $object instanceof Plugin){ if($object instanceof Listener or $object instanceof Plugin){
foreach(self::$allLists as $h){ foreach(self::$allLists as $h){
$h->unregister($object); $h->unregister($object);
@ -65,110 +49,41 @@ class HandlerList{
foreach($h->handlerSlots as $key => $list){ foreach($h->handlerSlots as $key => $list){
$h->handlerSlots[$key] = []; $h->handlerSlots[$key] = [];
} }
$h->handlers = null;
} }
} }
} }
public function __construct(){
$this->handlerSlots = [
EventPriority::LOWEST => [],
EventPriority::LOW => [],
EventPriority::NORMAL => [],
EventPriority::HIGH => [],
EventPriority::HIGHEST => [],
EventPriority::MONITOR => []
];
self::$allLists[] = $this;
}
/** /**
* @param RegisteredListener $listener * Returns the HandlerList for listeners that explicitly handle this event.
* *
* @throws \Exception * Calling this method also lazily initializes the $classMap inheritance tree of handler lists.
*/
public function register(RegisteredListener $listener){
if($listener->getPriority() < EventPriority::MONITOR or $listener->getPriority() > EventPriority::LOWEST){
return;
}
if(isset($this->handlerSlots[$listener->getPriority()][spl_object_hash($listener)])){
throw new \InvalidStateException("This listener is already registered to priority " . $listener->getPriority());
}
$this->handlers = null;
$this->handlerSlots[$listener->getPriority()][spl_object_hash($listener)] = $listener;
}
/**
* @param RegisteredListener[] $listeners
*/
public function registerAll(array $listeners){
foreach($listeners as $listener){
$this->register($listener);
}
}
/**
* @param RegisteredListener|Listener|Plugin $object
*/
public function unregister($object){
if($object instanceof Plugin or $object instanceof Listener){
$changed = false;
foreach($this->handlerSlots as $priority => $list){
foreach($list as $hash => $listener){
if(($object instanceof Plugin and $listener->getPlugin() === $object)
or ($object instanceof Listener and $listener->getListener() === $object)
){
unset($this->handlerSlots[$priority][$hash]);
$changed = true;
}
}
}
if($changed){
$this->handlers = null;
}
}elseif($object instanceof RegisteredListener){
if(isset($this->handlerSlots[$object->getPriority()][spl_object_hash($object)])){
unset($this->handlerSlots[$object->getPriority()][spl_object_hash($object)]);
$this->handlers = null;
}
}
}
public function bake(){
if($this->handlers !== null){
return;
}
$entries = [];
foreach($this->handlerSlots as $list){
foreach($list as $hash => $listener){
$entries[$hash] = $listener;
}
}
$this->handlers = $entries;
}
/**
* @param null|Plugin $plugin
* *
* @return RegisteredListener[] * @param string $event
*
* @return null|HandlerList
* @throws \ReflectionException
*/ */
public function getRegisteredListeners($plugin = null) : array{ public static function getHandlerListFor(string $event) : ?HandlerList{
if($plugin !== null){ if(isset(self::$allLists[$event])){
$listeners = []; return self::$allLists[$event];
foreach($this->getRegisteredListeners(null) as $hash => $listener){
if($listener->getPlugin() === $plugin){
$listeners[$hash] = $plugin;
}
}
return $listeners;
}else{
while(($handlers = $this->handlers) === null){
$this->bake();
}
return $handlers;
} }
$class = new \ReflectionClass($event);
$tags = PluginManager::parseDocComment((string) $class->getDocComment());
if($class->isAbstract() && !isset($tags["allowHandle"])){
return null;
}
$super = $class;
$parentList = null;
while($parentList === null && ($super = $super->getParentClass()) !== false){
// skip $noHandle events in the inheritance tree to go to the nearest ancestor
// while loop to allow skipping $noHandle events in the inheritance tree
$parentList = self::getHandlerListFor($super->getName());
}
return new HandlerList($event, $parentList);
} }
/** /**
@ -178,4 +93,79 @@ class HandlerList{
return self::$allLists; return self::$allLists;
} }
/** @var string */
private $class;
/** @var RegisteredListener[][] */
private $handlerSlots = [];
/** @var HandlerList|null */
private $parentList;
public function __construct(string $class, ?HandlerList $parentList){
$this->class = $class;
$this->handlerSlots = array_fill_keys(EventPriority::ALL, []);
$this->parentList = $parentList;
self::$allLists[$this->class] = $this;
}
/**
* @param RegisteredListener $listener
*
* @throws \Exception
*/
public function register(RegisteredListener $listener) : void{
if(!in_array($listener->getPriority(), EventPriority::ALL, true)){
return;
}
if(isset($this->handlerSlots[$listener->getPriority()][spl_object_hash($listener)])){
throw new \InvalidStateException("This listener is already registered to priority {$listener->getPriority()} of event {$this->class}");
}
$this->handlerSlots[$listener->getPriority()][spl_object_hash($listener)] = $listener;
}
/**
* @param RegisteredListener[] $listeners
*/
public function registerAll(array $listeners) : void{
foreach($listeners as $listener){
$this->register($listener);
}
}
/**
* @param RegisteredListener|Listener|Plugin $object
*/
public function unregister($object) : void{
if($object instanceof Plugin or $object instanceof Listener){
foreach($this->handlerSlots as $priority => $list){
foreach($list as $hash => $listener){
if(($object instanceof Plugin and $listener->getPlugin() === $object)
or ($object instanceof Listener and $listener->getListener() === $object)
){
unset($this->handlerSlots[$priority][$hash]);
}
}
}
}elseif($object instanceof RegisteredListener){
if(isset($this->handlerSlots[$object->getPriority()][spl_object_hash($object)])){
unset($this->handlerSlots[$object->getPriority()][spl_object_hash($object)]);
}
}
}
/**
* @param int $priority
*
* @return RegisteredListener[]
*/
public function getListenersByPriority(int $priority) : array{
return $this->handlerSlots[$priority];
}
/**
* @return null|HandlerList
*/
public function getParent() : ?HandlerList{
return $this->parentList;
}
} }

View File

@ -32,8 +32,6 @@ use pocketmine\Player;
* Called when a player destroys a block somewhere in the world. * Called when a player destroys a block somewhere in the world.
*/ */
class BlockBreakEvent extends BlockEvent implements Cancellable{ class BlockBreakEvent extends BlockEvent implements Cancellable{
public static $handlerList = null;
/** @var Player */ /** @var Player */
protected $player; protected $player;

View File

@ -24,6 +24,5 @@ declare(strict_types=1);
namespace pocketmine\event\block; namespace pocketmine\event\block;
class BlockFormEvent extends BlockGrowEvent{ class BlockFormEvent extends BlockGrowEvent{
public static $handlerList = null;
} }

View File

@ -30,8 +30,6 @@ use pocketmine\event\Cancellable;
* Called when plants or crops grow. * Called when plants or crops grow.
*/ */
class BlockGrowEvent extends BlockEvent implements Cancellable{ class BlockGrowEvent extends BlockEvent implements Cancellable{
public static $handlerList = null;
/** @var Block */ /** @var Block */
private $newState; private $newState;

View File

@ -32,8 +32,6 @@ use pocketmine\Player;
* Called when a player places a block * Called when a player places a block
*/ */
class BlockPlaceEvent extends BlockEvent implements Cancellable{ class BlockPlaceEvent extends BlockEvent implements Cancellable{
public static $handlerList = null;
/** @var Player */ /** @var Player */
protected $player; protected $player;

View File

@ -29,8 +29,6 @@ use pocketmine\block\Block;
* Called when a block spreads to another block, such as grass spreading to nearby dirt blocks. * Called when a block spreads to another block, such as grass spreading to nearby dirt blocks.
*/ */
class BlockSpreadEvent extends BlockFormEvent{ class BlockSpreadEvent extends BlockFormEvent{
public static $handlerList = null;
/** @var Block */ /** @var Block */
private $source; private $source;

View File

@ -29,6 +29,5 @@ use pocketmine\event\Cancellable;
* Called when a block tries to be updated due to a neighbor change * Called when a block tries to be updated due to a neighbor change
*/ */
class BlockUpdateEvent extends BlockEvent implements Cancellable{ class BlockUpdateEvent extends BlockEvent implements Cancellable{
public static $handlerList = null;
} }

View File

@ -29,6 +29,5 @@ use pocketmine\event\Cancellable;
* Called when leaves decay due to not being attached to wood. * Called when leaves decay due to not being attached to wood.
*/ */
class LeavesDecayEvent extends BlockEvent implements Cancellable{ class LeavesDecayEvent extends BlockEvent implements Cancellable{
public static $handlerList = null;
} }

View File

@ -31,8 +31,6 @@ use pocketmine\Player;
* Called when a sign is changed by a player. * Called when a sign is changed by a player.
*/ */
class SignChangeEvent extends BlockEvent implements Cancellable{ class SignChangeEvent extends BlockEvent implements Cancellable{
public static $handlerList = null;
/** @var Player */ /** @var Player */
private $player; private $player;
/** @var string[] */ /** @var string[] */

View File

@ -24,6 +24,5 @@ declare(strict_types=1);
namespace pocketmine\event\entity; namespace pocketmine\event\entity;
class EntityArmorChangeEvent extends EntityInventoryChangeEvent{ class EntityArmorChangeEvent extends EntityInventoryChangeEvent{
public static $handlerList = null;
} }

View File

@ -31,8 +31,6 @@ use pocketmine\event\Cancellable;
* Called when an Entity, excluding players, changes a block directly * Called when an Entity, excluding players, changes a block directly
*/ */
class EntityBlockChangeEvent extends EntityEvent implements Cancellable{ class EntityBlockChangeEvent extends EntityEvent implements Cancellable{
public static $handlerList = null;
/** @var Block */ /** @var Block */
private $from; private $from;
/** @var Block */ /** @var Block */

View File

@ -27,7 +27,6 @@ use pocketmine\block\Block;
use pocketmine\entity\Entity; use pocketmine\entity\Entity;
class EntityCombustByBlockEvent extends EntityCombustEvent{ class EntityCombustByBlockEvent extends EntityCombustEvent{
/** @var Block */ /** @var Block */
protected $combuster; protected $combuster;

View File

@ -26,7 +26,6 @@ namespace pocketmine\event\entity;
use pocketmine\entity\Entity; use pocketmine\entity\Entity;
class EntityCombustByEntityEvent extends EntityCombustEvent{ class EntityCombustByEntityEvent extends EntityCombustEvent{
/** @var Entity */ /** @var Entity */
protected $combuster; protected $combuster;

View File

@ -27,8 +27,6 @@ use pocketmine\entity\Entity;
use pocketmine\event\Cancellable; use pocketmine\event\Cancellable;
class EntityCombustEvent extends EntityEvent implements Cancellable{ class EntityCombustEvent extends EntityEvent implements Cancellable{
public static $handlerList = null;
protected $duration; protected $duration;
/** /**

View File

@ -30,11 +30,9 @@ use pocketmine\entity\Entity;
* Called when an entity takes damage from a block. * Called when an entity takes damage from a block.
*/ */
class EntityDamageByBlockEvent extends EntityDamageEvent{ class EntityDamageByBlockEvent extends EntityDamageEvent{
/** @var Block */ /** @var Block */
private $damager; private $damager;
/** /**
* @param Block $damager * @param Block $damager
* @param Entity $entity * @param Entity $entity

View File

@ -29,7 +29,6 @@ use pocketmine\entity\Entity;
* Called when an entity takes damage from an entity sourced from another entity, for example being hit by a snowball thrown by a Player. * Called when an entity takes damage from an entity sourced from another entity, for example being hit by a snowball thrown by a Player.
*/ */
class EntityDamageByChildEntityEvent extends EntityDamageByEntityEvent{ class EntityDamageByChildEntityEvent extends EntityDamageByEntityEvent{
/** @var int */ /** @var int */
private $childEntityEid; private $childEntityEid;

View File

@ -31,7 +31,6 @@ use pocketmine\entity\Living;
* Called when an entity takes damage from another entity. * Called when an entity takes damage from another entity.
*/ */
class EntityDamageByEntityEvent extends EntityDamageEvent{ class EntityDamageByEntityEvent extends EntityDamageEvent{
/** @var int */ /** @var int */
private $damagerEntityId; private $damagerEntityId;
/** @var float */ /** @var float */

View File

@ -30,8 +30,6 @@ use pocketmine\event\Cancellable;
* Called when an entity takes damage. * Called when an entity takes damage.
*/ */
class EntityDamageEvent extends EntityEvent implements Cancellable{ class EntityDamageEvent extends EntityEvent implements Cancellable{
public static $handlerList = null;
public const MODIFIER_BASE = 0; public const MODIFIER_BASE = 0;
public const MODIFIER_ARMOR = 1; public const MODIFIER_ARMOR = 1;
public const MODIFIER_STRENGTH = 2; public const MODIFIER_STRENGTH = 2;

View File

@ -27,12 +27,9 @@ use pocketmine\entity\Living;
use pocketmine\item\Item; use pocketmine\item\Item;
class EntityDeathEvent extends EntityEvent{ class EntityDeathEvent extends EntityEvent{
public static $handlerList = null;
/** @var Item[] */ /** @var Item[] */
private $drops = []; private $drops = [];
/** /**
* @param Living $entity * @param Living $entity
* @param Item[] $drops * @param Item[] $drops

View File

@ -34,8 +34,6 @@ use pocketmine\entity\Vehicle;
* Called when a entity is despawned * Called when a entity is despawned
*/ */
class EntityDespawnEvent extends EntityEvent{ class EntityDespawnEvent extends EntityEvent{
public static $handlerList = null;
/** @var int */ /** @var int */
private $entityType; private $entityType;

View File

@ -30,8 +30,6 @@ use pocketmine\entity\Entity;
* Called when an effect is added to an Entity. * Called when an effect is added to an Entity.
*/ */
class EntityEffectAddEvent extends EntityEffectEvent{ class EntityEffectAddEvent extends EntityEffectEvent{
public static $handlerList = null;
/** @var EffectInstance|null */ /** @var EffectInstance|null */
private $oldEffect; private $oldEffect;

View File

@ -28,7 +28,6 @@ use pocketmine\entity\Entity;
use pocketmine\event\Cancellable; use pocketmine\event\Cancellable;
class EntityEffectEvent extends EntityEvent implements Cancellable{ class EntityEffectEvent extends EntityEvent implements Cancellable{
/** @var EffectInstance */ /** @var EffectInstance */
private $effect; private $effect;

View File

@ -27,8 +27,6 @@ namespace pocketmine\event\entity;
* Called when an effect is removed from an entity. * Called when an effect is removed from an entity.
*/ */
class EntityEffectRemoveEvent extends EntityEffectEvent{ class EntityEffectRemoveEvent extends EntityEffectEvent{
public static $handlerList = null;
public function setCancelled(bool $value = true){ public function setCancelled(bool $value = true){
if($this->getEffect()->getDuration() <= 0){ if($this->getEffect()->getDuration() <= 0){
throw new \InvalidStateException("Removal of expired effects cannot be cancelled"); throw new \InvalidStateException("Removal of expired effects cannot be cancelled");

View File

@ -32,8 +32,6 @@ use pocketmine\level\Position;
* Called when a entity explodes * Called when a entity explodes
*/ */
class EntityExplodeEvent extends EntityEvent implements Cancellable{ class EntityExplodeEvent extends EntityEvent implements Cancellable{
public static $handlerList = null;
/** @var Position */ /** @var Position */
protected $position; protected $position;

View File

@ -31,8 +31,6 @@ use pocketmine\item\Item;
* Called before a slot in an entity's inventory changes. * Called before a slot in an entity's inventory changes.
*/ */
class EntityInventoryChangeEvent extends EntityEvent implements Cancellable{ class EntityInventoryChangeEvent extends EntityEvent implements Cancellable{
public static $handlerList = null;
/** @var Item */ /** @var Item */
private $oldItem; private $oldItem;
/** @var Item */ /** @var Item */

View File

@ -28,8 +28,6 @@ use pocketmine\event\Cancellable;
use pocketmine\level\Level; use pocketmine\level\Level;
class EntityLevelChangeEvent extends EntityEvent implements Cancellable{ class EntityLevelChangeEvent extends EntityEvent implements Cancellable{
public static $handlerList = null;
/** @var Level */ /** @var Level */
private $originLevel; private $originLevel;
/** @var Level */ /** @var Level */

View File

@ -28,8 +28,6 @@ use pocketmine\event\Cancellable;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
class EntityMotionEvent extends EntityEvent implements Cancellable{ class EntityMotionEvent extends EntityEvent implements Cancellable{
public static $handlerList = null;
/** @var Vector3 */ /** @var Vector3 */
private $mot; private $mot;

View File

@ -27,8 +27,6 @@ use pocketmine\entity\Entity;
use pocketmine\event\Cancellable; use pocketmine\event\Cancellable;
class EntityRegainHealthEvent extends EntityEvent implements Cancellable{ class EntityRegainHealthEvent extends EntityEvent implements Cancellable{
public static $handlerList = null;
public const CAUSE_REGEN = 0; public const CAUSE_REGEN = 0;
public const CAUSE_EATING = 1; public const CAUSE_EATING = 1;
public const CAUSE_MAGIC = 2; public const CAUSE_MAGIC = 2;

View File

@ -30,8 +30,6 @@ use pocketmine\event\Cancellable;
use pocketmine\item\Item; use pocketmine\item\Item;
class EntityShootBowEvent extends EntityEvent implements Cancellable{ class EntityShootBowEvent extends EntityEvent implements Cancellable{
public static $handlerList = null;
/** @var Item */ /** @var Item */
private $bow; private $bow;
/** @var Projectile */ /** @var Projectile */

View File

@ -35,8 +35,6 @@ use pocketmine\level\Position;
* Called when a entity is spawned * Called when a entity is spawned
*/ */
class EntitySpawnEvent extends EntityEvent{ class EntitySpawnEvent extends EntityEvent{
public static $handlerList = null;
/** @var int */ /** @var int */
private $entityType; private $entityType;

View File

@ -28,8 +28,6 @@ use pocketmine\event\Cancellable;
use pocketmine\level\Position; use pocketmine\level\Position;
class EntityTeleportEvent extends EntityEvent implements Cancellable{ class EntityTeleportEvent extends EntityEvent implements Cancellable{
public static $handlerList = null;
/** @var Position */ /** @var Position */
private $from; private $from;
/** @var Position */ /** @var Position */

View File

@ -30,8 +30,6 @@ use pocketmine\event\Cancellable;
* Called when a entity decides to explode * Called when a entity decides to explode
*/ */
class ExplosionPrimeEvent extends EntityEvent implements Cancellable{ class ExplosionPrimeEvent extends EntityEvent implements Cancellable{
public static $handlerList = null;
/** @var float */ /** @var float */
protected $force; protected $force;
/** @var bool */ /** @var bool */

View File

@ -27,7 +27,6 @@ use pocketmine\entity\object\ItemEntity;
use pocketmine\event\Cancellable; use pocketmine\event\Cancellable;
class ItemDespawnEvent extends EntityEvent implements Cancellable{ class ItemDespawnEvent extends EntityEvent implements Cancellable{
public static $handlerList = null;
/** /**
* @param ItemEntity $item * @param ItemEntity $item

View File

@ -26,7 +26,6 @@ namespace pocketmine\event\entity;
use pocketmine\entity\object\ItemEntity; use pocketmine\entity\object\ItemEntity;
class ItemSpawnEvent extends EntityEvent{ class ItemSpawnEvent extends EntityEvent{
public static $handlerList = null;
/** /**
* @param ItemEntity $item * @param ItemEntity $item

View File

@ -28,7 +28,6 @@ use pocketmine\entity\projectile\Projectile;
use pocketmine\math\RayTraceResult; use pocketmine\math\RayTraceResult;
class ProjectileHitBlockEvent extends ProjectileHitEvent{ class ProjectileHitBlockEvent extends ProjectileHitEvent{
/** @var Block */ /** @var Block */
private $blockHit; private $blockHit;

View File

@ -28,7 +28,6 @@ use pocketmine\entity\projectile\Projectile;
use pocketmine\math\RayTraceResult; use pocketmine\math\RayTraceResult;
class ProjectileHitEntityEvent extends ProjectileHitEvent{ class ProjectileHitEntityEvent extends ProjectileHitEvent{
/** @var Entity */ /** @var Entity */
private $entityHit; private $entityHit;

View File

@ -26,9 +26,10 @@ namespace pocketmine\event\entity;
use pocketmine\entity\projectile\Projectile; use pocketmine\entity\projectile\Projectile;
use pocketmine\math\RayTraceResult; use pocketmine\math\RayTraceResult;
/**
* @allowHandle
*/
abstract class ProjectileHitEvent extends EntityEvent{ abstract class ProjectileHitEvent extends EntityEvent{
public static $handlerList = null;
/** @var RayTraceResult */ /** @var RayTraceResult */
private $rayTraceResult; private $rayTraceResult;

View File

@ -27,8 +27,6 @@ use pocketmine\entity\projectile\Projectile;
use pocketmine\event\Cancellable; use pocketmine\event\Cancellable;
class ProjectileLaunchEvent extends EntityEvent implements Cancellable{ class ProjectileLaunchEvent extends EntityEvent implements Cancellable{
public static $handlerList = null;
/** /**
* @param Projectile $entity * @param Projectile $entity
*/ */

View File

@ -31,8 +31,6 @@ use pocketmine\item\Item;
use pocketmine\Player; use pocketmine\Player;
class CraftItemEvent extends Event implements Cancellable{ class CraftItemEvent extends Event implements Cancellable{
public static $handlerList = null;
/** @var CraftingTransaction */ /** @var CraftingTransaction */
private $transaction; private $transaction;

View File

@ -29,8 +29,6 @@ use pocketmine\item\Item;
use pocketmine\tile\Furnace; use pocketmine\tile\Furnace;
class FurnaceBurnEvent extends BlockEvent implements Cancellable{ class FurnaceBurnEvent extends BlockEvent implements Cancellable{
public static $handlerList = null;
/** @var Furnace */ /** @var Furnace */
private $furnace; private $furnace;
/** @var Item */ /** @var Item */

View File

@ -29,8 +29,6 @@ use pocketmine\item\Item;
use pocketmine\tile\Furnace; use pocketmine\tile\Furnace;
class FurnaceSmeltEvent extends BlockEvent implements Cancellable{ class FurnaceSmeltEvent extends BlockEvent implements Cancellable{
public static $handlerList = null;
/** @var Furnace */ /** @var Furnace */
private $furnace; private $furnace;
/** @var Item */ /** @var Item */

View File

@ -27,8 +27,6 @@ use pocketmine\inventory\Inventory;
use pocketmine\Player; use pocketmine\Player;
class InventoryCloseEvent extends InventoryEvent{ class InventoryCloseEvent extends InventoryEvent{
public static $handlerList = null;
/** @var Player */ /** @var Player */
private $who; private $who;

View File

@ -31,7 +31,6 @@ use pocketmine\event\Event;
use pocketmine\inventory\Inventory; use pocketmine\inventory\Inventory;
abstract class InventoryEvent extends Event{ abstract class InventoryEvent extends Event{
/** @var Inventory */ /** @var Inventory */
protected $inventory; protected $inventory;

View File

@ -28,8 +28,6 @@ use pocketmine\inventory\Inventory;
use pocketmine\Player; use pocketmine\Player;
class InventoryOpenEvent extends InventoryEvent implements Cancellable{ class InventoryOpenEvent extends InventoryEvent implements Cancellable{
public static $handlerList = null;
/** @var Player */ /** @var Player */
private $who; private $who;

View File

@ -28,8 +28,6 @@ use pocketmine\event\Cancellable;
use pocketmine\inventory\Inventory; use pocketmine\inventory\Inventory;
class InventoryPickupArrowEvent extends InventoryEvent implements Cancellable{ class InventoryPickupArrowEvent extends InventoryEvent implements Cancellable{
public static $handlerList = null;
/** @var Arrow */ /** @var Arrow */
private $arrow; private $arrow;

View File

@ -28,8 +28,6 @@ use pocketmine\event\Cancellable;
use pocketmine\inventory\Inventory; use pocketmine\inventory\Inventory;
class InventoryPickupItemEvent extends InventoryEvent implements Cancellable{ class InventoryPickupItemEvent extends InventoryEvent implements Cancellable{
public static $handlerList = null;
/** @var ItemEntity */ /** @var ItemEntity */
private $item; private $item;

View File

@ -32,8 +32,6 @@ use pocketmine\inventory\transaction\InventoryTransaction;
* The source of this can be a Player, entities, mobs, or even hoppers in the future! * The source of this can be a Player, entities, mobs, or even hoppers in the future!
*/ */
class InventoryTransactionEvent extends Event implements Cancellable{ class InventoryTransactionEvent extends Event implements Cancellable{
public static $handlerList = null;
/** @var InventoryTransaction */ /** @var InventoryTransaction */
private $transaction; private $transaction;

View File

@ -31,8 +31,6 @@ use pocketmine\level\Level;
* Called when a Chunk is loaded * Called when a Chunk is loaded
*/ */
class ChunkLoadEvent extends ChunkEvent{ class ChunkLoadEvent extends ChunkEvent{
public static $handlerList = null;
/** @var bool */ /** @var bool */
private $newChunk; private $newChunk;

View File

@ -27,5 +27,5 @@ namespace pocketmine\event\level;
* Called when a Chunk is populated (after receiving it on the main thread) * Called when a Chunk is populated (after receiving it on the main thread)
*/ */
class ChunkPopulateEvent extends ChunkEvent{ class ChunkPopulateEvent extends ChunkEvent{
public static $handlerList = null;
} }

View File

@ -29,5 +29,5 @@ use pocketmine\event\Cancellable;
* Called when a Chunk is unloaded * Called when a Chunk is unloaded
*/ */
class ChunkUnloadEvent extends ChunkEvent implements Cancellable{ class ChunkUnloadEvent extends ChunkEvent implements Cancellable{
public static $handlerList = null;
} }

View File

@ -27,5 +27,5 @@ namespace pocketmine\event\level;
* Called when a Level is initializing * Called when a Level is initializing
*/ */
class LevelInitEvent extends LevelEvent{ class LevelInitEvent extends LevelEvent{
public static $handlerList = null;
} }

View File

@ -27,5 +27,5 @@ namespace pocketmine\event\level;
* Called when a Level is loaded * Called when a Level is loaded
*/ */
class LevelLoadEvent extends LevelEvent{ class LevelLoadEvent extends LevelEvent{
public static $handlerList = null;
} }

View File

@ -27,5 +27,5 @@ namespace pocketmine\event\level;
* Called when a Level is saved * Called when a Level is saved
*/ */
class LevelSaveEvent extends LevelEvent{ class LevelSaveEvent extends LevelEvent{
public static $handlerList = null;
} }

View File

@ -29,5 +29,5 @@ use pocketmine\event\Cancellable;
* Called when a Level is unloaded * Called when a Level is unloaded
*/ */
class LevelUnloadEvent extends LevelEvent implements Cancellable{ class LevelUnloadEvent extends LevelEvent implements Cancellable{
public static $handlerList = null;
} }

View File

@ -31,8 +31,6 @@ use pocketmine\level\Position;
* The previous spawn is included * The previous spawn is included
*/ */
class SpawnChangeEvent extends LevelEvent{ class SpawnChangeEvent extends LevelEvent{
public static $handlerList = null;
/** @var Position */ /** @var Position */
private $previousSpawn; private $previousSpawn;

View File

@ -30,8 +30,6 @@ use pocketmine\Player;
* Called when a player is awarded an achievement * Called when a player is awarded an achievement
*/ */
class PlayerAchievementAwardedEvent extends PlayerEvent implements Cancellable{ class PlayerAchievementAwardedEvent extends PlayerEvent implements Cancellable{
public static $handlerList = null;
/** @var string */ /** @var string */
protected $achievement; protected $achievement;

View File

@ -30,8 +30,6 @@ use pocketmine\Player;
* Called when a player does an animation * Called when a player does an animation
*/ */
class PlayerAnimationEvent extends PlayerEvent implements Cancellable{ class PlayerAnimationEvent extends PlayerEvent implements Cancellable{
public static $handlerList = null;
/** @var int */ /** @var int */
private $animationType; private $animationType;

View File

@ -28,8 +28,6 @@ use pocketmine\event\Cancellable;
use pocketmine\Player; use pocketmine\Player;
class PlayerBedEnterEvent extends PlayerEvent implements Cancellable{ class PlayerBedEnterEvent extends PlayerEvent implements Cancellable{
public static $handlerList = null;
/** @var Block */ /** @var Block */
private $bed; private $bed;

View File

@ -27,8 +27,6 @@ use pocketmine\block\Block;
use pocketmine\Player; use pocketmine\Player;
class PlayerBedLeaveEvent extends PlayerEvent{ class PlayerBedLeaveEvent extends PlayerEvent{
public static $handlerList = null;
/** @var Block */ /** @var Block */
private $bed; private $bed;

View File

@ -32,8 +32,6 @@ use pocketmine\Player;
* Called when a player middle-clicks on a block to get an item in creative mode. * Called when a player middle-clicks on a block to get an item in creative mode.
*/ */
class PlayerBlockPickEvent extends PlayerEvent implements Cancellable{ class PlayerBlockPickEvent extends PlayerEvent implements Cancellable{
public static $handlerList = null;
/** @var Block */ /** @var Block */
private $blockClicked; private $blockClicked;
/** @var Item */ /** @var Item */

View File

@ -24,6 +24,5 @@ declare(strict_types=1);
namespace pocketmine\event\player; namespace pocketmine\event\player;
class PlayerBucketEmptyEvent extends PlayerBucketEvent{ class PlayerBucketEmptyEvent extends PlayerBucketEvent{
public static $handlerList = null;
} }

View File

@ -28,8 +28,10 @@ use pocketmine\event\Cancellable;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\Player; use pocketmine\Player;
/**
* @allowHandle
*/
abstract class PlayerBucketEvent extends PlayerEvent implements Cancellable{ abstract class PlayerBucketEvent extends PlayerEvent implements Cancellable{
/** @var Block */ /** @var Block */
private $blockClicked; private $blockClicked;
/** @var int */ /** @var int */

View File

@ -24,5 +24,5 @@ declare(strict_types=1);
namespace pocketmine\event\player; namespace pocketmine\event\player;
class PlayerBucketFillEvent extends PlayerBucketEvent{ class PlayerBucketFillEvent extends PlayerBucketEvent{
public static $handlerList = null;
} }

View File

@ -31,8 +31,6 @@ use pocketmine\Player;
* Called when a player changes their skin in-game. * Called when a player changes their skin in-game.
*/ */
class PlayerChangeSkinEvent extends PlayerEvent implements Cancellable{ class PlayerChangeSkinEvent extends PlayerEvent implements Cancellable{
public static $handlerList = null;
/** @var Skin */ /** @var Skin */
private $oldSkin; private $oldSkin;
/** @var Skin */ /** @var Skin */

View File

@ -31,8 +31,6 @@ use pocketmine\Server;
* Called when a player chats something * Called when a player chats something
*/ */
class PlayerChatEvent extends PlayerEvent implements Cancellable{ class PlayerChatEvent extends PlayerEvent implements Cancellable{
public static $handlerList = null;
/** @var string */ /** @var string */
protected $message; protected $message;

View File

@ -35,8 +35,6 @@ use pocketmine\Player;
* The message contains a slash at the start * The message contains a slash at the start
*/ */
class PlayerCommandPreprocessEvent extends PlayerEvent implements Cancellable{ class PlayerCommandPreprocessEvent extends PlayerEvent implements Cancellable{
public static $handlerList = null;
/** @var string */ /** @var string */
protected $message; protected $message;

View File

@ -31,8 +31,6 @@ use pocketmine\Player;
* Allows the creation of players overriding the base Player class * Allows the creation of players overriding the base Player class
*/ */
class PlayerCreationEvent extends Event{ class PlayerCreationEvent extends Event{
public static $handlerList = null;
/** @var SourceInterface */ /** @var SourceInterface */
private $interface; private $interface;
/** @var string */ /** @var string */

View File

@ -33,8 +33,6 @@ use pocketmine\Server;
* Called when a player's data is about to be saved to disk. * Called when a player's data is about to be saved to disk.
*/ */
class PlayerDataSaveEvent extends Event implements Cancellable{ class PlayerDataSaveEvent extends Event implements Cancellable{
public static $handlerList = null;
/** @var CompoundTag */ /** @var CompoundTag */
protected $data; protected $data;
/** @var string */ /** @var string */

View File

@ -29,8 +29,6 @@ use pocketmine\lang\TextContainer;
use pocketmine\Player; use pocketmine\Player;
class PlayerDeathEvent extends EntityDeathEvent{ class PlayerDeathEvent extends EntityDeathEvent{
public static $handlerList = null;
/** @var Player */ /** @var Player */
protected $entity; protected $entity;

View File

@ -31,8 +31,6 @@ use pocketmine\Player;
* Called when a player tries to drop an item from its hotbar * Called when a player tries to drop an item from its hotbar
*/ */
class PlayerDropItemEvent extends PlayerEvent implements Cancellable{ class PlayerDropItemEvent extends PlayerEvent implements Cancellable{
public static $handlerList = null;
/** @var Item */ /** @var Item */
private $drop; private $drop;

View File

@ -28,8 +28,6 @@ use pocketmine\item\WritableBook;
use pocketmine\Player; use pocketmine\Player;
class PlayerEditBookEvent extends PlayerEvent implements Cancellable{ class PlayerEditBookEvent extends PlayerEvent implements Cancellable{
public static $handlerList = null;
public const ACTION_REPLACE_PAGE = 0; public const ACTION_REPLACE_PAGE = 0;
public const ACTION_ADD_PAGE = 1; public const ACTION_ADD_PAGE = 1;
public const ACTION_DELETE_PAGE = 2; public const ACTION_DELETE_PAGE = 2;

View File

@ -28,8 +28,6 @@ use pocketmine\event\Cancellable;
use pocketmine\event\entity\EntityEvent; use pocketmine\event\entity\EntityEvent;
class PlayerExhaustEvent extends EntityEvent implements Cancellable{ class PlayerExhaustEvent extends EntityEvent implements Cancellable{
public static $handlerList = null;
public const CAUSE_ATTACK = 1; public const CAUSE_ATTACK = 1;
public const CAUSE_DAMAGE = 2; public const CAUSE_DAMAGE = 2;
public const CAUSE_MINING = 3; public const CAUSE_MINING = 3;

View File

@ -30,8 +30,6 @@ use pocketmine\Player;
* Called when a player has its gamemode changed * Called when a player has its gamemode changed
*/ */
class PlayerGameModeChangeEvent extends PlayerEvent implements Cancellable{ class PlayerGameModeChangeEvent extends PlayerEvent implements Cancellable{
public static $handlerList = null;
/** @var int */ /** @var int */
protected $gamemode; protected $gamemode;

View File

@ -35,8 +35,6 @@ use pocketmine\Player;
* Called when a player interacts or touches a block (including air?) * Called when a player interacts or touches a block (including air?)
*/ */
class PlayerInteractEvent extends PlayerEvent implements Cancellable{ class PlayerInteractEvent extends PlayerEvent implements Cancellable{
public static $handlerList = null;
public const LEFT_CLICK_BLOCK = 0; public const LEFT_CLICK_BLOCK = 0;
public const RIGHT_CLICK_BLOCK = 1; public const RIGHT_CLICK_BLOCK = 1;
public const LEFT_CLICK_AIR = 2; public const LEFT_CLICK_AIR = 2;

View File

@ -31,8 +31,6 @@ use pocketmine\Player;
* Called when a player eats something * Called when a player eats something
*/ */
class PlayerItemConsumeEvent extends PlayerEvent implements Cancellable{ class PlayerItemConsumeEvent extends PlayerEvent implements Cancellable{
public static $handlerList = null;
/** @var Item */ /** @var Item */
private $item; private $item;

View File

@ -28,8 +28,6 @@ use pocketmine\item\Item;
use pocketmine\Player; use pocketmine\Player;
class PlayerItemHeldEvent extends PlayerEvent implements Cancellable{ class PlayerItemHeldEvent extends PlayerEvent implements Cancellable{
public static $handlerList = null;
/** @var Item */ /** @var Item */
private $item; private $item;
/** @var int */ /** @var int */

View File

@ -30,8 +30,6 @@ use pocketmine\Player;
* Called when a player joins the server, after sending all the spawn packets * Called when a player joins the server, after sending all the spawn packets
*/ */
class PlayerJoinEvent extends PlayerEvent{ class PlayerJoinEvent extends PlayerEvent{
public static $handlerList = null;
/** @var string|TextContainer */ /** @var string|TextContainer */
protected $joinMessage; protected $joinMessage;

View File

@ -29,7 +29,6 @@ use pocketmine\Player;
* Called when a player jumps * Called when a player jumps
*/ */
class PlayerJumpEvent extends PlayerEvent{ class PlayerJumpEvent extends PlayerEvent{
public static $handlerList = null;
/** /**
* PlayerJumpEvent constructor. * PlayerJumpEvent constructor.

View File

@ -31,8 +31,6 @@ use pocketmine\Player;
* Called when a player leaves the server * Called when a player leaves the server
*/ */
class PlayerKickEvent extends PlayerEvent implements Cancellable{ class PlayerKickEvent extends PlayerEvent implements Cancellable{
public static $handlerList = null;
/** @var TextContainer|string */ /** @var TextContainer|string */
protected $quitMessage; protected $quitMessage;

View File

@ -30,8 +30,6 @@ use pocketmine\Player;
* Called when a player joins, after things have been correctly set up (you can change anything now) * Called when a player joins, after things have been correctly set up (you can change anything now)
*/ */
class PlayerLoginEvent extends PlayerEvent implements Cancellable{ class PlayerLoginEvent extends PlayerEvent implements Cancellable{
public static $handlerList = null;
/** @var string */ /** @var string */
protected $kickMessage; protected $kickMessage;

View File

@ -28,8 +28,6 @@ use pocketmine\level\Location;
use pocketmine\Player; use pocketmine\Player;
class PlayerMoveEvent extends PlayerEvent implements Cancellable{ class PlayerMoveEvent extends PlayerEvent implements Cancellable{
public static $handlerList = null;
/** @var Location */ /** @var Location */
private $from; private $from;
/** @var Location */ /** @var Location */

View File

@ -30,8 +30,6 @@ use pocketmine\Player;
* Called when the player logs in, before things have been set up * Called when the player logs in, before things have been set up
*/ */
class PlayerPreLoginEvent extends PlayerEvent implements Cancellable{ class PlayerPreLoginEvent extends PlayerEvent implements Cancellable{
public static $handlerList = null;
/** @var string */ /** @var string */
protected $kickMessage; protected $kickMessage;

View File

@ -30,7 +30,6 @@ use pocketmine\Player;
* Called when a player leaves the server * Called when a player leaves the server
*/ */
class PlayerQuitEvent extends PlayerEvent{ class PlayerQuitEvent extends PlayerEvent{
public static $handlerList = null;
/** @var TranslationContainer|string */ /** @var TranslationContainer|string */
protected $quitMessage; protected $quitMessage;

View File

@ -30,8 +30,6 @@ use pocketmine\Player;
* Called when a player is respawned (or first time spawned) * Called when a player is respawned (or first time spawned)
*/ */
class PlayerRespawnEvent extends PlayerEvent{ class PlayerRespawnEvent extends PlayerEvent{
public static $handlerList = null;
/** @var Position */ /** @var Position */
protected $position; protected $position;

View File

@ -27,8 +27,6 @@ use pocketmine\event\Cancellable;
use pocketmine\Player; use pocketmine\Player;
class PlayerToggleFlightEvent extends PlayerEvent implements Cancellable{ class PlayerToggleFlightEvent extends PlayerEvent implements Cancellable{
public static $handlerList = null;
/** @var bool */ /** @var bool */
protected $isFlying; protected $isFlying;

View File

@ -27,8 +27,6 @@ use pocketmine\event\Cancellable;
use pocketmine\Player; use pocketmine\Player;
class PlayerToggleSneakEvent extends PlayerEvent implements Cancellable{ class PlayerToggleSneakEvent extends PlayerEvent implements Cancellable{
public static $handlerList = null;
/** @var bool */ /** @var bool */
protected $isSneaking; protected $isSneaking;

View File

@ -27,8 +27,6 @@ use pocketmine\event\Cancellable;
use pocketmine\Player; use pocketmine\Player;
class PlayerToggleSprintEvent extends PlayerEvent implements Cancellable{ class PlayerToggleSprintEvent extends PlayerEvent implements Cancellable{
public static $handlerList = null;
/** @var bool */ /** @var bool */
protected $isSprinting; protected $isSprinting;

View File

@ -27,8 +27,6 @@ use pocketmine\event\Cancellable;
use pocketmine\Player; use pocketmine\Player;
class PlayerTransferEvent extends PlayerEvent implements Cancellable{ class PlayerTransferEvent extends PlayerEvent implements Cancellable{
public static $handlerList = null;
/** @var string */ /** @var string */
protected $address; protected $address;
/** @var int */ /** @var int */

View File

@ -28,6 +28,9 @@ namespace pocketmine\event\player\cheat;
use pocketmine\event\player\PlayerEvent; use pocketmine\event\player\PlayerEvent;
/**
* @allowHandle
*/
abstract class PlayerCheatEvent extends PlayerEvent{ abstract class PlayerCheatEvent extends PlayerEvent{
} }

View File

@ -32,7 +32,6 @@ use pocketmine\Player;
* Called when a player attempts to perform movement cheats such as clipping through blocks. * Called when a player attempts to perform movement cheats such as clipping through blocks.
*/ */
class PlayerIllegalMoveEvent extends PlayerCheatEvent implements Cancellable{ class PlayerIllegalMoveEvent extends PlayerCheatEvent implements Cancellable{
public static $handlerList = null;
/** @var Vector3 */ /** @var Vector3 */
private $attemptedPosition; private $attemptedPosition;

View File

@ -25,6 +25,5 @@ declare(strict_types=1);
namespace pocketmine\event\plugin; namespace pocketmine\event\plugin;
class PluginDisableEvent extends PluginEvent{ class PluginDisableEvent extends PluginEvent{
public static $handlerList = null;
} }

View File

@ -25,6 +25,5 @@ declare(strict_types=1);
namespace pocketmine\event\plugin; namespace pocketmine\event\plugin;
class PluginEnableEvent extends PluginEvent{ class PluginEnableEvent extends PluginEvent{
public static $handlerList = null;
} }

View File

@ -29,9 +29,7 @@ namespace pocketmine\event\plugin;
use pocketmine\event\Event; use pocketmine\event\Event;
use pocketmine\plugin\Plugin; use pocketmine\plugin\Plugin;
abstract class PluginEvent extends Event{ abstract class PluginEvent extends Event{
/** @var Plugin */ /** @var Plugin */
private $plugin; private $plugin;

View File

@ -28,8 +28,6 @@ use pocketmine\network\mcpe\protocol\DataPacket;
use pocketmine\Player; use pocketmine\Player;
class DataPacketReceiveEvent extends ServerEvent implements Cancellable{ class DataPacketReceiveEvent extends ServerEvent implements Cancellable{
public static $handlerList = null;
/** @var DataPacket */ /** @var DataPacket */
private $packet; private $packet;
/** @var Player */ /** @var Player */

View File

@ -28,8 +28,6 @@ use pocketmine\network\mcpe\protocol\DataPacket;
use pocketmine\Player; use pocketmine\Player;
class DataPacketSendEvent extends ServerEvent implements Cancellable{ class DataPacketSendEvent extends ServerEvent implements Cancellable{
public static $handlerList = null;
/** @var DataPacket */ /** @var DataPacket */
private $packet; private $packet;
/** @var Player */ /** @var Player */

View File

@ -31,8 +31,6 @@ use pocketmine\utils\Utils;
* Plugins should free caches or other non-essential data. * Plugins should free caches or other non-essential data.
*/ */
class LowMemoryEvent extends ServerEvent{ class LowMemoryEvent extends ServerEvent{
public static $handlerList = null;
/** @var int */ /** @var int */
private $memory; private $memory;
/** @var int */ /** @var int */

View File

@ -29,8 +29,6 @@ use pocketmine\network\SourceInterface;
* Called when a network interface crashes, with relevant crash information. * Called when a network interface crashes, with relevant crash information.
*/ */
class NetworkInterfaceCrashEvent extends NetworkInterfaceEvent{ class NetworkInterfaceCrashEvent extends NetworkInterfaceEvent{
public static $handlerList = null;
/** /**
* @var \Throwable * @var \Throwable
*/ */

View File

@ -29,6 +29,5 @@ use pocketmine\event\Cancellable;
* Called when a network interface is registered into the network, for example the RakLib interface. * Called when a network interface is registered into the network, for example the RakLib interface.
*/ */
class NetworkInterfaceRegisterEvent extends NetworkInterfaceEvent implements Cancellable{ class NetworkInterfaceRegisterEvent extends NetworkInterfaceEvent implements Cancellable{
public static $handlerList = null;
} }

Some files were not shown because too many files have changed in this diff Show More