mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 16:00:20 +00:00
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.
This commit is contained in:
parent
138d85307b
commit
6e8631347d
@ -1 +1 @@
|
||||
Subproject commit 2ab4d9172eba05cb7c6b8c98639db2ba9e60472c
|
||||
Subproject commit eac602e8bc084fbaf3bc133129d6c8e4dc517c52
|
@ -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[]
|
||||
*/
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user