PluginManager: clean up some Throwable abuse

This commit is contained in:
Dylan K. Taylor 2019-01-17 23:34:59 +00:00
parent c5df2f6f0d
commit c5998a92a8

View File

@ -172,7 +172,6 @@ class PluginManager{
return null; return null;
} }
try{
/** /**
* @var Plugin $plugin * @var Plugin $plugin
* @see Plugin::__construct() * @see Plugin::__construct()
@ -181,10 +180,6 @@ class PluginManager{
$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,6 +223,11 @@ class PluginManager{
} }
try{ try{
$description = $loader->getPluginDescription($file); $description = $loader->getPluginDescription($file);
}catch(\RuntimeException $e){ //TODO: more specific exception handling
$this->server->getLogger()->error($this->server->getLanguage()->translateString("pocketmine.plugin.fileError", [$file, $directory, $e->getMessage()]));
$this->server->getLogger()->logException($e);
continue;
}
if($description === null){ if($description === null){
continue; continue;
} }
@ -236,7 +236,8 @@ class PluginManager{
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){ }
if(strpos($name, " ") !== false){
$this->server->getLogger()->warning($this->server->getLanguage()->translateString("pocketmine.plugin.spacesDiscouraged", [$name])); $this->server->getLogger()->warning($this->server->getLanguage()->translateString("pocketmine.plugin.spacesDiscouraged", [$name]));
} }
@ -276,10 +277,6 @@ class PluginManager{
$softDependencies[$before] = [$name]; $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,7 +410,6 @@ 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();
@ -426,10 +422,6 @@ class PluginManager{
$this->enabledPlugins[$plugin->getDescription()->getName()] = $plugin; $this->enabledPlugins[$plugin->getDescription()->getName()] = $plugin;
(new PluginEnableEvent($plugin))->call(); (new PluginEnableEvent($plugin))->call();
}catch(\Throwable $e){
$this->server->getLogger()->logException($e);
$this->disablePlugin($plugin);
}
} }
} }
@ -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();