Updated Interface

This commit is contained in:
Shoghi Cervantes Pueyo 2012-12-26 14:02:37 +01:00
parent 39d5fea0ef
commit 196b0a4263
4 changed files with 15 additions and 9 deletions

View File

@ -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();
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}