From 196b0a426374e741aaa752cdfe69a369fb7b4ac5 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Wed, 26 Dec 2012 14:02:37 +0100 Subject: [PATCH] Updated Interface --- classes/API/PluginAPI.php | 18 ++++++++++++------ example/ExamplePlugin.php | 2 +- example/ReactorAsWater.php | 2 +- example/SpawnChanger.php | 2 +- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/classes/API/PluginAPI.php b/classes/API/PluginAPI.php index e81d9a927..020bd6294 100644 --- a/classes/API/PluginAPI.php +++ b/classes/API/PluginAPI.php @@ -27,7 +27,7 @@ the Free Software Foundation, either version 3 of the License, or class PluginAPI extends stdClass{ private $server, $plugins; - public function __construct($server){ + public function __construct(PocketMinecraftServer $server){ $this->server = $server; $this->plugins = array(); require_once("classes/Spyc.class.php"); //YAML parser @@ -90,12 +90,18 @@ class PluginAPI extends stdClass{ } $object = new $className($this->server->api, ((isset($info["api"]) and $info["api"] !== true) ? $this->server:false)); if(!($object instanceof Plugin)){ - console("[NOTICE] [PluginAPI] Plugin \"".$info["name"]."\" doesn't use the Plugin Interface"); + console("[ERROR] [PluginAPI] Plugin \"".$info["name"]."\" doesn't use the Plugin Interface"); + if(method_exists($object, "__destruct")){ + $object->__destruct(); + } + $object = null; + unset($object); + }else{ + $this->plugins[$className] = array($object, $info); } - $this->plugins[$className] = array($object, $info); } - public function get($plugin){ + public function get(Plugin $plugin){ foreach($this->plugins as &$p){ if($p[0] === $plugin){ return $p; @@ -104,7 +110,7 @@ class PluginAPI extends stdClass{ return false; } - public function createConfig($plugin, $default = array()){ + public function createConfig(Plugin $plugin, $default = array()){ $p = $this->get($plugin); if($p === false){ return false; @@ -167,7 +173,7 @@ class PluginAPI extends stdClass{ interface Plugin{ - public function __construct($api, $server = false); + public function __construct(ServerAPI $api, $server = false); public function init(); public function __destruct(); } \ No newline at end of file diff --git a/example/ExamplePlugin.php b/example/ExamplePlugin.php index ca277d8f8..7a32f1553 100644 --- a/example/ExamplePlugin.php +++ b/example/ExamplePlugin.php @@ -11,7 +11,7 @@ class=ExamplePlugin class ExamplePlugin implements Plugin{ private $api; - public function __construct($api, $server = false){ + public function __construct(ServerAPI $api, $server = false){ $this->api = $api; } diff --git a/example/ReactorAsWater.php b/example/ReactorAsWater.php index 3f2adb0cb..3315b0382 100644 --- a/example/ReactorAsWater.php +++ b/example/ReactorAsWater.php @@ -12,7 +12,7 @@ class=ReactorAsWater class ReactorAsWater implements Plugin{ private $api; - public function __construct($api, $server = false){ + public function __construct(ServerAPI $api, $server = false){ $this->api = $api; } diff --git a/example/SpawnChanger.php b/example/SpawnChanger.php index c7889824f..37b41670d 100644 --- a/example/SpawnChanger.php +++ b/example/SpawnChanger.php @@ -12,7 +12,7 @@ class=SpawnChanger class SpawnChanger implements Plugin{ private $api, $config, $path; - public function __construct($api, $server = false){ + public function __construct(ServerAPI $api, $server = false){ $this->api = $api; }