mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-11 14:05:35 +00:00
EventHandler code cleanup
This commit is contained in:
parent
ccdf587135
commit
2bdc8c400e
@ -34,54 +34,6 @@ abstract class BaseEvent{
|
|||||||
* Not doing so will deny the proper event initialization
|
* Not doing so will deny the proper event initialization
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected $eventName = null;
|
|
||||||
private $status = BaseEvent::NORMAL;
|
|
||||||
private $prioritySlot;
|
|
||||||
|
|
||||||
final public function getEventName(){
|
|
||||||
return $this->eventName !== null ? get_class($this) : $this->eventName;
|
|
||||||
}
|
|
||||||
|
|
||||||
final public function setPrioritySlot($slot){
|
|
||||||
$this->prioritySlot = (int) $slot;
|
|
||||||
}
|
|
||||||
|
|
||||||
final public function getPrioritySlot(){
|
|
||||||
return (int) $this->prioritySlot;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function isAllowed(){
|
|
||||||
return ($this->status & 0x7FFFFFFF) === BaseEvent::ALLOW;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setAllowed($forceAllow = false){
|
|
||||||
$this->status = BaseEvent::ALLOW | ($forceAllow === true ? BaseEvent::FORCE : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isCancelled(){
|
|
||||||
return ($this->status & 0x7FFFFFFF) === BaseEvent::DENY;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setCancelled($forceCancel = false){
|
|
||||||
if($this instanceof CancellableEvent){
|
|
||||||
$this->status = BaseEvent::DENY | ($forceCancel === true ? BaseEvent::FORCE : 0);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isNormal(){
|
|
||||||
return $this->status === BaseEvent::NORMAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setNormal(){
|
|
||||||
$this->status = BaseEvent::NORMAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isForced(){
|
|
||||||
return ($this->status & BaseEvent::FORCE) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function getHandlerList(){
|
public static function getHandlerList(){
|
||||||
return static::$handlers;
|
return static::$handlers;
|
||||||
}
|
}
|
||||||
@ -131,6 +83,57 @@ abstract class BaseEvent{
|
|||||||
}else{
|
}else{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
protected $eventName = null;
|
||||||
|
private $status = BaseEvent::NORMAL;
|
||||||
|
private $prioritySlot;
|
||||||
|
|
||||||
|
final public function getEventName(){
|
||||||
|
return $this->eventName !== null ? get_class($this) : $this->eventName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final public function setPrioritySlot($slot){
|
||||||
|
$this->prioritySlot = (int) $slot;
|
||||||
|
}
|
||||||
|
|
||||||
|
final public function getPrioritySlot(){
|
||||||
|
return (int) $this->prioritySlot;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function isAllowed(){
|
||||||
|
return ($this->status & 0x7FFFFFFF) === BaseEvent::ALLOW;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAllowed($forceAllow = false){
|
||||||
|
$this->status = BaseEvent::ALLOW | ($forceAllow === true ? BaseEvent::FORCE : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isCancelled(){
|
||||||
|
return ($this->status & 0x7FFFFFFF) === BaseEvent::DENY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCancelled($forceCancel = false){
|
||||||
|
if($this instanceof CancellableEvent){
|
||||||
|
$this->status = BaseEvent::DENY | ($forceCancel === true ? BaseEvent::FORCE : 0);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isNormal(){
|
||||||
|
return $this->status === BaseEvent::NORMAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setNormal(){
|
||||||
|
$this->status = BaseEvent::NORMAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isForced(){
|
||||||
|
return ($this->status & BaseEvent::FORCE) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -22,6 +22,9 @@
|
|||||||
abstract class EventHandler{
|
abstract class EventHandler{
|
||||||
|
|
||||||
public static function callEvent(BaseEvent $event){
|
public static function callEvent(BaseEvent $event){
|
||||||
|
if(count($event::$handlerPriority) === 0){
|
||||||
|
return BaseEvent::NORMAL;
|
||||||
|
}
|
||||||
foreach($event::$handlerPriority as $priority => $handlerList){
|
foreach($event::$handlerPriority as $priority => $handlerList){
|
||||||
if(count($handlerList) > 0){
|
if(count($handlerList) > 0){
|
||||||
$event->setPrioritySlot($priority);
|
$event->setPrioritySlot($priority);
|
||||||
@ -45,7 +48,6 @@ abstract class EventHandler{
|
|||||||
}else{
|
}else{
|
||||||
return BaseEvent::NORMAL;
|
return BaseEvent::NORMAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -20,10 +20,14 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Plugins that create events must use this class as the base
|
|
||||||
*/
|
|
||||||
|
|
||||||
abstract class PluginEvent extends BaseEvent{
|
abstract class PluginEvent extends BaseEvent{
|
||||||
|
private $plugin;
|
||||||
|
|
||||||
|
public function __construct(Plugin $plugin){
|
||||||
|
$this->plugin = $plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPlugin(){
|
||||||
|
return $this->plugin;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user