Merge branch 'stable' into minor-next

This commit is contained in:
Dylan K. Taylor
2024-11-25 14:32:30 +00:00
67 changed files with 339 additions and 130 deletions

View File

@ -695,6 +695,7 @@ class InventoryManager{
/**
* @param EnchantingOption[] $options
* @phpstan-param list<EnchantingOption> $options
*/
public function syncEnchantingTableOptions(array $options) : void{
$protocolOptions = [];

View File

@ -1092,7 +1092,7 @@ class NetworkSession{
public function syncAvailableCommands() : void{
$commandData = [];
foreach($this->server->getCommandMap()->getCommands() as $name => $command){
foreach($this->server->getCommandMap()->getCommands() as $command){
if(isset($commandData[$command->getLabel()]) || $command->getLabel() === "help" || !$command->testPermissionSilent($this->player)){
continue;
}

View File

@ -53,7 +53,6 @@ final class StandardPacketBroadcaster implements PacketBroadcaster{
$compressors = [];
/** @var NetworkSession[][] $targetsByCompressor */
$targetsByCompressor = [];
foreach($recipients as $recipient){
//TODO: different compressors might be compatible, it might not be necessary to split them up by object

View File

@ -78,7 +78,10 @@ class ChunkCache implements ChunkListener{
}
}
/** @var CompressBatchPromise[] */
/**
* @var CompressBatchPromise[]
* @phpstan-var array<int, CompressBatchPromise>
*/
private array $caches = [];
private int $hits = 0;

View File

@ -28,6 +28,7 @@ use pocketmine\nbt\LittleEndianNbtSerializer;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\Tag;
use pocketmine\nbt\TreeRoot;
use pocketmine\utils\Utils;
use function count;
use function ksort;
use const SORT_STRING;
@ -43,6 +44,7 @@ final class BlockStateDictionaryEntry{
/**
* @param Tag[] $stateProperties
* @phpstan-param array<string, Tag> $stateProperties
*/
public function __construct(
private string $stateName,
@ -79,6 +81,7 @@ final class BlockStateDictionaryEntry{
/**
* @param Tag[] $properties
* @phpstan-param array<string, Tag> $properties
*/
public static function encodeStateProperties(array $properties) : string{
if(count($properties) === 0){
@ -87,7 +90,7 @@ final class BlockStateDictionaryEntry{
//TODO: make a more efficient encoding - NBT will do for now, but it's not very compact
ksort($properties, SORT_STRING);
$tag = new CompoundTag();
foreach($properties as $k => $v){
foreach(Utils::stringifyKeys($properties) as $k => $v){
$tag->setTag($k, $v);
}
return (new LittleEndianNbtSerializer())->write(new TreeRoot($tag));

View File

@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\convert;
use pocketmine\network\mcpe\protocol\serializer\ItemTypeDictionary;
use pocketmine\network\mcpe\protocol\types\ItemTypeEntry;
use pocketmine\utils\AssumptionFailedError;
use pocketmine\utils\Utils;
use function is_array;
use function is_bool;
use function is_int;
@ -41,7 +42,7 @@ final class ItemTypeDictionaryFromDataHelper{
}
$params = [];
foreach($table as $name => $entry){
foreach(Utils::promoteKeys($table) as $name => $entry){
if(!is_array($entry) || !is_string($name) || !isset($entry["component_based"], $entry["runtime_id"]) || !is_bool($entry["component_based"]) || !is_int($entry["runtime_id"])){
throw new AssumptionFailedError("Invalid item list format");
}

View File

@ -251,7 +251,7 @@ class InGamePacketHandler extends PacketHandler{
if(count($blockActions) > 100){
throw new PacketHandlingException("Too many block actions in PlayerAuthInputPacket");
}
foreach($blockActions as $k => $blockAction){
foreach(Utils::promoteKeys($blockActions) as $k => $blockAction){
$actionHandled = false;
if($blockAction instanceof PlayerBlockActionStopBreak){
$actionHandled = $this->handlePlayerActionFromData($blockAction->getActionType(), new BlockPosition(0, 0, 0), Facing::DOWN);

View File

@ -54,6 +54,7 @@ use pocketmine\network\mcpe\protocol\types\inventory\stackresponse\ItemStackResp
use pocketmine\network\mcpe\protocol\types\inventory\UIInventorySlotOffset;
use pocketmine\player\Player;
use pocketmine\utils\AssumptionFailedError;
use pocketmine\utils\Utils;
use function array_key_first;
use function count;
use function spl_object_id;
@ -370,7 +371,7 @@ class ItemStackRequestExecutor{
* @throws ItemStackRequestProcessException
*/
public function generateInventoryTransaction() : InventoryTransaction{
foreach($this->request->getActions() as $k => $action){
foreach(Utils::promoteKeys($this->request->getActions()) as $k => $action){
try{
$this->processItemStackRequestAction($action);
}catch(ItemStackRequestProcessException $e){

View File

@ -150,7 +150,7 @@ class LoginPacketHandler extends PacketHandler{
protected function fetchAuthData(JwtChain $chain) : AuthenticationData{
/** @var AuthenticationData|null $extraData */
$extraData = null;
foreach($chain->chain as $k => $jwt){
foreach($chain->chain as $jwt){
//validate every chain element
try{
[, $claims, ] = JwtUtils::parse($jwt);