mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-03 16:49:53 +00:00
Added PluginEvent
This commit is contained in:
parent
9ab993c817
commit
a4cbb2f938
@ -81,22 +81,21 @@ abstract class BaseEvent{
|
|||||||
|
|
||||||
public static function unregisterAll(){
|
public static function unregisterAll(){
|
||||||
self::$handlers = array();
|
self::$handlers = array();
|
||||||
self::$handlerPriority = array(
|
self::$handlerPriority = array();
|
||||||
EventPriority::LOWEST => array(),
|
|
||||||
EventPriority::LOW => array(),
|
|
||||||
EventPriority::NORMAL => array(),
|
|
||||||
EventPriority::HIGH => array(),
|
|
||||||
EventPriority::HIGHEST => array(),
|
|
||||||
EventPriority::MONITOR => array()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function register(callable $handler, $priority = EventPriority::NORMAL){
|
public function register(callable $handler, $priority = EventPriority::NORMAL){
|
||||||
|
if($priority < EventPriority::MONITOR or $priority > EventPriority::LOWEST){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
$identifier = Utils::getCallableIdentifier($handler);
|
$identifier = Utils::getCallableIdentifier($handler);
|
||||||
if(isset(self::$handlers[$identifier])){ //Already registered
|
if(isset(self::$handlers[$identifier])){ //Already registered
|
||||||
return false;
|
return false;
|
||||||
}else{
|
}else{
|
||||||
self::$handlers[$identifier] = $handler;
|
self::$handlers[$identifier] = $handler;
|
||||||
|
if(!isset(self::$handlerPriority[(int) $priority])){
|
||||||
|
self::$handlerPriority[(int) $priority] = array();
|
||||||
|
}
|
||||||
self::$handlerPriority[(int) $priority][$identifier] = $handler;
|
self::$handlerPriority[(int) $priority][$identifier] = $handler;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -110,6 +109,9 @@ abstract class BaseEvent{
|
|||||||
}else{
|
}else{
|
||||||
for($priority = EventPriority::MONITOR; $priority <= EventPriority::LOWEST; ++$priority){
|
for($priority = EventPriority::MONITOR; $priority <= EventPriority::LOWEST; ++$priority){
|
||||||
unset(self::$handlerPriority[$priority][$identifier]);
|
unset(self::$handlerPriority[$priority][$identifier]);
|
||||||
|
if(count(self::$handlerPriority[$priority]) === 0){
|
||||||
|
unset(self::$handlerPriority[$priority]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unset(self::$handlers[$identifier]);
|
unset(self::$handlers[$identifier]);
|
||||||
|
@ -38,6 +38,7 @@ abstract class EventHandler{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($event instanceof CancellableEvent and $event->isCancelled()){
|
if($event instanceof CancellableEvent and $event->isCancelled()){
|
||||||
return BaseEvent::DENY;
|
return BaseEvent::DENY;
|
||||||
}elseif($event->isAllowed()){
|
}elseif($event->isAllowed()){
|
||||||
@ -45,6 +46,7 @@ abstract class EventHandler{
|
|||||||
}else{
|
}else{
|
||||||
return BaseEvent::NORMAL;
|
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