Added PluginEvent

This commit is contained in:
Shoghi Cervantes 2014-02-10 17:33:12 +01:00
parent 9ab993c817
commit a4cbb2f938
4 changed files with 23 additions and 34 deletions

View File

@ -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{

View File

@ -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;
}
}
}

View File

@ -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{
}

View File

@ -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{
}