mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 09:56:06 +00:00
PluginAPI
This commit is contained in:
@ -25,6 +25,67 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
|
||||
*/
|
||||
|
||||
class PluginAPI{
|
||||
class PluginAPI extends stdClass{
|
||||
private $server, $plugins;
|
||||
public function __construct($server){
|
||||
$this->server = $server;
|
||||
$this->plugins = array();
|
||||
}
|
||||
|
||||
private function load($file){
|
||||
$content = file_get_contents($file);
|
||||
$info = strstr($content, "*/", true);
|
||||
$content = substr(strstr($content, "*/"),2);
|
||||
if(preg_match_all('#([a-zA-Z0-9\-_]*)=([^\r\n]*)#u', $info, $matches) == 0){ //false or 0 matches
|
||||
console("[ERROR] [PluginAPI] Failed parsing of ".basename($file));
|
||||
return false;
|
||||
}
|
||||
$info = array();
|
||||
foreach($matches[1] as $k => $i){
|
||||
$v = $matches[2][$k];
|
||||
switch(strtolower($v)){
|
||||
case "on":
|
||||
case "true":
|
||||
case "yes":
|
||||
$v = true;
|
||||
break;
|
||||
case "off":
|
||||
case "false":
|
||||
case "no":
|
||||
$v = false;
|
||||
break;
|
||||
}
|
||||
$info[$i] = $v;
|
||||
}
|
||||
if(!isset($info["name"]) or !isset($info["version"]) or !isset($info["class"])){
|
||||
console("[ERROR] [PluginAPI] Failed parsing of ".basename($file));
|
||||
}
|
||||
console("[INFO] [PluginAPI] Loading plugin \"".$info["name"]."\" ".$info["version"]);
|
||||
if(eval($content) === false or !class_exists($info["class"])){
|
||||
console("[ERROR] [PluginAPI] Failed loading plugin");
|
||||
}
|
||||
$className = trim($info["class"]);
|
||||
if(isset($info["api"]) and $info["api"] !== true){
|
||||
console("[NOTICE] [PluginAPI] Plugin \"".$info["name"]."\" got raw access to Server methods");
|
||||
}
|
||||
$object = new $className($this->server->api, ((isset($info["api"]) and $info["api"] !== true) ? $this->server:false));
|
||||
$this->plugins[$className] = array($object, $info);
|
||||
}
|
||||
|
||||
public function init(){
|
||||
console("[INFO] Loading Plugins...");
|
||||
$dir = dir(FILE_PATH."data/plugins/");
|
||||
while(false !== ($file = $dir->read())){
|
||||
if($file !== "." and $file !== ".."){
|
||||
if(strtolower(substr($file, -3)) === "php"){
|
||||
$this->load(FILE_PATH."data/plugins/" . $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach($this->plugins as $p){
|
||||
if(method_exists($p[0], "init")){
|
||||
$p[0]->init();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -26,8 +26,8 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
*/
|
||||
|
||||
class ServerAPI extends stdClass{ //Yay! I can add anything to this class in runtime!
|
||||
var $server, $restart = false;
|
||||
private $config, $apiList = array();
|
||||
var $restart = false;
|
||||
private $server, $config, $apiList = array();
|
||||
function __construct(){
|
||||
console("[INFO] Starting ServerAPI server handler...");
|
||||
file_put_contents(FILE_PATH."packets.log", "");
|
||||
@ -291,9 +291,21 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
|
||||
$d = explode("=", $line);
|
||||
$n = strtolower(array_shift($d));
|
||||
$v = implode("=", $d);
|
||||
switch(strtolower(trim($v))){
|
||||
case "on":
|
||||
case "true":
|
||||
case "yes":
|
||||
$v = true;
|
||||
break;
|
||||
case "off":
|
||||
case "false":
|
||||
case "no":
|
||||
$v = false;
|
||||
break;
|
||||
}
|
||||
switch($n){
|
||||
case "last-update":
|
||||
if(trim($v) == "false"){
|
||||
if($v === false){
|
||||
$v = time();
|
||||
}else{
|
||||
$v = (int) $v;
|
||||
@ -308,10 +320,7 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
|
||||
$v = (int) $v;
|
||||
break;
|
||||
case "seed":
|
||||
$v = trim($v);
|
||||
if($v == "false"){
|
||||
$v = false;
|
||||
}elseif(preg_match("/[^0-9\-]/", $v) > 0){
|
||||
if($v !== false and preg_match("/[^0-9\-]/", $v) > 0){
|
||||
$str = new Java_String($v);
|
||||
$v = $str->hashCode();
|
||||
}else{
|
||||
@ -319,21 +328,14 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
|
||||
}
|
||||
break;
|
||||
case "server-id":
|
||||
$v = trim($v);
|
||||
$v = $v == "false" ? false:(preg_match("/[^0-9\-]/", $v) > 0 ? Utils::readInt(substr(md5($v, true), 0, 4)):$v);
|
||||
break;
|
||||
case "level-name":
|
||||
$v = trim($v);
|
||||
$v = $v == "false" ? false:$v;
|
||||
if($v !== false){
|
||||
$v = preg_match("/[^0-9\-]/", $v) > 0 ? Utils::readInt(substr(md5($v, true), 0, 4)):$v;
|
||||
}
|
||||
break;
|
||||
case "spawn":
|
||||
$v = explode(";", $v);
|
||||
$v = array("x" => floatval($v[0]), "y" => floatval($v[1]), "z" => floatval($v[2]));
|
||||
break;
|
||||
case "white-list":
|
||||
case "invisible":
|
||||
$v = trim($v) == "true" ? true:false;
|
||||
break;
|
||||
}
|
||||
$this->config[$n] = $v;
|
||||
}
|
||||
|
@ -166,7 +166,7 @@ class Session{
|
||||
break;
|
||||
case "onChat":
|
||||
$this->dataPacket(MC_CHAT, array(
|
||||
"message" => $data,
|
||||
"message" => str_replace("@username", $this->username, $data),
|
||||
));
|
||||
break;
|
||||
}
|
||||
|
Reference in New Issue
Block a user