diff --git a/composer.lock b/composer.lock index 6bfe05bd3..1786fc4ad 100644 --- a/composer.lock +++ b/composer.lock @@ -636,16 +636,16 @@ }, { "name": "phpstan/phpstan", - "version": "0.12.11", + "version": "0.12.14", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "ca5f2b7cf81c6d8fba74f9576970399c5817e03b" + "reference": "37bdd26a80235d0f9045b49f4151102b7831cbe2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/ca5f2b7cf81c6d8fba74f9576970399c5817e03b", - "reference": "ca5f2b7cf81c6d8fba74f9576970399c5817e03b", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/37bdd26a80235d0f9045b49f4151102b7831cbe2", + "reference": "37bdd26a80235d0f9045b49f4151102b7831cbe2", "shasum": "" }, "require": { @@ -671,7 +671,7 @@ "MIT" ], "description": "PHPStan - PHP Static Analysis Tool", - "time": "2020-02-16T14:00:29+00:00" + "time": "2020-03-02T22:29:43+00:00" }, { "name": "phpstan/phpstan-phpunit", diff --git a/src/CoreConstants.php b/src/CoreConstants.php index b67745e04..bf88306f1 100644 --- a/src/CoreConstants.php +++ b/src/CoreConstants.php @@ -23,6 +23,10 @@ declare(strict_types=1); namespace pocketmine; +use function define; +use function defined; +use function dirname; + // composer autoload doesn't use require_once and also pthreads can inherit things if(defined('pocketmine\_CORE_CONSTANTS_INCLUDED')){ return; diff --git a/src/GlobalConstants.php b/src/GlobalConstants.php index d3b4a9f9a..e32d07c04 100644 --- a/src/GlobalConstants.php +++ b/src/GlobalConstants.php @@ -19,6 +19,8 @@ * */ +declare(strict_types=1); + // composer autoload doesn't use require_once and also pthreads can inherit things if(defined('pocketmine\_GLOBAL_CONSTANTS_INCLUDED')){ return; diff --git a/src/VersionInfo.php b/src/VersionInfo.php index 20e7272b8..4a8f59fb7 100644 --- a/src/VersionInfo.php +++ b/src/VersionInfo.php @@ -23,6 +23,8 @@ declare(strict_types=1); namespace pocketmine; +use function defined; + // composer autoload doesn't use require_once and also pthreads can inherit things // TODO: drop this file and use a final class with constants if(defined('pocketmine\_VERSION_INFO_INCLUDED')){ diff --git a/src/entity/effect/Effect.php b/src/entity/effect/Effect.php index bcc347cf6..8b6e757e1 100644 --- a/src/entity/effect/Effect.php +++ b/src/entity/effect/Effect.php @@ -43,7 +43,7 @@ class Effect{ /** * @param int $id Effect ID as per Minecraft PE * @param string $name Translation key used for effect name - * @param Color $color + * @param Color $color Color of bubbles given by this effect * @param bool $isBad Whether the effect is harmful * @param bool $hasBubbles Whether the effect has potion bubbles. Some do not (e.g. Instant Damage has its own particles instead of bubbles) */ diff --git a/src/entity/object/ExperienceOrb.php b/src/entity/object/ExperienceOrb.php index a1059ca94..c87217795 100644 --- a/src/entity/object/ExperienceOrb.php +++ b/src/entity/object/ExperienceOrb.php @@ -39,14 +39,10 @@ class ExperienceOrb extends Entity{ public const TAG_VALUE_PC = "Value"; //short public const TAG_VALUE_PE = "experience value"; //int (WTF?) - /** - * Max distance an orb will follow a player across. - */ + /** Max distance an orb will follow a player across. */ public const MAX_TARGET_DISTANCE = 8.0; - /** - * Split sizes used for dropping experience orbs. - */ + /** Split sizes used for dropping experience orbs. */ public const ORB_SPLIT_SIZES = [2477, 1237, 617, 307, 149, 73, 37, 17, 7, 3, 1]; //This is indexed biggest to smallest so that we can return as soon as we found the biggest value. /** diff --git a/src/network/mcpe/protocol/AvailableCommandsPacket.php b/src/network/mcpe/protocol/AvailableCommandsPacket.php index d98ee2e01..70992f42a 100644 --- a/src/network/mcpe/protocol/AvailableCommandsPacket.php +++ b/src/network/mcpe/protocol/AvailableCommandsPacket.php @@ -77,9 +77,7 @@ class AvailableCommandsPacket extends DataPacket implements ClientboundPacket{ */ public const ARG_FLAG_ENUM = 0x200000; - /** - * This is used for /xp L. It can only be applied to integer parameters. - */ + /** This is used for /xp L. It can only be applied to integer parameters. */ public const ARG_FLAG_POSTFIX = 0x1000000; public const HARDCODED_ENUM_NAMES = [ diff --git a/src/network/mcpe/protocol/ProtocolInfo.php b/src/network/mcpe/protocol/ProtocolInfo.php index 8a120d142..f6541eef3 100644 --- a/src/network/mcpe/protocol/ProtocolInfo.php +++ b/src/network/mcpe/protocol/ProtocolInfo.php @@ -40,17 +40,11 @@ final class ProtocolInfo{ * This file is generated automatically, do not edit it manually. */ - /** - * Actual Minecraft: PE protocol version - */ + /** Actual Minecraft: PE protocol version */ public const CURRENT_PROTOCOL = 389; - /** - * Current Minecraft PE version reported by the server. This is usually the earliest currently supported version. - */ + /** Current Minecraft PE version reported by the server. This is usually the earliest currently supported version. */ public const MINECRAFT_VERSION = 'v1.14.0'; - /** - * Version number sent to clients in ping responses. - */ + /** Version number sent to clients in ping responses. */ public const MINECRAFT_VERSION_NETWORK = '1.14.0'; public const LOGIN_PACKET = 0x01; diff --git a/src/player/Player.php b/src/player/Player.php index 3a2e8fce1..71d3402fd 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -1601,7 +1601,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, $item = $this->inventory->getItemInHand(); $oldItem = clone $item; if($this->getWorld()->useBreakOn($pos, $item, $this, true)){ - if($this->hasFiniteResources() and !$item->equalsExact($oldItem)){ + if($this->hasFiniteResources() and !$item->equalsExact($oldItem) and $oldItem->equalsExact($this->inventory->getItemInHand())){ $this->inventory->setItemInHand($item); } $this->hungerManager->exhaust(0.025, PlayerExhaustEvent::CAUSE_MINING); @@ -1625,7 +1625,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, $item = $this->inventory->getItemInHand(); //this is a copy of the real item $oldItem = clone $item; if($this->getWorld()->useItemOn($pos, $item, $face, $clickOffset, $this, true)){ - if($this->hasFiniteResources() and !$item->equalsExact($oldItem)){ + if($this->hasFiniteResources() and !$item->equalsExact($oldItem) and $oldItem->equalsExact($this->inventory->getItemInHand())){ $this->inventory->setItemInHand($item); } return true; @@ -1694,7 +1694,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, if($this->isAlive()){ //reactive damage like thorns might cause us to be killed by attacking another mob, which //would mean we'd already have dropped the inventory by the time we reached here - if($heldItem->onAttackEntity($entity) and $this->hasFiniteResources()){ //always fire the hook, even if we are survival + if($heldItem->onAttackEntity($entity) and $this->hasFiniteResources() and $heldItem->equalsExact($this->inventory->getItemInHand())){ //always fire the hook, even if we are survival $this->inventory->setItemInHand($heldItem); } diff --git a/src/plugin/PluginDescription.php b/src/plugin/PluginDescription.php index c4d1d3f05..dd7a06835 100644 --- a/src/plugin/PluginDescription.php +++ b/src/plugin/PluginDescription.php @@ -53,6 +53,8 @@ class PluginDescription{ private $api; /** @var int[] */ private $compatibleMcpeProtocols = []; + /** @var string[] */ + private $compatibleOperatingSystems = []; /** * @var string[][] * @phpstan-var array> @@ -112,6 +114,7 @@ class PluginDescription{ $this->api = array_map("\strval", (array) ($plugin["api"] ?? [])); $this->compatibleMcpeProtocols = array_map("\intval", (array) ($plugin["mcpe-protocol"] ?? [])); + $this->compatibleOperatingSystems = array_map("\strval", (array) ($plugin["os"] ?? [])); if(isset($plugin["commands"]) and is_array($plugin["commands"])){ $this->commands = $plugin["commands"]; @@ -185,6 +188,13 @@ class PluginDescription{ return $this->compatibleMcpeProtocols; } + /** + * @return string[] + */ + public function getCompatibleOperatingSystems() : array{ + return $this->compatibleOperatingSystems; + } + /** * @return string[] */ diff --git a/src/plugin/PluginManager.php b/src/plugin/PluginManager.php index 5e031b741..ced8032b6 100644 --- a/src/plugin/PluginManager.php +++ b/src/plugin/PluginManager.php @@ -46,6 +46,7 @@ use function explode; use function file_exists; use function get_class; use function implode; +use function in_array; use function is_a; use function is_array; use function is_dir; @@ -251,6 +252,14 @@ class PluginManager{ continue; } + if(count($description->getCompatibleOperatingSystems()) > 0 and !in_array(Utils::getOS(), $description->getCompatibleOperatingSystems(), true)) { + $this->server->getLogger()->error($this->server->getLanguage()->translateString("pocketmine.plugin.loadError", [ + $name, + $this->server->getLanguage()->translateString("%pocketmine.plugin.incompatibleOS", [implode(", ", $description->getCompatibleOperatingSystems())]) + ])); + continue; + } + if(count($pluginMcpeProtocols = $description->getCompatibleMcpeProtocols()) > 0){ $serverMcpeProtocols = [ProtocolInfo::CURRENT_PROTOCOL]; if(count(array_intersect($pluginMcpeProtocols, $serverMcpeProtocols)) === 0){ diff --git a/src/thread/Thread.php b/src/thread/Thread.php index aec708e23..26c2037b2 100644 --- a/src/thread/Thread.php +++ b/src/thread/Thread.php @@ -22,6 +22,7 @@ declare(strict_types=1); namespace pocketmine\thread; +use const PTHREADS_INHERIT_ALL; /** * This class must be extended by all custom threading classes @@ -29,7 +30,7 @@ namespace pocketmine\thread; abstract class Thread extends \Thread{ use CommonThreadPartsTrait; - public function start(?int $options = \PTHREADS_INHERIT_ALL) : bool{ + public function start(?int $options = PTHREADS_INHERIT_ALL) : bool{ //this is intentionally not traitified ThreadManager::getInstance()->add($this); diff --git a/src/thread/Worker.php b/src/thread/Worker.php index 75b106a82..1d473e95f 100644 --- a/src/thread/Worker.php +++ b/src/thread/Worker.php @@ -22,6 +22,7 @@ declare(strict_types=1); namespace pocketmine\thread; +use const PTHREADS_INHERIT_ALL; /** * This class must be extended by all custom threading classes @@ -29,7 +30,7 @@ namespace pocketmine\thread; abstract class Worker extends \Worker{ use CommonThreadPartsTrait; - public function start(?int $options = \PTHREADS_INHERIT_ALL) : bool{ + public function start(?int $options = PTHREADS_INHERIT_ALL) : bool{ //this is intentionally not traitified ThreadManager::getInstance()->add($this); diff --git a/src/world/format/Chunk.php b/src/world/format/Chunk.php index 82aa8bde2..c1ab0db60 100644 --- a/src/world/format/Chunk.php +++ b/src/world/format/Chunk.php @@ -159,7 +159,7 @@ class Chunk{ * Returns the internal ID of the blockstate at the given coordinates. * * @param int $x 0-15 - * @param int $y + * @param int $y 0-255 * @param int $z 0-15 * * @return int bitmap, (id << 4) | meta @@ -180,7 +180,7 @@ class Chunk{ * Returns the sky light level at the specified chunk block coordinates * * @param int $x 0-15 - * @param int $y + * @param int $y 0-255 * @param int $z 0-15 * * @return int 0-15 @@ -193,7 +193,7 @@ class Chunk{ * Sets the sky light level at the specified chunk block coordinates * * @param int $x 0-15 - * @param int $y + * @param int $y 0-255 * @param int $z 0-15 * @param int $level 0-15 */ @@ -211,7 +211,7 @@ class Chunk{ * Returns the block light level at the specified chunk block coordinates * * @param int $x 0-15 - * @param int $y 0-15 + * @param int $y 0-255 * @param int $z 0-15 * * @return int 0-15 @@ -224,7 +224,7 @@ class Chunk{ * Sets the block light level at the specified chunk block coordinates * * @param int $x 0-15 - * @param int $y 0-15 + * @param int $y 0-255 * @param int $z 0-15 * @param int $level 0-15 */ @@ -452,7 +452,7 @@ class Chunk{ * Returns the tile at the specified chunk block coordinates, or null if no tile exists. * * @param int $x 0-15 - * @param int $y + * @param int $y 0-255 * @param int $z 0-15 */ public function getTile(int $x, int $y, int $z) : ?Tile{ @@ -630,7 +630,7 @@ class Chunk{ * Hashes the given chunk block coordinates into a single integer. * * @param int $x 0-15 - * @param int $y + * @param int $y 0-255 * @param int $z 0-15 */ public static function blockHash(int $x, int $y, int $z) : int{