mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 11:39:43 +00:00
support php8019 and some cleanup (by @D-aHTuCT)
This commit is contained in:
parent
cf0f9df267
commit
b60f0877e1
376 changed files with 6528 additions and 13472 deletions
|
|
@ -1,30 +1,12 @@
|
|||
<?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 BaseEvent{
|
||||
|
||||
const ALLOW = 0;
|
||||
const DENY = 1;
|
||||
const NORMAL = 2;
|
||||
const FORCE = 0x80000000;
|
||||
|
||||
|
||||
/**
|
||||
* Any callable event must declare the static variables
|
||||
*
|
||||
|
|
@ -33,68 +15,24 @@ abstract class BaseEvent{
|
|||
*
|
||||
* 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(){
|
||||
return static::$handlers;
|
||||
}
|
||||
|
||||
|
||||
public static function getPriorityList(){
|
||||
return static::$handlerPriority;
|
||||
}
|
||||
|
||||
|
||||
public static function unregisterAll(){
|
||||
static::$handlers = array();
|
||||
static::$handlerPriority = array();
|
||||
static::$handlers = [];
|
||||
static::$handlerPriority = [];
|
||||
}
|
||||
|
||||
|
||||
public static function register(callable $handler, $priority = EventPriority::NORMAL){
|
||||
if($priority < EventPriority::MONITOR or $priority > EventPriority::LOWEST){
|
||||
return false;
|
||||
|
|
@ -105,14 +43,14 @@ abstract class BaseEvent{
|
|||
}else{
|
||||
static::$handlers[$identifier] = $handler;
|
||||
if(!isset(static::$handlerPriority[(int) $priority])){
|
||||
static::$handlerPriority[(int) $priority] = array();
|
||||
static::$handlerPriority[(int) $priority] = [];
|
||||
krsort(static::$handlerPriority);
|
||||
}
|
||||
static::$handlerPriority[(int) $priority][$identifier] = $handler;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function unregister(callable $handler, $priority = EventPriority::NORMAL){
|
||||
$identifier = Utils::getCallableIdentifier($handler);
|
||||
if(isset(static::$handlers[$identifier])){
|
||||
|
|
@ -131,6 +69,48 @@ abstract class BaseEvent{
|
|||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
final public function getEventName(){
|
||||
return $this->eventName !== null ? get_class($this) : $this->eventName;
|
||||
}
|
||||
|
||||
final public function getPrioritySlot(){
|
||||
return (int) $this->prioritySlot;
|
||||
}
|
||||
|
||||
final public function setPrioritySlot($slot){
|
||||
$this->prioritySlot = (int) $slot;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue