mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 08:44:01 +00:00
Merge commit 'a34f3261c'
# Conflicts: # resources/vanilla # src/event/entity/EntityExplodeEvent.php # src/pocketmine/event/block/SignChangeEvent.php # src/utils/Utils.php
This commit is contained in:
commit
d840e8c4d4
@ -25,6 +25,7 @@ namespace pocketmine\event\entity;
|
||||
|
||||
use pocketmine\entity\Living;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\utils\Utils;
|
||||
|
||||
/**
|
||||
* @phpstan-extends EntityEvent<Living>
|
||||
@ -62,6 +63,7 @@ class EntityDeathEvent extends EntityEvent{
|
||||
* @param Item[] $drops
|
||||
*/
|
||||
public function setDrops(array $drops) : void{
|
||||
Utils::validateArrayValueType($drops, function(Item $_) : void{});
|
||||
$this->drops = $drops;
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,7 @@ use pocketmine\block\Block;
|
||||
use pocketmine\entity\Entity;
|
||||
use pocketmine\event\Cancellable;
|
||||
use pocketmine\event\CancellableTrait;
|
||||
use pocketmine\utils\Utils;
|
||||
use pocketmine\world\Position;
|
||||
|
||||
/**
|
||||
@ -70,6 +71,7 @@ class EntityExplodeEvent extends EntityEvent implements Cancellable{
|
||||
* @param Block[] $blocks
|
||||
*/
|
||||
public function setBlockList(array $blocks) : void{
|
||||
Utils::validateArrayValueType($blocks, function(Block $_) : void{});
|
||||
$this->blocks = $blocks;
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,8 @@ use pocketmine\event\CancellableTrait;
|
||||
use pocketmine\permission\PermissionManager;
|
||||
use pocketmine\player\Player;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\utils\Utils;
|
||||
use function array_values;
|
||||
use function spl_object_id;
|
||||
|
||||
/**
|
||||
@ -100,6 +102,7 @@ class PlayerChatEvent extends PlayerEvent implements Cancellable{
|
||||
* @param CommandSender[] $recipients
|
||||
*/
|
||||
public function setRecipients(array $recipients) : void{
|
||||
Utils::validateArrayValueType($recipients, function(CommandSender $_) : void{});
|
||||
$this->recipients = $recipients;
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ use pocketmine\player\Player;
|
||||
use pocketmine\plugin\Plugin;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\utils\Binary;
|
||||
use pocketmine\utils\Utils;
|
||||
use function chr;
|
||||
use function count;
|
||||
use function str_replace;
|
||||
@ -127,6 +128,7 @@ final class QueryInfo{
|
||||
* @param Plugin[] $plugins
|
||||
*/
|
||||
public function setPlugins(array $plugins) : void{
|
||||
Utils::validateArrayValueType($plugins, function(Plugin $_) : void{});
|
||||
$this->plugins = $plugins;
|
||||
$this->destroyCache();
|
||||
}
|
||||
@ -142,6 +144,7 @@ final class QueryInfo{
|
||||
* @param Player[] $players
|
||||
*/
|
||||
public function setPlayerList(array $players) : void{
|
||||
Utils::validateArrayValueType($players, function(Player $_) : void{});
|
||||
$this->players = $players;
|
||||
$this->destroyCache();
|
||||
}
|
||||
|
@ -501,6 +501,21 @@ class Utils{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @phpstan-template TMemberType
|
||||
* @phpstan-param array<mixed, TMemberType> $array
|
||||
* @phpstan-param \Closure(TMemberType) : void $validator
|
||||
*/
|
||||
public static function validateArrayValueType(array $array, \Closure $validator) : void{
|
||||
foreach($array as $k => $v){
|
||||
try{
|
||||
$validator($v);
|
||||
}catch(\TypeError $e){
|
||||
throw new \TypeError("Incorrect type of element at \"$k\": " . $e->getMessage(), 0, $e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function checkUTF8(string $string) : void{
|
||||
if(!mb_check_encoding($string, 'UTF-8')){
|
||||
throw new \InvalidArgumentException("Text must be valid UTF-8");
|
||||
|
@ -30,6 +30,11 @@ parameters:
|
||||
count: 1
|
||||
path: ../../../src/utils/Utils.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$ of closure expects TMemberType, TMemberType given\\.$#"
|
||||
count: 1
|
||||
path: ../../../src/utils/Utils.php
|
||||
|
||||
-
|
||||
message: "#^Call to function is_resource\\(\\) with resource will always evaluate to true\\.$#"
|
||||
count: 2
|
||||
|
Loading…
x
Reference in New Issue
Block a user