From ddfe828445b15a8c6ecdff5ab6808eb586111a74 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 31 Aug 2017 20:27:05 +0100 Subject: [PATCH 1/8] Require PHP 7.2, bump PocketMine-MP version to 1.7dev --- .travis.yml | 12 ++++++++++-- src/pocketmine/PocketMine.php | 12 ++++++------ src/pocketmine/Thread.php | 2 +- src/pocketmine/Worker.php | 2 +- .../object/{Object.php => PopulatorObject.php} | 2 +- 5 files changed, 19 insertions(+), 11 deletions(-) rename src/pocketmine/level/generator/object/{Object.php => PopulatorObject.php} (96%) diff --git a/.travis.yml b/.travis.yml index cd6d65dad0..93cc404cad 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,20 @@ language: php php: - - 7.0 + - 7.2 before_script: - - pecl install channel://pecl.php.net/pthreads-3.1.6 +# - pecl install channel://pecl.php.net/pthreads-3.1.6 - pecl install channel://pecl.php.net/weakref-0.3.3 - echo | pecl install channel://pecl.php.net/yaml-2.0.0 + - git clone https://github.com/krakjoe/pthreads.git --depth=1 + - cd pthreads + - phpize + - ./configure + - make + - make install + - cd .. + - echo "extension=pthreads.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini script: - ./tests/travis.sh diff --git a/src/pocketmine/PocketMine.php b/src/pocketmine/PocketMine.php index 18d83f72b2..71d647fda0 100644 --- a/src/pocketmine/PocketMine.php +++ b/src/pocketmine/PocketMine.php @@ -78,9 +78,9 @@ namespace pocketmine { use pocketmine\wizard\SetupWizard; use raklib\RakLib; - const VERSION = "1.6.2dev"; + const VERSION = "1.7dev"; const API_VERSION = "3.0.0-ALPHA7"; - const CODENAME = "Unleashed"; + const CODENAME = "[REDACTED]"; /* * Startup code. Do not look at it, it may harm you. @@ -89,8 +89,8 @@ namespace pocketmine { * Enjoy it as much as I did writing it. I don't want to do it again. */ - if(version_compare("7.0", PHP_VERSION) > 0 or version_compare("7.1", PHP_VERSION) <= 0){ - echo "[CRITICAL] You must use PHP 7.0" . PHP_EOL; + if(version_compare("7.2", PHP_VERSION) > 0){ + echo "[CRITICAL] You must use PHP >= 7.2" . PHP_EOL; echo "[CRITICAL] Please use the installer provided on the homepage." . PHP_EOL; exit(1); } @@ -431,8 +431,8 @@ namespace pocketmine { if(substr_count($pthreads_version, ".") < 2){ $pthreads_version = "0.$pthreads_version"; } - if(version_compare($pthreads_version, "3.1.5") < 0){ - $logger->critical("pthreads >= 3.1.5 is required, while you have $pthreads_version."); + if(version_compare($pthreads_version, "3.1.7-dev") < 0){ + $logger->critical("pthreads >= 3.1.7-dev is required, while you have $pthreads_version."); ++$errors; } diff --git a/src/pocketmine/Thread.php b/src/pocketmine/Thread.php index 1f1be497cf..b6a4d2b62b 100644 --- a/src/pocketmine/Thread.php +++ b/src/pocketmine/Thread.php @@ -60,7 +60,7 @@ abstract class Thread extends \Thread{ } } - public function start(int $options = PTHREADS_INHERIT_ALL){ + public function start(?int $options = \PTHREADS_INHERIT_ALL){ ThreadManager::getInstance()->add($this); if(!$this->isRunning() and !$this->isJoined() and !$this->isTerminated()){ diff --git a/src/pocketmine/Worker.php b/src/pocketmine/Worker.php index 85e3dedf9a..f9ade50716 100644 --- a/src/pocketmine/Worker.php +++ b/src/pocketmine/Worker.php @@ -61,7 +61,7 @@ abstract class Worker extends \Worker{ } } - public function start(int $options = PTHREADS_INHERIT_ALL){ + public function start(?int $options = \PTHREADS_INHERIT_ALL){ ThreadManager::getInstance()->add($this); if(!$this->isRunning() and !$this->isJoined() and !$this->isTerminated()){ diff --git a/src/pocketmine/level/generator/object/Object.php b/src/pocketmine/level/generator/object/PopulatorObject.php similarity index 96% rename from src/pocketmine/level/generator/object/Object.php rename to src/pocketmine/level/generator/object/PopulatorObject.php index 0abf2a3554..8714c0d89d 100644 --- a/src/pocketmine/level/generator/object/Object.php +++ b/src/pocketmine/level/generator/object/PopulatorObject.php @@ -27,6 +27,6 @@ declare(strict_types=1); namespace pocketmine\level\generator\object; -abstract class Object{ +abstract class PopulatorObject{ } \ No newline at end of file From 8caabd32670dd4a3d9bd915f86bdf5fe3923b346 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 31 Aug 2017 21:04:36 +0100 Subject: [PATCH 2/8] Check for existence of ChunkUtils extension --- src/pocketmine/level/format/io/ChunkUtils.php | 142 +++++++++--------- 1 file changed, 72 insertions(+), 70 deletions(-) diff --git a/src/pocketmine/level/format/io/ChunkUtils.php b/src/pocketmine/level/format/io/ChunkUtils.php index e9e35e8ce0..3a02ba04fa 100644 --- a/src/pocketmine/level/format/io/ChunkUtils.php +++ b/src/pocketmine/level/format/io/ChunkUtils.php @@ -23,84 +23,86 @@ declare(strict_types=1); namespace pocketmine\level\format\io; -class ChunkUtils{ +if(!extension_loaded('pocketmine_chunkutils')){ + class ChunkUtils{ - /** - * Re-orders a byte array (YZX -> XZY and vice versa) - * - * @param string $array length 4096 - * - * @return string length 4096 - */ - final public static function reorderByteArray(string $array) : string{ - $result = str_repeat("\x00", 4096); - if($array !== $result){ - $i = 0; - for($x = 0; $x < 16; ++$x){ - $zM = $x + 256; - for($z = $x; $z < $zM; $z += 16){ - $yM = $z + 4096; - for($y = $z; $y < $yM; $y += 256){ - $result{$i} = $array{$y}; - ++$i; - } - } - } - } - - return $result; - } - - /** - * Re-orders a nibble array (YZX -> XZY and vice versa) - * - * @param string $array length 2048 - * @param string $commonValue length 1 common value to fill the default array with and to expect, may improve sort time - * - * @return string length 2048 - */ - final public static function reorderNibbleArray(string $array, string $commonValue = "\x00") : string{ - $result = str_repeat($commonValue, 2048); - - if($array !== $result){ - $i = 0; - for($x = 0; $x < 8; ++$x){ - for($z = 0; $z < 16; ++$z){ - $zx = (($z << 3) | $x); - for($y = 0; $y < 8; ++$y){ - $j = (($y << 8) | $zx); - $j80 = ($j | 0x80); - if($array{$j} === $commonValue and $array{$j80} === $commonValue){ - //values are already filled - }else{ - $i1 = ord($array{$j}); - $i2 = ord($array{$j80}); - $result{$i} = chr(($i2 << 4) | ($i1 & 0x0f)); - $result{$i | 0x80} = chr(($i1 >> 4) | ($i2 & 0xf0)); + /** + * Re-orders a byte array (YZX -> XZY and vice versa) + * + * @param string $array length 4096 + * + * @return string length 4096 + */ + final public static function reorderByteArray(string $array) : string{ + $result = str_repeat("\x00", 4096); + if($array !== $result){ + $i = 0; + for($x = 0; $x < 16; ++$x){ + $zM = $x + 256; + for($z = $x; $z < $zM; $z += 16){ + $yM = $z + 4096; + for($y = $z; $y < $yM; $y += 256){ + $result{$i} = $array{$y}; + ++$i; } - $i++; } } - $i += 128; } + + return $result; } - return $result; - } + /** + * Re-orders a nibble array (YZX -> XZY and vice versa) + * + * @param string $array length 2048 + * @param string $commonValue length 1 common value to fill the default array with and to expect, may improve sort time + * + * @return string length 2048 + */ + final public static function reorderNibbleArray(string $array, string $commonValue = "\x00") : string{ + $result = str_repeat($commonValue, 2048); - /** - * Converts pre-MCPE-1.0 biome color array to biome ID array. - * - * @param int[] $array of biome color values - * - * @return string - */ - public static function convertBiomeColors(array $array) : string{ - $result = str_repeat("\x00", 256); - foreach($array as $i => $color){ - $result{$i} = chr(($color >> 24) & 0xff); + if($array !== $result){ + $i = 0; + for($x = 0; $x < 8; ++$x){ + for($z = 0; $z < 16; ++$z){ + $zx = (($z << 3) | $x); + for($y = 0; $y < 8; ++$y){ + $j = (($y << 8) | $zx); + $j80 = ($j | 0x80); + if($array{$j} === $commonValue and $array{$j80} === $commonValue){ + //values are already filled + }else{ + $i1 = ord($array{$j}); + $i2 = ord($array{$j80}); + $result{$i} = chr(($i2 << 4) | ($i1 & 0x0f)); + $result{$i | 0x80} = chr(($i1 >> 4) | ($i2 & 0xf0)); + } + $i++; + } + } + $i += 128; + } + } + + return $result; } - return $result; - } + /** + * Converts pre-MCPE-1.0 biome color array to biome ID array. + * + * @param int[] $array of biome color values + * + * @return string + */ + public static function convertBiomeColors(array $array) : string{ + $result = str_repeat("\x00", 256); + foreach($array as $i => $color){ + $result{$i} = chr(($color >> 24) & 0xff); + } + return $result; + } + + } } \ No newline at end of file From 16aeb0ac857d3c89db166c18e846f558675cef6c Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 31 Aug 2017 21:12:45 +0100 Subject: [PATCH 3/8] Update .travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 93cc404cad..3a2aaaef8d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ php: before_script: # - pecl install channel://pecl.php.net/pthreads-3.1.6 - pecl install channel://pecl.php.net/weakref-0.3.3 - - echo | pecl install channel://pecl.php.net/yaml-2.0.0 + - echo | pecl install channel://pecl.php.net/yaml-2.0.2 - git clone https://github.com/krakjoe/pthreads.git --depth=1 - cd pthreads - phpize From 00e4fff259ef6b9059f09d04f9f6ff9c848b8475 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 1 Sep 2017 20:05:04 +0100 Subject: [PATCH 4/8] Fixed Item fromString() crash on PHP 7.2 --- src/pocketmine/item/ItemFactory.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/pocketmine/item/ItemFactory.php b/src/pocketmine/item/ItemFactory.php index 79f059a91d..aacbb3c41c 100644 --- a/src/pocketmine/item/ItemFactory.php +++ b/src/pocketmine/item/ItemFactory.php @@ -338,11 +338,13 @@ class ItemFactory{ if(defined(Item::class . "::" . strtoupper($b[0]))){ $item = self::get(constant(Item::class . "::" . strtoupper($b[0])), $meta); - if($item->getId() === Item::AIR and strtoupper($b[0]) !== "AIR"){ - $item = self::get($b[0] & 0xFFFF, $meta); + if($item->getId() === Item::AIR and strtoupper($b[0]) !== "AIR" and is_numeric($b[0])){ + $item = self::get(((int) $b[0]) & 0xFFFF, $meta); } + }elseif(is_numeric($b[0])){ + $item = self::get(((int) $b[0]) & 0xFFFF, $meta); }else{ - $item = self::get($b[0] & 0xFFFF, $meta); + $item = self::get(Item::AIR, 0, 0); } return $item; From 85ff23646139ad55789a9734f08036ba464522c6 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 7 Sep 2017 17:27:07 +0100 Subject: [PATCH 5/8] Fixed formatting issues in Travis test script --- tests/travis.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/travis.sh b/tests/travis.sh index 92469586da..2498e0c67a 100755 --- a/tests/travis.sh +++ b/tests/travis.sh @@ -27,10 +27,10 @@ rm -rf ./plugins/PocketMine-DevTools echo -e "version\nmakeserver\nstop\n" | "$PHP_BINARY" src/pocketmine/PocketMine.php --no-wizard --disable-ansi --disable-readline --debug.level=2 if ls plugins/DevTools/PocketMine*.phar >/dev/null 2>&1; then - echo Server phar created successfully. + echo Server phar created successfully. else - echo No phar created! - exit 1 + echo No phar created! + exit 1 fi cp -r tests/plugins/PocketMine-TesterPlugin ./plugins @@ -44,9 +44,9 @@ fi result=$(echo "$output" | grep 'Finished' | grep -v 'PASS') if [ "$result" != "" ]; then - echo "$result" - echo Some tests did not complete successfully, changing build status to failed - exit 1 + echo "$result" + echo Some tests did not complete successfully, changing build status to failed + exit 1 else - echo All tests passed + echo All tests passed fi From 8c363cb5719165a78a1fd683c62eb6394a46a23e Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 9 Sep 2017 18:44:18 +0100 Subject: [PATCH 6/8] Added capability to specify arguments to PocketMine.php when running start.ps1 Example: .\start.ps1 --disable-ansi --debug.level=2 --- start.ps1 | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/start.ps1 b/start.ps1 index ef3c1221f5..9c0cf318f4 100644 --- a/start.ps1 +++ b/start.ps1 @@ -1,6 +1,8 @@ -param ( +[CmdletBinding(PositionalBinding=$false)] +param ( [string]$php = "", - [switch]$Loop = $false + [switch]$Loop = $false, + [string][Parameter(ValueFromRemainingArguments)]$extraPocketMineArgs ) if($php -ne ""){ @@ -23,7 +25,7 @@ if(Test-Path "PocketMine-MP.phar"){ } function StartServer{ - $command = "powershell " + $binary + " " + $file + " --enable-ansi" + $command = "powershell " + $binary + " " + $file + " --enable-ansi " + $extraPocketMineArgs iex $command } From 8761256246ba12129e0526c0057ed9323d177cd4 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 9 Sep 2017 19:21:32 +0100 Subject: [PATCH 7/8] Be more clear about WHY not to use source installs in production --- src/pocketmine/PocketMine.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/PocketMine.php b/src/pocketmine/PocketMine.php index b039ef2d43..f5b1734469 100644 --- a/src/pocketmine/PocketMine.php +++ b/src/pocketmine/PocketMine.php @@ -534,7 +534,7 @@ namespace pocketmine { if(\Phar::running(true) === ""){ - $logger->warning("Non-packaged PocketMine-MP installation detected, do not use on production."); + $logger->warning("Non-packaged PocketMine-MP installation detected. Consider using a phar in production for better performance."); } ThreadManager::init(); From 7f5d8cc900a8e10ec87facf77b823fa51f500e14 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 9 Sep 2017 19:27:26 +0100 Subject: [PATCH 8/8] Always log stack traces regardless of whether log-debug is enabled --- src/pocketmine/utils/MainLogger.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pocketmine/utils/MainLogger.php b/src/pocketmine/utils/MainLogger.php index 686f68344d..8e97d61041 100644 --- a/src/pocketmine/utils/MainLogger.php +++ b/src/pocketmine/utils/MainLogger.php @@ -105,8 +105,8 @@ class MainLogger extends \AttachableThreadedLogger{ $this->send($message, \LogLevel::INFO, "INFO", TextFormat::WHITE); } - public function debug($message){ - if($this->logDebug === false){ + public function debug($message, bool $force = false){ + if($this->logDebug === false and !$force){ return; } $this->send($message, \LogLevel::DEBUG, "DEBUG", TextFormat::GRAY); @@ -156,7 +156,7 @@ class MainLogger extends \AttachableThreadedLogger{ $errfile = \pocketmine\cleanPath($errfile); $this->log($type, get_class($e) . ": \"$errstr\" ($errno) in \"$errfile\" at line $errline"); foreach(\pocketmine\getTrace(0, $trace) as $i => $line){ - $this->debug($line); + $this->debug($line, true); } }