diff --git a/.travis.yml b/.travis.yml index 5eece2d4..4cac71a0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ sudo: true language: php php: - - 7.0 + - 7.2.1 before_script: - pecl install channel://pecl.php.net/pthreads-3.1.6 diff --git a/src/pocketmine/PocketMine.php b/src/pocketmine/PocketMine.php index 0955fe63..1408ed6c 100644 --- a/src/pocketmine/PocketMine.php +++ b/src/pocketmine/PocketMine.php @@ -88,6 +88,8 @@ function dummy(){ const CODENAME = "Wolf"; const TURANIC_API_VERSION = '2.0.0'; + const MIN_PHP_VERSION = "7.2.0"; + /* * Startup code. Do not look at it, it may harm you. * Most of them are hacks to fix date-related bugs, or basic functions used after this @@ -101,8 +103,8 @@ function dummy(){ @define('pocketmine\PATH', \getcwd() . DIRECTORY_SEPARATOR); } - if(version_compare("7.0.15", PHP_VERSION) > 0){ - echo "[CRITICAL] You must use PHP >= 7.0.15" . PHP_EOL; + if(version_compare(MIN_PHP_VERSION, PHP_VERSION) > 0){ + echo "[CRITICAL] You must use PHP >= " . MIN_PHP_VERSION . PHP_EOL; echo "[CRITICAL] Please use the installer provided on the homepage." . PHP_EOL; exit(1); } diff --git a/src/pocketmine/Thread.php b/src/pocketmine/Thread.php index 2602e6b9..00669422 100644 --- a/src/pocketmine/Thread.php +++ b/src/pocketmine/Thread.php @@ -63,7 +63,7 @@ public function registerClassLoader(){ * * @return bool */ - 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()){ @@ -93,9 +93,10 @@ public function quit(){ ThreadManager::getInstance()->remove($this); } - /** - * @return string - */ + /** + * @return string + * @throws \ReflectionException + */ public function getThreadName(){ return (new \ReflectionClass($this))->getShortName(); } diff --git a/src/pocketmine/Worker.php b/src/pocketmine/Worker.php index 5e3d07b5..b21bc891 100644 --- a/src/pocketmine/Worker.php +++ b/src/pocketmine/Worker.php @@ -64,7 +64,7 @@ public function registerClassLoader(){ * * @return bool */ - 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()){ @@ -98,10 +98,11 @@ public function quit(){ ThreadManager::getInstance()->remove($this); } - /** - * @return string - */ - public function getThreadName(){ + /** + * @return string + * @throws \ReflectionException + */ + public function getThreadName() : string{ return (new \ReflectionClass($this))->getShortName(); } } \ No newline at end of file diff --git a/src/pocketmine/entity/Human.php b/src/pocketmine/entity/Human.php index 6604de5e..fd206bff 100644 --- a/src/pocketmine/entity/Human.php +++ b/src/pocketmine/entity/Human.php @@ -306,7 +306,7 @@ public function getXpLevel() : int{ * * @param int $level */ - public function setXpLevel(int $level){ + public function setXpLevel(int $level) : void{ $this->attributeMap->getAttribute(Attribute::EXPERIENCE_LEVEL)->setValue($level); } @@ -316,7 +316,7 @@ public function setXpLevel(int $level){ * @param int $amount * @param bool $playSound */ - public function addXpLevels(int $amount, bool $playSound = true){ + public function addXpLevels(int $amount, bool $playSound = true) : void{ $oldLevel = $this->getXpLevel(); $this->setXpLevel($oldLevel + $amount); @@ -332,7 +332,7 @@ public function addXpLevels(int $amount, bool $playSound = true){ * Subtracts a number of XP levels from the player. * @param int $amount */ - public function subtractXpLevels(int $amount){ + public function subtractXpLevels(int $amount) : void{ $this->setXpLevel($this->getXpLevel() - $amount); } @@ -349,7 +349,7 @@ public function getXpProgress() : float{ * * @param float $progress */ - public function setXpProgress(float $progress){ + public function setXpProgress(float $progress) : void{ $this->attributeMap->getAttribute(Attribute::EXPERIENCE)->setValue($progress); } @@ -378,7 +378,7 @@ public function getCurrentTotalXp() : int{ * * @param int $amount */ - public function setCurrentTotalXp(int $amount){ + public function setCurrentTotalXp(int $amount) : void{ $newLevel = ExperienceUtils::getLevelFromXp($amount); $this->setXpLevel((int) $newLevel); @@ -392,7 +392,7 @@ public function setCurrentTotalXp(int $amount){ * @param int $amount * @param bool $playSound Whether to play level-up and XP gained sounds. */ - public function addXp(int $amount, bool $playSound = true){ + public function addXp(int $amount, bool $playSound = true) : void{ $this->totalXp += $amount; $oldLevel = $this->getXpLevel(); @@ -411,7 +411,7 @@ public function addXp(int $amount, bool $playSound = true){ } } - private function playLevelUpSound(int $newLevel){ + private function playLevelUpSound(int $newLevel) : void{ $volume = 0x10000000 * (min(30, $newLevel) / 5); //No idea why such odd numbers, but this works... $this->level->broadcastLevelSoundEvent($this, LevelSoundEventPacket::SOUND_LEVELUP, 1, (int) $volume); } @@ -420,7 +420,7 @@ private function playLevelUpSound(int $newLevel){ * Takes an amount of XP from the player, recalculating their XP level and progress. * @param int $amount */ - public function subtractXp(int $amount){ + public function subtractXp(int $amount) : void{ $this->addXp(-$amount); } @@ -430,7 +430,7 @@ public function subtractXp(int $amount){ * * @return int */ - public function getLifetimeTotalXp(){ + public function getLifetimeTotalXp() : int{ return $this->totalXp; } @@ -440,7 +440,7 @@ public function getLifetimeTotalXp(){ * * @param int $amount */ - public function setLifetimeTotalXp(int $amount){ + public function setLifetimeTotalXp(int $amount) : void{ if($amount < 0){ throw new \InvalidArgumentException("XP must be greater than 0"); } @@ -461,7 +461,7 @@ public function canPickupXp() : bool{ * * @param int $value */ - public function resetXpCooldown(int $value = 2){ + public function resetXpCooldown(int $value = 2) : void{ $this->xpCooldown = $value; } @@ -472,14 +472,14 @@ public function getXpDropAmount() : int{ /** * @return PlayerInventory */ - public function getInventory(){ + public function getInventory() : PlayerInventory{ return $this->inventory; } /** * @return EnderChestInventory */ - public function getEnderChestInventory(){ + public function getEnderChestInventory() : EnderChestInventory{ return $this->enderChestInventory; } diff --git a/src/pocketmine/network/mcpe/NetworkBinaryStream.php b/src/pocketmine/network/mcpe/NetworkBinaryStream.php index 16879881..cbae7937 100644 --- a/src/pocketmine/network/mcpe/NetworkBinaryStream.php +++ b/src/pocketmine/network/mcpe/NetworkBinaryStream.php @@ -39,7 +39,7 @@ public function getString() : string{ return $this->get($this->getUnsignedVarInt()); } - public function putString(string $v){ + public function putString(string $v) : void{ $this->putUnsignedVarInt(strlen($v)); $this->put($v); } @@ -54,7 +54,7 @@ public function getUUID() : UUID{ return new UUID($part0, $part1, $part2, $part3); } - public function putUUID(UUID $uuid){ + public function putUUID(UUID $uuid) : void{ $this->putLInt($uuid->getPart(1)); $this->putLInt($uuid->getPart(0)); $this->putLInt($uuid->getPart(3)); @@ -101,7 +101,7 @@ public function getSlot() : Item{ } - public function putSlot(Item $item){ + public function putSlot(Item $item) : void{ if($item->getId() === 0){ $this->putVarInt(0); @@ -181,7 +181,7 @@ public function getEntityMetadata(bool $types = true) : array{ * * @param array $metadata */ - public function putEntityMetadata(array $metadata){ + public function putEntityMetadata(array $metadata) : void{ $this->putUnsignedVarInt(count($metadata)); foreach($metadata as $key => $d){ $this->putUnsignedVarInt($key); //data key @@ -260,7 +260,7 @@ public function getAttributeList() : array{ * * @param Attribute[] ...$attributes */ - public function putAttributeList(Attribute ...$attributes){ + public function putAttributeList(Attribute ...$attributes) : void{ $this->putUnsignedVarInt(count($attributes)); foreach($attributes as $attribute){ $this->putLFloat($attribute->getMinValue()); @@ -284,7 +284,7 @@ public function getEntityUniqueId() : int{ * * @param int $eid */ - public function putEntityUniqueId(int $eid){ + public function putEntityUniqueId(int $eid) : void{ $this->putVarLong($eid); } @@ -301,7 +301,7 @@ public function getEntityRuntimeId() : int{ * * @param int $eid */ - public function putEntityRuntimeId(int $eid){ + public function putEntityRuntimeId(int $eid) : void{ $this->putUnsignedVarLong($eid); } @@ -325,7 +325,7 @@ public function getBlockPosition(&$x, &$y, &$z){ * @param int $y * @param int $z */ - public function putBlockPosition(int $x, int $y, int $z){ + public function putBlockPosition(int $x, int $y, int $z) : void{ $this->putVarInt($x); $this->putUnsignedVarInt($y); $this->putVarInt($z); @@ -351,7 +351,7 @@ public function getSignedBlockPosition(&$x, &$y, &$z){ * @param int $y * @param int $z */ - public function putSignedBlockPosition(int $x, int $y, int $z){ + public function putSignedBlockPosition(int $x, int $y, int $z) : void{ $this->putVarInt($x); $this->putVarInt($y); $this->putVarInt($z); @@ -378,7 +378,7 @@ public function getVector3() : Vector3{ * * @param Vector3|null $vector */ - public function putVector3Nullable($vector){ + public function putVector3Nullable(?Vector3 $vector) : void{ if($vector){ $this->putVector3($vector); }else{ @@ -394,7 +394,7 @@ public function putVector3Nullable($vector){ * * @param Vector3 $vector */ - public function putVector3(Vector3 $vector){ + public function putVector3(Vector3 $vector) : void{ $this->putLFloat($vector->x); $this->putLFloat($vector->y); $this->putLFloat($vector->z); @@ -404,7 +404,7 @@ public function getByteRotation() : float{ return (float) ($this->getByte() * (360 / 256)); } - public function putByteRotation(float $rotation){ + public function putByteRotation(float $rotation) : void{ $this->putByte((int) ($rotation / (360 / 256))); } @@ -445,7 +445,7 @@ public function getGameRules() : array{ * * @param array $rules */ - public function putGameRules(array $rules){ + public function putGameRules(array $rules) : void{ $this->putUnsignedVarInt(count($rules)); foreach($rules as $name => $rule){ $this->putString($name); @@ -481,7 +481,7 @@ protected function getEntityLink() : EntityLink{ /** * @param EntityLink $link */ - protected function putEntityLink(EntityLink $link){ + protected function putEntityLink(EntityLink $link) : void{ $this->putEntityUniqueId($link->fromEntityUniqueId); $this->putEntityUniqueId($link->toEntityUniqueId); $this->putByte($link->type); diff --git a/src/pocketmine/scheduler/AsyncWorker.php b/src/pocketmine/scheduler/AsyncWorker.php index 3e791d69..32d3e622 100644 --- a/src/pocketmine/scheduler/AsyncWorker.php +++ b/src/pocketmine/scheduler/AsyncWorker.php @@ -68,7 +68,7 @@ public function handleException(\Throwable $e){ /** * @return string */ - public function getThreadName(){ + public function getThreadName() : string{ return "Asynchronous Worker #" . $this->id; } diff --git a/src/pocketmine/utils/Terminal.php b/src/pocketmine/utils/Terminal.php index 5a8d8cb8..0508c1e9 100644 --- a/src/pocketmine/utils/Terminal.php +++ b/src/pocketmine/utils/Terminal.php @@ -57,13 +57,21 @@ abstract class Terminal { */ public static function hasFormattingCodes(){ if(self::$formattingCodes === null){ - $opts = getopt("", ["enable-ansi", "disable-ansi"]); - if(isset($opts["disable-ansi"])){ - self::$formattingCodes = false; - }else{ - self::$formattingCodes = ((Utils::getOS() !== "win" and getenv("TERM") != "" and (!function_exists("posix_ttyname") or !defined("STDOUT") or posix_ttyname(STDOUT) !== false)) or isset($opts["enable-ansi"])); - } - } + $opts = getopt("", ["enable-ansi", "disable-ansi"]); + if(isset($opts["disable-ansi"])){ + self::$formattingCodes = false; + }else{ + $stdout = fopen("php://stdout", "w"); + self::$formattingCodes = (isset($opts["enable-ansi"]) or ( //user explicitly told us to enable ANSI + stream_isatty($stdout) and //STDOUT isn't being piped + ( + getenv('TERM') !== false or //Console says it supports colours + (function_exists('sapi_windows_vt100_support') and sapi_windows_vt100_support($stdout)) //we're on windows and have vt100 support + ) + )); + fclose($stdout); + } + } return self::$formattingCodes; } diff --git a/src/raklib/server/RakLibServer.php b/src/raklib/server/RakLibServer.php index 48adf7ee..b59d58b3 100644 --- a/src/raklib/server/RakLibServer.php +++ b/src/raklib/server/RakLibServer.php @@ -202,7 +202,7 @@ public function cleanPath($path){ return str_replace(["\\", ".php", "phar://", str_replace(["\\", "phar://"], ["/", ""], $this->mainPath)], ["/", "", "", ""], $path); } - public function run(){ + public function run() : void{ try{ $this->loader->register(true); diff --git a/src/raklib/server/SessionManager.php b/src/raklib/server/SessionManager.php index 9730dcbf..ec48257d 100644 --- a/src/raklib/server/SessionManager.php +++ b/src/raklib/server/SessionManager.php @@ -419,12 +419,7 @@ protected static function addressHash(string $ip, int $port) : string{ return $ip . ":" . $port; } - /** - * @param InternetAddress $address - * - * @return Session|null - */ - public function getSession(InternetAddress $address){ + public function getSession(InternetAddress $address) : ?Session{ return $this->sessions[(string) $address] ?? null; } @@ -483,21 +478,11 @@ public function getID() : int{ return $this->server->getServerId(); } - /** - * @param int $id - * @param string $class - */ private function registerPacket(int $id, string $class){ $this->packetPool[$id] = new $class; } - /** - * @param int $id - * @param string $buffer - * - * @return Packet|null - */ - public function getPacketFromPool(int $id, string $buffer = ""){ + public function getPacketFromPool(int $id, string $buffer = "") : ?Packet{ $pk = $this->packetPool[$id]; if($pk !== null){ $pk = clone $pk; @@ -520,4 +505,4 @@ private function registerPackets(){ $this->registerPacket(UnconnectedPong::$ID, UnconnectedPong::class); $this->registerPacket(AdvertiseSystem::$ID, AdvertiseSystem::class); } -} +} \ No newline at end of file diff --git a/src/raklib/server/UDPServerSocket.php b/src/raklib/server/UDPServerSocket.php index bc965e45..f96e7f8c 100644 --- a/src/raklib/server/UDPServerSocket.php +++ b/src/raklib/server/UDPServerSocket.php @@ -55,24 +55,10 @@ public function close(){ socket_close($this->socket); } - /** - * @param string|null &$buffer - * @param string|null &$source - * @param int|null &$port - * - * @return int|bool - */ - public function readPacket(&$buffer, &$source, &$port){ + public function readPacket(?string &$buffer, ?string &$source, ?int &$port){ return socket_recvfrom($this->socket, $buffer, 65535, 0, $source, $port); } - /** - * @param string $buffer - * @param string $dest - * @param int $port - * - * @return int|bool - */ public function writePacket(string $buffer, string $dest, int $port){ return socket_sendto($this->socket, $buffer, strlen($buffer), 0, $dest, $port); } diff --git a/src/raklib/utils/InternetAddress.php b/src/raklib/utils/InternetAddress.php index e948ecfb..02ce9c2f 100644 --- a/src/raklib/utils/InternetAddress.php +++ b/src/raklib/utils/InternetAddress.php @@ -72,4 +72,4 @@ public function getVersion() : int{ public function __toString(){ return $this->ip . ":" . $this->port; } -} +} \ No newline at end of file diff --git a/start.cmd b/start.cmd index 38e5c0b2..cb7e5f15 100644 --- a/start.cmd +++ b/start.cmd @@ -32,5 +32,5 @@ if exist Turanic*.phar ( if exist bin\mintty.exe ( start "" bin\mintty.exe -o Columns=88 -o Rows=32 -o AllowBlinking=0 -o FontQuality=3 -o Font="Consolas" -o FontHeight=10 -o CursorType=0 -o CursorBlinks=1 -h error -t "Turanic" -w max %PHP_BINARY% %POCKETMINE_FILE% --enable-ansi %* ) else ( - %PHP_BINARY% -c bin\php %POCKETMINE_FILE% %* + %PHP_BINARY% -c bin\php %POCKETMINE_FILE% %* ) \ No newline at end of file diff --git a/start.ps1 b/start.ps1 new file mode 100644 index 00000000..86e5c42c --- /dev/null +++ b/start.ps1 @@ -0,0 +1,48 @@ +[CmdletBinding(PositionalBinding=$false)] +param ( + [string]$php = "", + [switch]$Loop = $false, + [string]$file = "", + [string][Parameter(ValueFromRemainingArguments)]$extraPocketMineArgs +) + +if($php -ne ""){ + $binary = $php +}elseif(Test-Path "bin\php\php.exe"){ + $env:PHPRC = "" + $binary = "bin\php\php.exe" +}else{ + $binary = "php" +} + +if($file -eq ""){ + if(Test-Path "PocketMine-MP.phar"){ + $file = "PocketMine-MP.phar" + }elseif(Test-Path "src\pocketmine\PocketMine.php"){ + $file = "src\pocketmine\PocketMine.php" + }else{ + echo "Couldn't find a valid PocketMine-MP installation" + pause + exit 1 + } +} + +function StartServer{ + $command = "powershell " + $binary + " " + $file + " --enable-ansi " + $extraPocketMineArgs + iex $command +} + +$loops = 0 + +StartServer + +while($Loop){ + if($loops -ne 0){ + echo ("Restarted " + $loops + " times") + } + $loops++ + echo "To escape the loop, press CTRL+C now. Otherwise, wait 5 seconds for the server to restart." + echo "" + Start-Sleep 5 + StartServer +} \ No newline at end of file