From 5f52e0021359a466b6feae42a24ba5f30372124c Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 9 Apr 2018 15:54:20 +0100 Subject: [PATCH] Fixed plugin loaders trying to load plugins they aren't able to load closes #2125 This is an API break for things implementing the PluginLoader interface. --- src/pocketmine/plugin/PharPluginLoader.php | 5 +++++ src/pocketmine/plugin/PluginLoader.php | 9 +++++++++ src/pocketmine/plugin/PluginManager.php | 3 +++ src/pocketmine/plugin/ScriptPluginLoader.php | 5 +++++ tests/plugins/PocketMine-DevTools | 2 +- 5 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/pocketmine/plugin/PharPluginLoader.php b/src/pocketmine/plugin/PharPluginLoader.php index 488718e6d..5e78d1376 100644 --- a/src/pocketmine/plugin/PharPluginLoader.php +++ b/src/pocketmine/plugin/PharPluginLoader.php @@ -101,6 +101,11 @@ class PharPluginLoader implements PluginLoader{ return "/\\.phar$/i"; } + public function canLoadPlugin(string $path) : bool{ + $ext = ".phar"; + return is_file($path) and substr($path, -strlen($ext)) === $ext; + } + /** * @param PluginBase $plugin * @param PluginDescription $description diff --git a/src/pocketmine/plugin/PluginLoader.php b/src/pocketmine/plugin/PluginLoader.php index 1d219ec48..f5c71a556 100644 --- a/src/pocketmine/plugin/PluginLoader.php +++ b/src/pocketmine/plugin/PluginLoader.php @@ -53,6 +53,15 @@ interface PluginLoader{ */ public function getPluginFilters() : string; + /** + * Returns whether this PluginLoader can load the plugin in the given path. + * + * @param string $path + * + * @return bool + */ + public function canLoadPlugin(string $path) : bool; + /** * @param Plugin $plugin * diff --git a/src/pocketmine/plugin/PluginManager.php b/src/pocketmine/plugin/PluginManager.php index fa8bd7854..769deb5e5 100644 --- a/src/pocketmine/plugin/PluginManager.php +++ b/src/pocketmine/plugin/PluginManager.php @@ -210,6 +210,9 @@ class PluginManager{ continue; } $file = $directory . $file; + if(!$loader->canLoadPlugin($file)){ + continue; + } try{ $description = $loader->getPluginDescription($file); if($description instanceof PluginDescription){ diff --git a/src/pocketmine/plugin/ScriptPluginLoader.php b/src/pocketmine/plugin/ScriptPluginLoader.php index 31d852e61..368620757 100644 --- a/src/pocketmine/plugin/ScriptPluginLoader.php +++ b/src/pocketmine/plugin/ScriptPluginLoader.php @@ -124,6 +124,11 @@ class ScriptPluginLoader implements PluginLoader{ return "/\\.php$/i"; } + public function canLoadPlugin(string $path) : bool{ + $ext = ".php"; + return is_file($path) and substr($path, -strlen($ext)) === $ext; + } + /** * @param PluginBase $plugin * @param PluginDescription $description diff --git a/tests/plugins/PocketMine-DevTools b/tests/plugins/PocketMine-DevTools index 96fa93a3b..a897b84de 160000 --- a/tests/plugins/PocketMine-DevTools +++ b/tests/plugins/PocketMine-DevTools @@ -1 +1 @@ -Subproject commit 96fa93a3b4ee417ea5aff9ebb4e85d1fc6c7f960 +Subproject commit a897b84de445069dee898eaed95a9ff708a19383