Merge branch 'stable' into next-minor

This commit is contained in:
Dylan K. Taylor 2020-05-17 10:03:17 +01:00
commit 8c0d441a13
12 changed files with 105 additions and 13 deletions

View File

@ -1397,7 +1397,7 @@ class Server{
Network::$BATCH_THRESHOLD = -1; Network::$BATCH_THRESHOLD = -1;
} }
$this->networkCompressionLevel = $this->getProperty("network.compression-level", 7); $this->networkCompressionLevel = (int) $this->getProperty("network.compression-level", 7);
if($this->networkCompressionLevel < 1 or $this->networkCompressionLevel > 9){ if($this->networkCompressionLevel < 1 or $this->networkCompressionLevel > 9){
$this->logger->warning("Invalid network compression level $this->networkCompressionLevel set, setting to default 7"); $this->logger->warning("Invalid network compression level $this->networkCompressionLevel set, setting to default 7");
$this->networkCompressionLevel = 7; $this->networkCompressionLevel = 7;

View File

@ -23,6 +23,11 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\ItemIds;
use function mt_rand;
class CocoaBlock extends Transparent{ class CocoaBlock extends Transparent{
protected $id = self::COCOA_BLOCK; protected $id = self::COCOA_BLOCK;
@ -48,4 +53,14 @@ class CocoaBlock extends Transparent{
public function isAffectedBySilkTouch() : bool{ public function isAffectedBySilkTouch() : bool{
return false; return false;
} }
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get(ItemIds::DYE, 3, ($this->meta >> 2) === 2 ? mt_rand(2, 3) : 1)
];
}
public function getPickedItem() : Item{
return ItemFactory::get(ItemIds::DYE, 3);
}
} }

View File

@ -1931,7 +1931,12 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
} }
public function spawnTo(Player $player) : void{ public function spawnTo(Player $player) : void{
if(!isset($this->hasSpawned[$player->getLoaderId()]) and $this->chunk !== null and isset($player->usedChunks[Level::chunkHash($this->chunk->getX(), $this->chunk->getZ())])){ if(
!isset($this->hasSpawned[$player->getLoaderId()]) and
$this->chunk !== null and
isset($player->usedChunks[$chunkHash = Level::chunkHash($this->chunk->getX(), $this->chunk->getZ())]) and
$player->usedChunks[$chunkHash] === true
){
$this->hasSpawned[$player->getLoaderId()] = $player; $this->hasSpawned[$player->getLoaderId()] = $player;
$this->sendSpawnPacket($player); $this->sendSpawnPacket($player);

View File

@ -1909,7 +1909,7 @@ class Level implements ChunkManager, Metadatable{
if($player !== null){ if($player !== null){
$ev = new BlockPlaceEvent($player, $hand, $blockReplace, $blockClicked, $item); $ev = new BlockPlaceEvent($player, $hand, $blockReplace, $blockClicked, $item);
if($this->checkSpawnProtection($player, $blockClicked)){ if($this->checkSpawnProtection($player, $blockReplace)){
$ev->setCancelled(); $ev->setCancelled();
} }

View File

@ -34,17 +34,26 @@ abstract class LightUpdate{
/** @var ChunkManager */ /** @var ChunkManager */
protected $level; protected $level;
/** @var int[][] blockhash => [x, y, z, new light level] */ /**
* @var int[][] blockhash => [x, y, z, new light level]
* @phpstan-var array<int, array{int, int, int, int}>
*/
protected $updateNodes = []; protected $updateNodes = [];
/** @var \SplQueue */ /** @var \SplQueue */
protected $spreadQueue; protected $spreadQueue;
/** @var bool[] */ /**
* @var true[]
* @phpstan-var array<int, true>
*/
protected $spreadVisited = []; protected $spreadVisited = [];
/** @var \SplQueue */ /** @var \SplQueue */
protected $removalQueue; protected $removalQueue;
/** @var bool[] */ /**
* @var true[]
* @phpstan-var array<int, true>
*/
protected $removalVisited = []; protected $removalVisited = [];
/** @var SubChunkIteratorManager */ /** @var SubChunkIteratorManager */
protected $subChunkHandler; protected $subChunkHandler;

View File

@ -28,6 +28,7 @@ namespace pocketmine\network\mcpe\protocol;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\NetworkSession;
use pocketmine\network\mcpe\protocol\types\DeviceOS;
use pocketmine\network\mcpe\protocol\types\EntityLink; use pocketmine\network\mcpe\protocol\types\EntityLink;
use pocketmine\utils\UUID; use pocketmine\utils\UUID;
use function count; use function count;
@ -84,7 +85,7 @@ class AddPlayerPacket extends DataPacket{
/** @var string */ /** @var string */
public $deviceId = ""; //TODO: fill player's device ID (???) public $deviceId = ""; //TODO: fill player's device ID (???)
/** @var int */ /** @var int */
public $buildPlatform = -1; public $buildPlatform = DeviceOS::UNKNOWN;
protected function decodePayload(){ protected function decodePayload(){
$this->uuid = $this->getUUID(); $this->uuid = $this->getUUID();

View File

@ -0,0 +1,44 @@
<?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/
*
*
*/
declare(strict_types=1);
namespace pocketmine\network\mcpe\protocol\types;
final class DeviceOS{
public const UNKNOWN = -1;
public const ANDROID = 1;
public const IOS = 2;
public const OSX = 3;
public const AMAZON = 4;
public const GEAR_VR = 5;
public const HOLOLENS = 6;
public const WINDOWS_10 = 7;
public const WIN32 = 8;
public const DEDICATED = 9;
public const TVOS = 10;
public const PLAYSTATION = 11;
public const NINTENDO = 12;
public const XBOX = 13;
public const WINDOWS_PHONE = 14;
}

View File

@ -40,7 +40,7 @@ class PlayerListEntry{
/** @var string */ /** @var string */
public $platformChatId = ""; public $platformChatId = "";
/** @var int */ /** @var int */
public $buildPlatform = -1; public $buildPlatform = DeviceOS::UNKNOWN;
/** @var bool */ /** @var bool */
public $isTeacher = false; public $isTeacher = false;
/** @var bool */ /** @var bool */

View File

@ -49,11 +49,11 @@ class SkinImage{
public static function fromLegacy(string $data) : SkinImage{ public static function fromLegacy(string $data) : SkinImage{
switch(strlen($data)){ switch(strlen($data)){
case 64 * 32 * 4: case 64 * 32 * 4:
return new self(64, 32, $data); return new self(32, 64, $data);
case 64 * 64 * 4: case 64 * 64 * 4:
return new self(64, 64, $data); return new self(64, 64, $data);
case 128 * 64 * 4: case 128 * 64 * 4:
return new self(128, 64, $data); return new self(64, 128, $data);
case 128 * 128 * 4: case 128 * 128 * 4:
return new self(128, 128, $data); return new self(128, 128, $data);
} }

View File

@ -116,7 +116,7 @@ class PermissionManager{
$this->defaultPerms[$permission->getName()] = $permission; $this->defaultPerms[$permission->getName()] = $permission;
$this->dirtyPermissibles(false); $this->dirtyPermissibles(false);
} }
Timings::$permissionDefaultTimer->startTiming(); Timings::$permissionDefaultTimer->stopTiming();
} }
private function dirtyPermissibles(bool $op) : void{ private function dirtyPermissibles(bool $op) : void{

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\resourcepacks; namespace pocketmine\resourcepacks;
use Ahc\Json\Comment as CommentedJsonDecoder; use Ahc\Json\Comment as CommentedJsonDecoder;
use function assert;
use function count; use function count;
use function fclose; use function fclose;
use function feof; use function feof;
@ -35,6 +36,8 @@ use function fseek;
use function gettype; use function gettype;
use function hash_file; use function hash_file;
use function implode; use function implode;
use function preg_match;
use function strlen;
class ZippedResourcePack implements ResourcePack{ class ZippedResourcePack implements ResourcePack{
@ -85,7 +88,22 @@ class ZippedResourcePack implements ResourcePack{
} }
if(($manifestData = $archive->getFromName("manifest.json")) === false){ if(($manifestData = $archive->getFromName("manifest.json")) === false){
if($archive->locateName("pack_manifest.json") !== false){ $manifestPath = null;
$manifestIdx = null;
for($i = 0; $i < $archive->numFiles; ++$i){
$name = $archive->getNameIndex($i);
if(
($manifestPath === null or strlen($name) < strlen($manifestPath)) and
preg_match('#.*/manifest.json$#', $name) === 1
){
$manifestPath = $name;
$manifestIdx = $i;
}
}
if($manifestIdx !== null){
$manifestData = $archive->getFromIndex($manifestIdx);
assert($manifestData !== false);
}elseif($archive->locateName("pack_manifest.json") !== false){
throw new ResourcePackException("Unsupported old pack format"); throw new ResourcePackException("Unsupported old pack format");
}else{ }else{
throw new ResourcePackException("manifest.json not found in the archive root"); throw new ResourcePackException("manifest.json not found in the archive root");

View File

@ -36,7 +36,7 @@ class TaskScheduler{
/** @var bool */ /** @var bool */
private $enabled = true; private $enabled = true;
/** @var ReversePriorityQueue<Task> */ /** @var ReversePriorityQueue<TaskHandler> */
protected $queue; protected $queue;
/** @var TaskHandler[] */ /** @var TaskHandler[] */