mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-18 12:04:46 +00:00
Updated trigger_error to Exceptions, fixed bug in Plugin task deletion
This commit is contained in:
@@ -46,15 +46,15 @@ class PharPluginLoader implements PluginLoader{
|
||||
* @param string $file
|
||||
*
|
||||
* @return Plugin
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function loadPlugin($file){
|
||||
if(\Phar::isValidPharFilename($file) and ($description = $this->getPluginDescription($file)) instanceof PluginDescription){
|
||||
console("[INFO] Loading " . $description->getFullName());
|
||||
$dataFolder = dirname($file) . DIRECTORY_SEPARATOR . $description->getName();
|
||||
if(file_exists($dataFolder) and !is_dir($dataFolder)){
|
||||
trigger_error("Projected dataFolder '" . $dataFolder . "' for " . $description->getName() . " exists and is not a directory", E_USER_WARNING);
|
||||
|
||||
return null;
|
||||
throw new \Exception("Projected dataFolder '" . $dataFolder . "' for " . $description->getName() . " exists and is not a directory");
|
||||
}
|
||||
$file = "phar://$file";
|
||||
$className = $description->getMain();
|
||||
@@ -68,9 +68,7 @@ class PharPluginLoader implements PluginLoader{
|
||||
|
||||
return $plugin;
|
||||
}else{
|
||||
trigger_error("Couldn't load plugin " . $description->getName() . ": main class not found", E_USER_WARNING);
|
||||
|
||||
return null;
|
||||
throw new \Exception("Couldn't load plugin " . $description->getName() . ": main class not found");
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -50,12 +50,14 @@ class PluginDescription{
|
||||
$this->loadMap(\yaml_parse($yamlString));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $plugin
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function loadMap(array $plugin){
|
||||
$this->name = preg_replace("[^A-Za-z0-9 _.-]", "", $plugin["name"]);
|
||||
if($this->name === ""){
|
||||
trigger_error("Invalid PluginDescription name", E_USER_WARNING);
|
||||
|
||||
return;
|
||||
throw new \Exception("Invalid PluginDescription name");
|
||||
}
|
||||
$this->name = str_replace(" ", "_", $this->name);
|
||||
$this->version = $plugin["version"];
|
||||
|
@@ -638,12 +638,12 @@ class PluginManager{
|
||||
*
|
||||
* @param Listener $listener
|
||||
* @param Plugin $plugin
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function registerEvents(Listener $listener, Plugin $plugin){
|
||||
if(!$plugin->isEnabled()){
|
||||
trigger_error("Plugin attempted to register " . get_class($listener) . " while not enabled", E_USER_WARNING);
|
||||
|
||||
return;
|
||||
throw new \Exception("Plugin attempted to register " . get_class($listener) . " while not enabled");
|
||||
}
|
||||
|
||||
$reflection = new \ReflectionClass(get_class($listener));
|
||||
@@ -680,17 +680,15 @@ class PluginManager{
|
||||
* @param EventExecutor $executor
|
||||
* @param Plugin $plugin
|
||||
* @param bool $ignoreCancelled
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function registerEvent($event, Listener $listener, $priority, EventExecutor $executor, Plugin $plugin, $ignoreCancelled = false){
|
||||
if(!is_subclass_of($event, "pocketmine\\event\\Event")){
|
||||
trigger_error($event . " is not a valid Event", E_USER_WARNING);
|
||||
|
||||
return;
|
||||
throw new \Exception($event . " is not a valid Event");
|
||||
}
|
||||
if(!$plugin->isEnabled()){
|
||||
trigger_error("Plugin attempted to register " . $event . " while not enabled");
|
||||
|
||||
return;
|
||||
throw new \Exception("Plugin attempted to register " . $event . " while not enabled");
|
||||
}
|
||||
|
||||
$this->getEventListeners($event)->register(new RegisteredListener($listener, $executor, $priority, $plugin, $ignoreCancelled));
|
||||
|
Reference in New Issue
Block a user