Added extra Exceptions

This commit is contained in:
Shoghi Cervantes
2014-10-28 21:07:12 +01:00
parent b6f7ee20fc
commit 8c4faa8622
37 changed files with 215 additions and 87 deletions

View File

@ -24,6 +24,7 @@ namespace pocketmine\plugin;
use pocketmine\event\plugin\PluginDisableEvent;
use pocketmine\event\plugin\PluginEnableEvent;
use pocketmine\Server;
use pocketmine\utils\PluginException;
/**
* Handles different types of plugins
@ -54,7 +55,7 @@ class PharPluginLoader implements PluginLoader{
$this->server->getLogger()->info("Loading " . $description->getFullName());
$dataFolder = dirname($file) . DIRECTORY_SEPARATOR . $description->getName();
if(file_exists($dataFolder) and !is_dir($dataFolder)){
throw new \Exception("Projected dataFolder '" . $dataFolder . "' for " . $description->getName() . " exists and is not a directory");
throw new \InvalidStateException("Projected dataFolder '" . $dataFolder . "' for " . $description->getName() . " exists and is not a directory");
}
$file = "phar://$file";
$className = $description->getMain();
@ -66,7 +67,7 @@ class PharPluginLoader implements PluginLoader{
return $plugin;
}else{
throw new \Exception("Couldn't load plugin " . $description->getName() . ": main class not found");
throw new PluginException("Couldn't load plugin " . $description->getName() . ": main class not found");
}
}

View File

@ -22,6 +22,7 @@
namespace pocketmine\plugin;
use pocketmine\permission\Permission;
use pocketmine\utils\PluginException;
class PluginDescription{
private $name;
@ -53,12 +54,12 @@ class PluginDescription{
/**
* @param array $plugin
*
* @throws \Exception
* @throws PluginException
*/
private function loadMap(array $plugin){
$this->name = preg_replace("[^A-Za-z0-9 _.-]", "", $plugin["name"]);
if($this->name === ""){
throw new \Exception("Invalid PluginDescription name");
throw new PluginException("Invalid PluginDescription name");
}
$this->name = str_replace(" ", "_", $this->name);
$this->version = $plugin["version"];

View File

@ -34,6 +34,7 @@ use pocketmine\permission\Permissible;
use pocketmine\permission\Permission;
use pocketmine\Server;
use pocketmine\utils\MainLogger;
use pocketmine\utils\PluginException;
/**
* Manages all the plugins, Permissions and Permissibles
@ -675,11 +676,11 @@ class PluginManager{
* @param Listener $listener
* @param Plugin $plugin
*
* @throws \Exception
* @throws PluginException
*/
public function registerEvents(Listener $listener, Plugin $plugin){
if(!$plugin->isEnabled()){
throw new \Exception("Plugin attempted to register " . get_class($listener) . " while not enabled");
throw new PluginException("Plugin attempted to register " . get_class($listener) . " while not enabled");
}
$reflection = new \ReflectionClass(get_class($listener));
@ -723,15 +724,15 @@ class PluginManager{
* @param Plugin $plugin
* @param bool $ignoreCancelled
*
* @throws \Exception
* @throws PluginException
*/
public function registerEvent($event, Listener $listener, $priority, EventExecutor $executor, Plugin $plugin, $ignoreCancelled = false){
if(!is_subclass_of($event, Event::class) or (new \ReflectionClass($event))->isAbstract()){
throw new \Exception($event . " is not a valid Event");
throw new PluginException($event . " is not a valid Event");
}
if(!$plugin->isEnabled()){
throw new \Exception("Plugin attempted to register " . $event . " while not enabled");
throw new PluginException("Plugin attempted to register " . $event . " while not enabled");
}
$timings = new TimingsHandler("Plugin: " . $plugin->getDescription()->getFullName() . " Event: " . get_class($listener) . "::" . ($executor instanceof MethodEventExecutor ? $executor->getMethod() : "???") . "(" . (new \ReflectionClass($event))->getShortName() . ")", self::$pluginParentTimer);