mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-15 02:09:42 +00:00
Command: validate permissions, require permission registration in advance of commands using them
this fixes #3200. This causes permissions to be registered before plugin load, which changes some behaviour, but after discussions on #internals-dev we couldn't see any reason to keep the behaviour the way it was, and several reasons to change it to be something like this.
This commit is contained in:
parent
6bca38999d
commit
92f6967665
@ -931,6 +931,8 @@ class Server{
|
|||||||
TimingsHandler::setEnabled((bool) $this->configGroup->getProperty("settings.enable-profiling", false));
|
TimingsHandler::setEnabled((bool) $this->configGroup->getProperty("settings.enable-profiling", false));
|
||||||
$this->profilingTickRate = (float) $this->configGroup->getProperty("settings.profile-report-trigger", 20);
|
$this->profilingTickRate = (float) $this->configGroup->getProperty("settings.profile-report-trigger", 20);
|
||||||
|
|
||||||
|
DefaultPermissions::registerCorePermissions();
|
||||||
|
|
||||||
$this->commandMap = new SimpleCommandMap($this);
|
$this->commandMap = new SimpleCommandMap($this);
|
||||||
|
|
||||||
Enchantment::init();
|
Enchantment::init();
|
||||||
@ -1268,7 +1270,6 @@ class Server{
|
|||||||
|
|
||||||
if($type->equals(PluginLoadOrder::POSTWORLD())){
|
if($type->equals(PluginLoadOrder::POSTWORLD())){
|
||||||
$this->commandMap->registerServerAliases();
|
$this->commandMap->registerServerAliases();
|
||||||
DefaultPermissions::registerCorePermissions();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,6 +99,13 @@ abstract class Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function setPermission(?string $permission) : void{
|
public function setPermission(?string $permission) : void{
|
||||||
|
if($permission !== null){
|
||||||
|
foreach(explode(";", $permission) as $perm){
|
||||||
|
if(PermissionManager::getInstance()->getPermission($perm) === null){
|
||||||
|
throw new \InvalidArgumentException("Cannot use non-existing permission \"$perm\"");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
$this->permission = $permission;
|
$this->permission = $permission;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,6 +161,11 @@ class PluginManager{
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$permManager = PermissionManager::getInstance();
|
||||||
|
foreach($description->getPermissions() as $perm){
|
||||||
|
$permManager->addPermission($perm);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Plugin $plugin
|
* @var Plugin $plugin
|
||||||
* @see Plugin::__construct()
|
* @see Plugin::__construct()
|
||||||
@ -364,10 +369,6 @@ class PluginManager{
|
|||||||
if(!$plugin->isEnabled()){
|
if(!$plugin->isEnabled()){
|
||||||
$this->server->getLogger()->info($this->server->getLanguage()->translateString("pocketmine.plugin.enable", [$plugin->getDescription()->getFullName()]));
|
$this->server->getLogger()->info($this->server->getLanguage()->translateString("pocketmine.plugin.enable", [$plugin->getDescription()->getFullName()]));
|
||||||
|
|
||||||
$permManager = PermissionManager::getInstance();
|
|
||||||
foreach($plugin->getDescription()->getPermissions() as $perm){
|
|
||||||
$permManager->addPermission($perm);
|
|
||||||
}
|
|
||||||
$plugin->getScheduler()->setEnabled(true);
|
$plugin->getScheduler()->setEnabled(true);
|
||||||
$plugin->onEnableStateChange(true);
|
$plugin->onEnableStateChange(true);
|
||||||
|
|
||||||
@ -393,10 +394,6 @@ class PluginManager{
|
|||||||
$plugin->onEnableStateChange(false);
|
$plugin->onEnableStateChange(false);
|
||||||
$plugin->getScheduler()->shutdown();
|
$plugin->getScheduler()->shutdown();
|
||||||
HandlerListManager::global()->unregisterAll($plugin);
|
HandlerListManager::global()->unregisterAll($plugin);
|
||||||
$permManager = PermissionManager::getInstance();
|
|
||||||
foreach($plugin->getDescription()->getPermissions() as $perm){
|
|
||||||
$permManager->removePermission($perm);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user