From d7a35a530220b002b404a835ef9412544cef8fb8 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 2 May 2019 14:00:28 +0100 Subject: [PATCH 1/3] Entity: fixed motion not being initialized when `Motion` NBT tag is missing fixes CA 2355485 --- src/pocketmine/entity/Entity.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index e551ee2857..a87296ed27 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -593,6 +593,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ throw new \InvalidStateException("Cannot create entities in unloaded chunks"); } + $this->motion = new Vector3(0, 0, 0); if($this->namedtag->hasTag("Motion", ListTag::class)){ /** @var float[] $motion */ $motion = $this->namedtag->getListTag("Motion")->getAllValues(); From 3878f58847af23f62a7fc4402f4c9e8c4ebf0b70 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 2 May 2019 14:22:01 +0100 Subject: [PATCH 2/3] Level: fixed crash when time overflows this can be triggered by a plugin setting time to PHP_INT_MAX fixes CA 2346977 --- src/pocketmine/level/Level.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 4834377cd1..e70baf6f04 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -112,6 +112,8 @@ use function trim; use const INT32_MAX; use const INT32_MIN; use const M_PI; +use const PHP_INT_MAX; +use const PHP_INT_MIN; #include @@ -762,7 +764,7 @@ class Level implements ChunkManager, Metadatable{ */ public function sendTime(Player ...$targets){ $pk = new SetTimePacket(); - $pk->time = $this->time; + $pk->time = $this->time & 0xffffffff; //avoid overflowing the field, since the packet uses an int32 $this->server->broadcastPacket(count($targets) > 0 ? $targets : $this->players, $pk); } @@ -790,7 +792,12 @@ class Level implements ChunkManager, Metadatable{ protected function actuallyDoTick(int $currentTick) : void{ if(!$this->stopTime){ - $this->time++; + //this simulates an overflow, as would happen in any language which doesn't do stupid things to var types + if($this->time === PHP_INT_MAX){ + $this->time = PHP_INT_MIN; + }else{ + $this->time++; + } } $this->sunAnglePercentage = $this->computeSunAnglePercentage(); //Sun angle depends on the current time From 13ea984b1267989065eceebefd32a56f13c660df Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 2 May 2019 15:02:10 +0100 Subject: [PATCH 3/3] Server: setup world things at a more appropriate time closes #2859 this also fixes reported headaches attempting to override generators before world load. --- src/pocketmine/Server.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index c5911d8b86..22619b57fe 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -1692,6 +1692,12 @@ class Server{ Item::initCreativeItems(); Biome::init(); + LevelProviderManager::init(); + if(extension_loaded("leveldb")){ + $this->logger->debug($this->getLanguage()->translateString("pocketmine.debug.enable")); + } + GeneratorManager::registerDefaultGenerators(); + $this->craftingManager = new CraftingManager(); $this->resourceManager = new ResourcePackManager($this->getDataPath() . "resource_packs" . DIRECTORY_SEPARATOR, $this->logger); @@ -1713,13 +1719,6 @@ class Server{ $this->network->registerInterface(new RakLibInterface($this)); - LevelProviderManager::init(); - if(extension_loaded("leveldb")){ - $this->logger->debug($this->getLanguage()->translateString("pocketmine.debug.enable")); - } - - GeneratorManager::registerDefaultGenerators(); - foreach((array) $this->getProperty("worlds", []) as $name => $options){ if($options === null){ $options = [];