From 6e8631347d64c0c7d929454ff91c19ffdc047a5a Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 1 Sep 2017 17:57:40 +0100 Subject: [PATCH 1/5] Added capability to specify compatible protocol versions in plugin.yml (#1247) Protocol-dependent plugins may specify the `mcpe-protocol` attribute in plugin.yml to disallow plugin loading when the protocol changes. --- src/pocketmine/lang/locale | 2 +- src/pocketmine/plugin/PluginDescription.php | 12 ++++++++++++ src/pocketmine/plugin/PluginManager.php | 19 +++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/pocketmine/lang/locale b/src/pocketmine/lang/locale index 2ab4d9172..eac602e8b 160000 --- a/src/pocketmine/lang/locale +++ b/src/pocketmine/lang/locale @@ -1 +1 @@ -Subproject commit 2ab4d9172eba05cb7c6b8c98639db2ba9e60472c +Subproject commit eac602e8bc084fbaf3bc133129d6c8e4dc517c52 diff --git a/src/pocketmine/plugin/PluginDescription.php b/src/pocketmine/plugin/PluginDescription.php index dc7be00e8..006e01e06 100644 --- a/src/pocketmine/plugin/PluginDescription.php +++ b/src/pocketmine/plugin/PluginDescription.php @@ -23,12 +23,15 @@ declare(strict_types=1); namespace pocketmine\plugin; +use pocketmine\network\mcpe\protocol\ProtocolInfo; use pocketmine\permission\Permission; class PluginDescription{ private $name; private $main; private $api; + /** @var int[] */ + private $compatibleMcpeProtocols = []; private $extensions = []; private $depend = []; private $softDepend = []; @@ -76,6 +79,8 @@ class PluginDescription{ throw new PluginException("Invalid PluginDescription main, cannot start within the PocketMine namespace"); } + $this->compatibleMcpeProtocols = array_map("intval", (array) ($plugin["mcpe-protocol"] ?? [])); + if(isset($plugin["commands"]) and is_array($plugin["commands"])){ $this->commands = $plugin["commands"]; } @@ -147,6 +152,13 @@ class PluginDescription{ return $this->api; } + /** + * @return int[] + */ + public function getCompatibleMcpeProtocols() : array{ + return $this->compatibleMcpeProtocols; + } + /** * @return string[] */ diff --git a/src/pocketmine/plugin/PluginManager.php b/src/pocketmine/plugin/PluginManager.php index 17511cec0..0e926898d 100644 --- a/src/pocketmine/plugin/PluginManager.php +++ b/src/pocketmine/plugin/PluginManager.php @@ -32,6 +32,7 @@ use pocketmine\event\HandlerList; use pocketmine\event\Listener; use pocketmine\event\Timings; use pocketmine\event\TimingsHandler; +use pocketmine\network\mcpe\protocol\ProtocolInfo; use pocketmine\permission\Permissible; use pocketmine\permission\Permission; use pocketmine\Server; @@ -258,6 +259,24 @@ class PluginManager{ continue; } + if(count($pluginMcpeProtocols = $description->getCompatibleMcpeProtocols()) > 0){ + $serverMcpeProtocols = [ProtocolInfo::CURRENT_PROTOCOL]; + if(count(array_intersect($pluginMcpeProtocols, $serverMcpeProtocols)) === 0){ + $this->server->getLogger()->error($this->server->getLanguage()->translateString( + "pocketmine.plugin.loadError", + [ + $name, + $this->server->getLanguage()->translateString( + "%pocketmine.plugin.incompatibleProtocol", + [ + implode(", ", $pluginMcpeProtocols) + ]) + ] + )); + continue; + } + } + $plugins[$name] = $file; $softDependencies[$name] = $description->getSoftDepend(); From 506118e28f9107e695ad348225f9e61aa212da79 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 1 Sep 2017 18:13:07 +0100 Subject: [PATCH 2/5] Fixed exception thrown when plugins specify API version like 3.0 instead of 3.0.0 This could only be seen in a build with a non-suffixed API version, for example 3.0.0. When attempting to load plugins which specify API like 3.0 the server would raise errors. --- src/pocketmine/plugin/PluginManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/plugin/PluginManager.php b/src/pocketmine/plugin/PluginManager.php index 0e926898d..4dd93d3e0 100644 --- a/src/pocketmine/plugin/PluginManager.php +++ b/src/pocketmine/plugin/PluginManager.php @@ -238,7 +238,7 @@ class PluginManager{ continue; } - $pluginNumbers = array_map("intval", explode(".", $pluginApi[0])); + $pluginNumbers = array_map("intval", array_pad(explode(".", $pluginApi[0]), 3, "0")); //plugins might specify API like "3.0" or "3" $serverNumbers = array_map("intval", explode(".", $serverApi[0])); if($pluginNumbers[0] !== $serverNumbers[0]){ //Completely different API version From 517609dc2e5852299b2e54d05fa9e13e89931b42 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 1 Sep 2017 18:32:37 +0100 Subject: [PATCH 3/5] Cleaned up plugin property reading --- src/pocketmine/plugin/PluginDescription.php | 27 +++++++++------------ 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/pocketmine/plugin/PluginDescription.php b/src/pocketmine/plugin/PluginDescription.php index 006e01e06..9f63b2156 100644 --- a/src/pocketmine/plugin/PluginDescription.php +++ b/src/pocketmine/plugin/PluginDescription.php @@ -74,11 +74,11 @@ class PluginDescription{ $this->name = str_replace(" ", "_", $this->name); $this->version = (string) $plugin["version"]; $this->main = $plugin["main"]; - $this->api = array_map(function($v){ return (string) $v; }, !is_array($plugin["api"]) ? [$plugin["api"]] : $plugin["api"]); if(stripos($this->main, "pocketmine\\") === 0){ throw new PluginException("Invalid PluginDescription main, cannot start within the PocketMine namespace"); } + $this->api = array_map("strval", (array) $plugin["api"] ?? []); $this->compatibleMcpeProtocols = array_map("intval", (array) ($plugin["mcpe-protocol"] ?? [])); if(isset($plugin["commands"]) and is_array($plugin["commands"])){ @@ -99,22 +99,17 @@ class PluginDescription{ $this->extensions[$k] = is_array($v) ? $v : [$v]; } } - if(isset($plugin["softdepend"])){ - $this->softDepend = (array) $plugin["softdepend"]; - } - if(isset($plugin["loadbefore"])){ - $this->loadBefore = (array) $plugin["loadbefore"]; - } - if(isset($plugin["website"])){ - $this->website = $plugin["website"]; - } - if(isset($plugin["description"])){ - $this->description = $plugin["description"]; - } - if(isset($plugin["prefix"])){ - $this->prefix = $plugin["prefix"]; - } + $this->softDepend = (array) ($plugin["softdepend"] ?? $this->softDepend); + + $this->loadBefore = (array) ($plugin["loadbefore"] ?? $this->loadBefore); + + $this->website = (string) ($plugin["website"] ?? $this->website); + + $this->description = (string) ($plugin["description"] ?? $this->description); + + $this->prefix = (string) ($plugin["prefix"] ?? $this->prefix); + if(isset($plugin["load"])){ $order = strtoupper($plugin["load"]); if(!defined(PluginLoadOrder::class . "::" . $order)){ From c81b76cbf6ec851742e021e38fd2e01e7ece7334 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 1 Sep 2017 18:52:55 +0100 Subject: [PATCH 4/5] Make plugin load errors more descriptive --- src/pocketmine/lang/locale | 2 +- src/pocketmine/plugin/PluginManager.php | 25 ++++++++++++------------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/pocketmine/lang/locale b/src/pocketmine/lang/locale index eac602e8b..9868a649a 160000 --- a/src/pocketmine/lang/locale +++ b/src/pocketmine/lang/locale @@ -1 +1 @@ -Subproject commit eac602e8bc084fbaf3bc133129d6c8e4dc517c52 +Subproject commit 9868a649ad9151d9724298b4fcf3345eab9ea409 diff --git a/src/pocketmine/plugin/PluginManager.php b/src/pocketmine/plugin/PluginManager.php index 4dd93d3e0..0717d9bde 100644 --- a/src/pocketmine/plugin/PluginManager.php +++ b/src/pocketmine/plugin/PluginManager.php @@ -255,24 +255,20 @@ class PluginManager{ } if($compatible === false){ - $this->server->getLogger()->error($this->server->getLanguage()->translateString("pocketmine.plugin.loadError", [$name, "%pocketmine.plugin.incompatibleAPI"])); + $this->server->getLogger()->error($this->server->getLanguage()->translateString("pocketmine.plugin.loadError", [ + $name, + $this->server->getLanguage()->translateString("%pocketmine.plugin.incompatibleAPI", [implode(", ", $description->getCompatibleApis())]) + ])); continue; } if(count($pluginMcpeProtocols = $description->getCompatibleMcpeProtocols()) > 0){ $serverMcpeProtocols = [ProtocolInfo::CURRENT_PROTOCOL]; if(count(array_intersect($pluginMcpeProtocols, $serverMcpeProtocols)) === 0){ - $this->server->getLogger()->error($this->server->getLanguage()->translateString( - "pocketmine.plugin.loadError", - [ - $name, - $this->server->getLanguage()->translateString( - "%pocketmine.plugin.incompatibleProtocol", - [ - implode(", ", $pluginMcpeProtocols) - ]) - ] - )); + $this->server->getLogger()->error($this->server->getLanguage()->translateString("pocketmine.plugin.loadError", [ + $name, + $this->server->getLanguage()->translateString("%pocketmine.plugin.incompatibleProtocol", [implode(", ", $pluginMcpeProtocols)]) + ])); continue; } } @@ -306,7 +302,10 @@ class PluginManager{ if(isset($loadedPlugins[$dependency]) or $this->getPlugin($dependency) instanceof Plugin){ unset($dependencies[$name][$key]); }elseif(!isset($plugins[$dependency])){ - $this->server->getLogger()->critical($this->server->getLanguage()->translateString("pocketmine.plugin.loadError", [$name, "%pocketmine.plugin.unknownDependency"])); + $this->server->getLogger()->critical($this->server->getLanguage()->translateString("pocketmine.plugin.loadError", [ + $name, + $this->server->getLanguage()->translateString("%pocketmine.plugin.unknownDependency", [$dependency]) + ])); break; } } From 14ea76ecd707bc321cebb54d3a87cbaec93fb163 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 1 Sep 2017 19:36:57 +0100 Subject: [PATCH 5/5] Fixed PlayerBucketEmptyEvent never called, close #1339 --- src/pocketmine/item/Bucket.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pocketmine/item/Bucket.php b/src/pocketmine/item/Bucket.php index b906575de..489c6d1c2 100644 --- a/src/pocketmine/item/Bucket.php +++ b/src/pocketmine/item/Bucket.php @@ -27,6 +27,7 @@ use pocketmine\block\Air; use pocketmine\block\Block; use pocketmine\block\BlockFactory; use pocketmine\block\Liquid; +use pocketmine\event\player\PlayerBucketEmptyEvent; use pocketmine\event\player\PlayerBucketFillEvent; use pocketmine\level\Level; use pocketmine\math\Vector3; @@ -70,7 +71,7 @@ class Bucket extends Item{ }elseif($targetBlock instanceof Liquid){ $result = clone $this; $result->setDamage(0); - $player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $block, $face, $this, $result)); + $player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketEmptyEvent($player, $block, $face, $this, $result)); if(!$ev->isCancelled()){ $player->getLevel()->setBlock($block, $targetBlock, true, true); if($player->isSurvival()){