diff --git a/src/pocketmine/PocketMine.php b/src/pocketmine/PocketMine.php index 735b529af..0afd772f6 100644 --- a/src/pocketmine/PocketMine.php +++ b/src/pocketmine/PocketMine.php @@ -53,83 +53,89 @@ namespace pocketmine { * Enjoy it as much as I did writing it. I don't want to do it again. */ - if(version_compare(MIN_PHP_VERSION, PHP_VERSION) > 0){ - critical_error(\pocketmine\NAME . " requires PHP >= " . MIN_PHP_VERSION . ", but you have PHP " . PHP_VERSION . "."); - critical_error("Please refer to the installation instructions at http://pmmp.rtfd.io/en/rtfd/installation.html."); - exit(1); - } - - if(PHP_INT_SIZE < 8){ - critical_error("Running " . \pocketmine\NAME . " with 32-bit systems/PHP is no longer supported."); - critical_error("Please upgrade to a 64-bit system, or use a 64-bit PHP binary if this is a 64-bit system."); - critical_error("Please refer to the installation instructions at http://pmmp.rtfd.io/en/rtfd/installation.html."); - exit(1); - } - - /* Dependencies check */ - - $errors = 0; - - if(php_sapi_name() !== "cli"){ - critical_error("You must run " . \pocketmine\NAME . " using the CLI."); - ++$errors; - } - - $extensions = [ - "bcmath" => "BC Math", - "curl" => "cURL", - "ctype" => "ctype", - "date" => "Date", - "hash" => "Hash", - "json" => "JSON", - "mbstring" => "Multibyte String", - "openssl" => "OpenSSL", - "pcre" => "PCRE", - "phar" => "Phar", - "pthreads" => "pthreads", - "reflection" => "Reflection", - "sockets" => "Sockets", - "spl" => "SPL", - "yaml" => "YAML", - "zip" => "Zip", - "zlib" => "Zlib" - ]; - - foreach($extensions as $ext => $name){ - if(!extension_loaded($ext)){ - critical_error("Unable to find the $name ($ext) extension."); - ++$errors; + /** + * @return string[] + */ + function check_platform_dependencies(){ + if(version_compare(MIN_PHP_VERSION, PHP_VERSION) > 0){ + //If PHP version isn't high enough, anything below might break, so don't bother checking it. + return [ + \pocketmine\NAME . " requires PHP >= " . MIN_PHP_VERSION . ", but you have PHP " . PHP_VERSION . "." + ]; } - } - if(extension_loaded("pthreads")){ - $pthreads_version = phpversion("pthreads"); - if(substr_count($pthreads_version, ".") < 2){ - $pthreads_version = "0.$pthreads_version"; + $messages = []; + + if(PHP_INT_SIZE < 8){ + $messages[] = "Running " . \pocketmine\NAME . " with 32-bit systems/PHP is no longer supported. Please upgrade to a 64-bit system, or use a 64-bit PHP binary if this is a 64-bit system."; } - if(version_compare($pthreads_version, "3.1.7dev") < 0){ - critical_error("pthreads >= 3.1.7dev is required, while you have $pthreads_version."); - ++$errors; + + if(php_sapi_name() !== "cli"){ + $messages[] = "You must run " . \pocketmine\NAME . " using the CLI."; } - } - if(extension_loaded("leveldb")){ - $leveldb_version = phpversion("leveldb"); - if(version_compare($leveldb_version, "0.2.1") < 0){ - critical_error("php-leveldb >= 0.2.1 is required, while you have $leveldb_version"); - ++$errors; + $extensions = [ + "bcmath" => "BC Math", + "curl" => "cURL", + "ctype" => "ctype", + "date" => "Date", + "hash" => "Hash", + "json" => "JSON", + "mbstring" => "Multibyte String", + "openssl" => "OpenSSL", + "pcre" => "PCRE", + "phar" => "Phar", + "pthreads" => "pthreads", + "reflection" => "Reflection", + "sockets" => "Sockets", + "spl" => "SPL", + "yaml" => "YAML", + "zip" => "Zip", + "zlib" => "Zlib" + ]; + + foreach($extensions as $ext => $name){ + if(!extension_loaded($ext)){ + $messages[] = "Unable to find the $name ($ext) extension."; + } } + + if(extension_loaded("pthreads")){ + $pthreads_version = phpversion("pthreads"); + if(substr_count($pthreads_version, ".") < 2){ + $pthreads_version = "0.$pthreads_version"; + } + if(version_compare($pthreads_version, "3.1.7dev") < 0){ + $messages[] = "pthreads >= 3.1.7dev is required, while you have $pthreads_version."; + } + } + + if(extension_loaded("leveldb")){ + $leveldb_version = phpversion("leveldb"); + if(version_compare($leveldb_version, "0.2.1") < 0){ + $messages[] = "php-leveldb >= 0.2.1 is required, while you have $leveldb_version."; + } + } + + if(extension_loaded("pocketmine")){ + $messages[] = "The native PocketMine extension is no longer supported."; + } + + return $messages; } - if(extension_loaded("pocketmine")){ - critical_error("The native PocketMine extension is no longer supported."); - ++$errors; - } - - if($errors > 0){ + if(!empty($messages = check_platform_dependencies())){ + echo PHP_EOL; + $binary = version_compare(PHP_VERSION, "5.4") >= 0 ? PHP_BINARY : "unknown"; + critical_error("Selected PHP binary ($binary) does not satisfy some requirements."); + foreach($messages as $m){ + echo " - $m" . PHP_EOL; + } critical_error("Please recompile PHP with the needed configuration, or refer to the installation instructions at http://pmmp.rtfd.io/en/rtfd/installation.html."); + echo PHP_EOL; exit(1); } + unset($messages); error_reporting(-1); diff --git a/src/pocketmine/inventory/DoubleChestInventory.php b/src/pocketmine/inventory/DoubleChestInventory.php index 06578e19f..781892640 100644 --- a/src/pocketmine/inventory/DoubleChestInventory.php +++ b/src/pocketmine/inventory/DoubleChestInventory.php @@ -64,7 +64,12 @@ class DoubleChestInventory extends ChestInventory implements InventoryHolder{ } public function setItem(int $index, Item $item, bool $send = true) : bool{ - return $index < $this->left->getSize() ? $this->left->setItem($index, $item, $send) : $this->right->setItem($index - $this->left->getSize(), $item, $send); + $old = $this->getItem($index); + if($index < $this->left->getSize() ? $this->left->setItem($index, $item, $send) : $this->right->setItem($index - $this->left->getSize(), $item, $send)){ + $this->onSlotChange($index, $old, $send); + return true; + } + return false; } public function getContents(bool $includeEmpty = false) : array{ diff --git a/src/pocketmine/tile/Chest.php b/src/pocketmine/tile/Chest.php index 15ff38580..beb6d1214 100644 --- a/src/pocketmine/tile/Chest.php +++ b/src/pocketmine/tile/Chest.php @@ -113,10 +113,14 @@ class Chest extends Spawnable implements InventoryHolder, Container, Nameable{ $pair->checkPairing(); } if($this->doubleInventory === null){ - if(($pair->x + ($pair->z << 15)) > ($this->x + ($this->z << 15))){ //Order them correctly - $this->doubleInventory = new DoubleChestInventory($pair, $this); + if($pair->doubleInventory !== null){ + $this->doubleInventory = $pair->doubleInventory; }else{ - $this->doubleInventory = new DoubleChestInventory($this, $pair); + if(($pair->x + ($pair->z << 15)) > ($this->x + ($this->z << 15))){ //Order them correctly + $this->doubleInventory = new DoubleChestInventory($pair, $this); + }else{ + $this->doubleInventory = new DoubleChestInventory($this, $pair); + } } } }else{