mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 08:17:34 +00:00
Added PluginEvent
This commit is contained in:
parent
9ab993c817
commit
a4cbb2f938
@ -81,22 +81,21 @@ abstract class BaseEvent{
|
||||
|
||||
public static function unregisterAll(){
|
||||
self::$handlers = array();
|
||||
self::$handlerPriority = array(
|
||||
EventPriority::LOWEST => array(),
|
||||
EventPriority::LOW => array(),
|
||||
EventPriority::NORMAL => array(),
|
||||
EventPriority::HIGH => array(),
|
||||
EventPriority::HIGHEST => array(),
|
||||
EventPriority::MONITOR => array()
|
||||
);
|
||||
self::$handlerPriority = array();
|
||||
}
|
||||
|
||||
public function register(callable $handler, $priority = EventPriority::NORMAL){
|
||||
if($priority < EventPriority::MONITOR or $priority > EventPriority::LOWEST){
|
||||
return false;
|
||||
}
|
||||
$identifier = Utils::getCallableIdentifier($handler);
|
||||
if(isset(self::$handlers[$identifier])){ //Already registered
|
||||
return false;
|
||||
}else{
|
||||
self::$handlers[$identifier] = $handler;
|
||||
if(!isset(self::$handlerPriority[(int) $priority])){
|
||||
self::$handlerPriority[(int) $priority] = array();
|
||||
}
|
||||
self::$handlerPriority[(int) $priority][$identifier] = $handler;
|
||||
return true;
|
||||
}
|
||||
@ -110,8 +109,11 @@ abstract class BaseEvent{
|
||||
}else{
|
||||
for($priority = EventPriority::MONITOR; $priority <= EventPriority::LOWEST; ++$priority){
|
||||
unset(self::$handlerPriority[$priority][$identifier]);
|
||||
if(count(self::$handlerPriority[$priority]) === 0){
|
||||
unset(self::$handlerPriority[$priority]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
unset(self::$handlers[$identifier]);
|
||||
return true;
|
||||
}else{
|
||||
|
@ -38,6 +38,7 @@ abstract class EventHandler{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($event instanceof CancellableEvent and $event->isCancelled()){
|
||||
return BaseEvent::DENY;
|
||||
}elseif($event->isAllowed()){
|
||||
@ -45,6 +46,7 @@ abstract class EventHandler{
|
||||
}else{
|
||||
return BaseEvent::NORMAL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
abstract class MalleableEvent extends BaseEvent{
|
||||
|
||||
}
|
@ -19,6 +19,15 @@
|
||||
*
|
||||
*/
|
||||
|
||||
abstract class MalleableCancellableEvent extends CancellableEvent{
|
||||
|
||||
/**
|
||||
* Plugins that create events must use one of these classes as the base
|
||||
*/
|
||||
|
||||
abstract class PluginEvent extends BaseEvent{
|
||||
|
||||
}
|
||||
|
||||
abstract class CancellablePluginEvent extends CancellableEvent{
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user