mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 16:00:20 +00:00
Apply union types in some places (BC breaks)
This commit is contained in:
parent
23ae0c7cac
commit
3b6ff3c42b
@ -87,10 +87,7 @@ class SignText{
|
||||
return $this->lines;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|string $index
|
||||
*/
|
||||
private function checkLineIndex($index) : void{
|
||||
private function checkLineIndex(int|string $index) : void{
|
||||
if(!is_int($index)){
|
||||
throw new \InvalidArgumentException("Index must be an integer");
|
||||
}
|
||||
|
@ -57,10 +57,7 @@ class HandlerList{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RegisteredListener|Listener|Plugin $object
|
||||
*/
|
||||
public function unregister($object) : void{
|
||||
public function unregister(RegisteredListener|Plugin|Listener $object) : void{
|
||||
if($object instanceof Plugin || $object instanceof Listener){
|
||||
foreach($this->handlerSlots as $priority => $list){
|
||||
foreach($list as $hash => $listener){
|
||||
@ -71,7 +68,7 @@ class HandlerList{
|
||||
}
|
||||
}
|
||||
}
|
||||
}elseif($object instanceof RegisteredListener){
|
||||
}else{
|
||||
if(isset($this->handlerSlots[$object->getPriority()][spl_object_id($object)])){
|
||||
unset($this->handlerSlots[$object->getPriority()][spl_object_id($object)]);
|
||||
}
|
||||
|
@ -40,10 +40,8 @@ class HandlerListManager{
|
||||
/**
|
||||
* Unregisters all the listeners
|
||||
* If a Plugin or Listener is passed, all the listeners with that object will be removed
|
||||
*
|
||||
* @param Plugin|Listener|RegisteredListener|null $object
|
||||
*/
|
||||
public function unregisterAll($object = null) : void{
|
||||
public function unregisterAll(RegisteredListener|Plugin|Listener|null $object = null) : void{
|
||||
if($object instanceof Listener || $object instanceof Plugin || $object instanceof RegisteredListener){
|
||||
foreach($this->allLists as $h){
|
||||
$h->unregister($object);
|
||||
|
@ -35,32 +35,26 @@ interface Permissible{
|
||||
*
|
||||
* @internal
|
||||
* @see Permissible::addAttachment() for normal permission assignments
|
||||
* @param Permission|string $name
|
||||
*/
|
||||
public function setBasePermission($name, bool $grant) : void;
|
||||
public function setBasePermission(Permission|string $name, bool $grant) : void;
|
||||
|
||||
/**
|
||||
* Unsets a baseline permission previously set. If it wasn't already set, this will have no effect.
|
||||
* Note that this might have different results than setting the permission to false.
|
||||
*
|
||||
* @internal
|
||||
* @param Permission|string $name
|
||||
*/
|
||||
public function unsetBasePermission($name) : void;
|
||||
public function unsetBasePermission(Permission|string $name) : void;
|
||||
|
||||
/**
|
||||
* Checks if this instance has a permission overridden
|
||||
*
|
||||
* @param string|Permission $name
|
||||
*/
|
||||
public function isPermissionSet($name) : bool;
|
||||
public function isPermissionSet(Permission|string $name) : bool;
|
||||
|
||||
/**
|
||||
* Returns the permission value if overridden, or the default value if not
|
||||
*
|
||||
* @param string|Permission $name
|
||||
*/
|
||||
public function hasPermission($name) : bool;
|
||||
public function hasPermission(Permission|string $name) : bool;
|
||||
|
||||
public function addAttachment(Plugin $plugin, ?string $name = null, ?bool $value = null) : PermissionAttachment;
|
||||
|
||||
|
@ -31,31 +31,19 @@ trait PermissibleDelegateTrait{
|
||||
/** @var Permissible */
|
||||
private $perm;
|
||||
|
||||
/**
|
||||
* @param Permission|string $name
|
||||
*/
|
||||
public function setBasePermission($name, bool $value) : void{
|
||||
$this->perm->setBasePermission($name, $value);
|
||||
public function setBasePermission(Permission|string $name, bool $grant) : void{
|
||||
$this->perm->setBasePermission($name, $grant);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Permission|string $name
|
||||
*/
|
||||
public function unsetBasePermission($name) : void{
|
||||
public function unsetBasePermission(Permission|string $name) : void{
|
||||
$this->perm->unsetBasePermission($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Permission|string $name
|
||||
*/
|
||||
public function isPermissionSet($name) : bool{
|
||||
public function isPermissionSet(Permission|string $name) : bool{
|
||||
return $this->perm->isPermissionSet($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Permission|string $name
|
||||
*/
|
||||
public function hasPermission($name) : bool{
|
||||
public function hasPermission(Permission|string $name) : bool{
|
||||
return $this->perm->hasPermission($name);
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ class PermissibleInternal implements Permissible{
|
||||
$this->recalculatePermissions();
|
||||
}
|
||||
|
||||
public function setBasePermission($name, bool $grant) : void{
|
||||
public function setBasePermission(Permission|string $name, bool $grant) : void{
|
||||
if($name instanceof Permission){
|
||||
$name = $name->getName();
|
||||
}
|
||||
@ -77,22 +77,16 @@ class PermissibleInternal implements Permissible{
|
||||
$this->recalculatePermissions();
|
||||
}
|
||||
|
||||
public function unsetBasePermission($name) : void{
|
||||
public function unsetBasePermission(Permission|string $name) : void{
|
||||
unset($this->rootPermissions[$name instanceof Permission ? $name->getName() : $name]);
|
||||
$this->recalculatePermissions();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Permission|string $name
|
||||
*/
|
||||
public function isPermissionSet($name) : bool{
|
||||
public function isPermissionSet(Permission|string $name) : bool{
|
||||
return isset($this->permissions[$name instanceof Permission ? $name->getName() : $name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Permission|string $name
|
||||
*/
|
||||
public function hasPermission($name) : bool{
|
||||
public function hasPermission(Permission|string $name) : bool{
|
||||
if($name instanceof Permission){
|
||||
$name = $name->getName();
|
||||
}
|
||||
|
@ -96,10 +96,7 @@ class PermissionAttachment{
|
||||
$this->recalculatePermissibles();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|Permission $name
|
||||
*/
|
||||
public function setPermission($name, bool $value) : void{
|
||||
public function setPermission(Permission|string $name, bool $value) : void{
|
||||
$name = $name instanceof Permission ? $name->getName() : $name;
|
||||
if(isset($this->permissions[$name])){
|
||||
if($this->permissions[$name] === $value){
|
||||
@ -120,10 +117,7 @@ class PermissionAttachment{
|
||||
$this->recalculatePermissibles();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|Permission $name
|
||||
*/
|
||||
public function unsetPermission($name) : void{
|
||||
public function unsetPermission(Permission|string $name) : void{
|
||||
$name = $name instanceof Permission ? $name->getName() : $name;
|
||||
if(isset($this->permissions[$name])){
|
||||
unset($this->permissions[$name]);
|
||||
|
@ -56,10 +56,7 @@ class PermissionManager{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|Permission $permission
|
||||
*/
|
||||
public function removePermission($permission) : void{
|
||||
public function removePermission(Permission|string $permission) : void{
|
||||
if($permission instanceof Permission){
|
||||
unset($this->permissions[$permission->getName()]);
|
||||
}else{
|
||||
|
@ -54,11 +54,9 @@ class PermissionParser{
|
||||
];
|
||||
|
||||
/**
|
||||
* @param bool|string $value
|
||||
*
|
||||
* @throws PermissionParserException
|
||||
*/
|
||||
public static function defaultFromString($value) : string{
|
||||
public static function defaultFromString(bool|string $value) : string{
|
||||
if(is_bool($value)){
|
||||
if($value){
|
||||
return "true";
|
||||
|
@ -85,7 +85,7 @@ class PluginDescription{
|
||||
/**
|
||||
* @param string|mixed[] $yamlString
|
||||
*/
|
||||
public function __construct($yamlString){
|
||||
public function __construct(array|string $yamlString){
|
||||
if(is_string($yamlString)){
|
||||
$map = yaml_parse($yamlString);
|
||||
if($map === false){
|
||||
|
@ -40,22 +40,12 @@ class ThreadManager extends \Volatile{
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Worker|Thread $thread
|
||||
*/
|
||||
public function add($thread) : void{
|
||||
if($thread instanceof Thread || $thread instanceof Worker){
|
||||
$this[spl_object_id($thread)] = $thread;
|
||||
}
|
||||
public function add(Worker|Thread $thread) : void{
|
||||
$this[spl_object_id($thread)] = $thread;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Worker|Thread $thread
|
||||
*/
|
||||
public function remove($thread) : void{
|
||||
if($thread instanceof Thread || $thread instanceof Worker){
|
||||
unset($this[spl_object_id($thread)]);
|
||||
}
|
||||
public function remove(Worker|Thread $thread) : void{
|
||||
unset($this[spl_object_id($thread)]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -169,7 +169,7 @@ class Internet{
|
||||
* @phpstan-param TErrorVar $err
|
||||
* @phpstan-param-out TErrorVar|string $err
|
||||
*/
|
||||
public static function postURL(string $page, $args, int $timeout = 10, array $extraHeaders = [], &$err = null) : ?InternetRequestResult{
|
||||
public static function postURL(string $page, array|string $args, int $timeout = 10, array $extraHeaders = [], &$err = null) : ?InternetRequestResult{
|
||||
try{
|
||||
return self::simpleCurl($page, $timeout, $extraHeaders, [
|
||||
CURLOPT_POST => 1,
|
||||
@ -185,7 +185,7 @@ class Internet{
|
||||
* General cURL shorthand function.
|
||||
* NOTE: This is a blocking operation and can take a significant amount of time. It is inadvisable to use this method on the main thread.
|
||||
*
|
||||
* @param float|int $timeout The maximum connect timeout and timeout in seconds, correct to ms.
|
||||
* @param float $timeout The maximum connect timeout and timeout in seconds, correct to ms.
|
||||
* @param string[] $extraHeaders extra headers to send as a plain string array
|
||||
* @param array $extraOpts extra CURLOPT_* to set as an [opt => value] map
|
||||
* @param \Closure|null $onSuccess function to be called if there is no error. Accepts a resource argument as the cURL handle.
|
||||
@ -195,7 +195,7 @@ class Internet{
|
||||
*
|
||||
* @throws InternetException if a cURL error occurs
|
||||
*/
|
||||
public static function simpleCurl(string $page, $timeout = 10, array $extraHeaders = [], array $extraOpts = [], ?\Closure $onSuccess = null) : InternetRequestResult{
|
||||
public static function simpleCurl(string $page, float $timeout = 10, array $extraHeaders = [], array $extraOpts = [], ?\Closure $onSuccess = null) : InternetRequestResult{
|
||||
if(!self::$online){
|
||||
throw new InternetException("Cannot execute web request while offline");
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ final class Process{
|
||||
*
|
||||
* @return int process exit code
|
||||
*/
|
||||
public static function execute(string $command, string &$stdout = null, string &$stderr = null) : int{
|
||||
public static function execute(string $command, ?string &$stdout = null, ?string &$stderr = null) : int{
|
||||
$process = proc_open($command, [
|
||||
["pipe", "r"],
|
||||
["pipe", "w"],
|
||||
|
Loading…
x
Reference in New Issue
Block a user