mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-13 13:25:16 +00:00
PluginManager: clean up some Throwable abuse
This commit is contained in:
parent
c5df2f6f0d
commit
c5998a92a8
@ -172,19 +172,14 @@ class PluginManager{
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
try{
|
/**
|
||||||
/**
|
* @var Plugin $plugin
|
||||||
* @var Plugin $plugin
|
* @see Plugin::__construct()
|
||||||
* @see Plugin::__construct()
|
*/
|
||||||
*/
|
$plugin = new $mainClass($loader, $this->server, $description, $dataFolder, $prefixed);
|
||||||
$plugin = new $mainClass($loader, $this->server, $description, $dataFolder, $prefixed);
|
$this->plugins[$plugin->getDescription()->getName()] = $plugin;
|
||||||
$this->plugins[$plugin->getDescription()->getName()] = $plugin;
|
|
||||||
|
|
||||||
return $plugin;
|
return $plugin;
|
||||||
}catch(\Throwable $e){
|
|
||||||
$this->server->getLogger()->logException($e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -228,57 +223,59 @@ class PluginManager{
|
|||||||
}
|
}
|
||||||
try{
|
try{
|
||||||
$description = $loader->getPluginDescription($file);
|
$description = $loader->getPluginDescription($file);
|
||||||
if($description === null){
|
}catch(\RuntimeException $e){ //TODO: more specific exception handling
|
||||||
continue;
|
$this->server->getLogger()->error($this->server->getLanguage()->translateString("pocketmine.plugin.fileError", [$file, $directory, $e->getMessage()]));
|
||||||
}
|
$this->server->getLogger()->logException($e);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if($description === null){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$name = $description->getName();
|
$name = $description->getName();
|
||||||
if(stripos($name, "pocketmine") !== false or stripos($name, "minecraft") !== false or stripos($name, "mojang") !== false){
|
if(stripos($name, "pocketmine") !== false or stripos($name, "minecraft") !== false or stripos($name, "mojang") !== false){
|
||||||
$this->server->getLogger()->error($this->server->getLanguage()->translateString("pocketmine.plugin.loadError", [$name, "%pocketmine.plugin.restrictedName"]));
|
$this->server->getLogger()->error($this->server->getLanguage()->translateString("pocketmine.plugin.loadError", [$name, "%pocketmine.plugin.restrictedName"]));
|
||||||
continue;
|
continue;
|
||||||
}elseif(strpos($name, " ") !== false){
|
}
|
||||||
$this->server->getLogger()->warning($this->server->getLanguage()->translateString("pocketmine.plugin.spacesDiscouraged", [$name]));
|
if(strpos($name, " ") !== false){
|
||||||
}
|
$this->server->getLogger()->warning($this->server->getLanguage()->translateString("pocketmine.plugin.spacesDiscouraged", [$name]));
|
||||||
|
}
|
||||||
|
|
||||||
if(isset($plugins[$name]) or $this->getPlugin($name) instanceof Plugin){
|
if(isset($plugins[$name]) or $this->getPlugin($name) instanceof Plugin){
|
||||||
$this->server->getLogger()->error($this->server->getLanguage()->translateString("pocketmine.plugin.duplicateError", [$name]));
|
$this->server->getLogger()->error($this->server->getLanguage()->translateString("pocketmine.plugin.duplicateError", [$name]));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$this->isCompatibleApi(...$description->getCompatibleApis())){
|
if(!$this->isCompatibleApi(...$description->getCompatibleApis())){
|
||||||
|
$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", [
|
$this->server->getLogger()->error($this->server->getLanguage()->translateString("pocketmine.plugin.loadError", [
|
||||||
$name,
|
$name,
|
||||||
$this->server->getLanguage()->translateString("%pocketmine.plugin.incompatibleAPI", [implode(", ", $description->getCompatibleApis())])
|
$this->server->getLanguage()->translateString("%pocketmine.plugin.incompatibleProtocol", [implode(", ", $pluginMcpeProtocols)])
|
||||||
]));
|
]));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(count($pluginMcpeProtocols = $description->getCompatibleMcpeProtocols()) > 0){
|
$plugins[$name] = $file;
|
||||||
$serverMcpeProtocols = [ProtocolInfo::CURRENT_PROTOCOL];
|
|
||||||
if(count(array_intersect($pluginMcpeProtocols, $serverMcpeProtocols)) === 0){
|
$softDependencies[$name] = $description->getSoftDepend();
|
||||||
$this->server->getLogger()->error($this->server->getLanguage()->translateString("pocketmine.plugin.loadError", [
|
$dependencies[$name] = $description->getDepend();
|
||||||
$name,
|
|
||||||
$this->server->getLanguage()->translateString("%pocketmine.plugin.incompatibleProtocol", [implode(", ", $pluginMcpeProtocols)])
|
foreach($description->getLoadBefore() as $before){
|
||||||
]));
|
if(isset($softDependencies[$before])){
|
||||||
continue;
|
$softDependencies[$before][] = $name;
|
||||||
}
|
}else{
|
||||||
|
$softDependencies[$before] = [$name];
|
||||||
}
|
}
|
||||||
|
|
||||||
$plugins[$name] = $file;
|
|
||||||
|
|
||||||
$softDependencies[$name] = $description->getSoftDepend();
|
|
||||||
$dependencies[$name] = $description->getDepend();
|
|
||||||
|
|
||||||
foreach($description->getLoadBefore() as $before){
|
|
||||||
if(isset($softDependencies[$before])){
|
|
||||||
$softDependencies[$before][] = $name;
|
|
||||||
}else{
|
|
||||||
$softDependencies[$before] = [$name];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}catch(\Throwable $e){
|
|
||||||
$this->server->getLogger()->error($this->server->getLanguage()->translateString("pocketmine.plugin.fileError", [$file, $directory, $e->getMessage()]));
|
|
||||||
$this->server->getLogger()->logException($e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -413,23 +410,18 @@ class PluginManager{
|
|||||||
*/
|
*/
|
||||||
public function enablePlugin(Plugin $plugin){
|
public function enablePlugin(Plugin $plugin){
|
||||||
if(!$plugin->isEnabled()){
|
if(!$plugin->isEnabled()){
|
||||||
try{
|
$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();
|
$permManager = PermissionManager::getInstance();
|
||||||
foreach($plugin->getDescription()->getPermissions() as $perm){
|
foreach($plugin->getDescription()->getPermissions() as $perm){
|
||||||
$permManager->addPermission($perm);
|
$permManager->addPermission($perm);
|
||||||
}
|
|
||||||
$plugin->getScheduler()->setEnabled(true);
|
|
||||||
$plugin->onEnableStateChange(true);
|
|
||||||
|
|
||||||
$this->enabledPlugins[$plugin->getDescription()->getName()] = $plugin;
|
|
||||||
|
|
||||||
(new PluginEnableEvent($plugin))->call();
|
|
||||||
}catch(\Throwable $e){
|
|
||||||
$this->server->getLogger()->logException($e);
|
|
||||||
$this->disablePlugin($plugin);
|
|
||||||
}
|
}
|
||||||
|
$plugin->getScheduler()->setEnabled(true);
|
||||||
|
$plugin->onEnableStateChange(true);
|
||||||
|
|
||||||
|
$this->enabledPlugins[$plugin->getDescription()->getName()] = $plugin;
|
||||||
|
|
||||||
|
(new PluginEnableEvent($plugin))->call();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -449,11 +441,7 @@ class PluginManager{
|
|||||||
|
|
||||||
unset($this->enabledPlugins[$plugin->getDescription()->getName()]);
|
unset($this->enabledPlugins[$plugin->getDescription()->getName()]);
|
||||||
|
|
||||||
try{
|
$plugin->onEnableStateChange(false);
|
||||||
$plugin->onEnableStateChange(false);
|
|
||||||
}catch(\Throwable $e){
|
|
||||||
$this->server->getLogger()->logException($e);
|
|
||||||
}
|
|
||||||
$plugin->getScheduler()->shutdown();
|
$plugin->getScheduler()->shutdown();
|
||||||
HandlerList::unregisterAll($plugin);
|
HandlerList::unregisterAll($plugin);
|
||||||
$permManager = PermissionManager::getInstance();
|
$permManager = PermissionManager::getInstance();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user