mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-23 20:04:02 +00:00
Look! New PluginAPI!
This commit is contained in:
parent
14e1dda327
commit
a0a7042d43
@ -22,8 +22,10 @@
|
|||||||
class PluginAPI extends stdClass{
|
class PluginAPI extends stdClass{
|
||||||
private $server;
|
private $server;
|
||||||
private $plugins = array();
|
private $plugins = array();
|
||||||
|
private $randomNonce;
|
||||||
public function __construct(){
|
public function __construct(){
|
||||||
$this->server = ServerAPI::request();
|
$this->server = ServerAPI::request();
|
||||||
|
$this->randomNonce = Utils::getRandomBytes(16, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getList(){
|
public function getList(){
|
||||||
@ -33,14 +35,9 @@ class PluginAPI extends stdClass{
|
|||||||
}
|
}
|
||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getInfo($className){
|
public function getAll(){
|
||||||
$className = strtolower($className);
|
return $this->plugins;
|
||||||
if(!isset($this->plugins[$className])){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$plugin = $this->plugins[$className];
|
|
||||||
return array($plugin[1], get_class_methods($plugin[0]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function load($file){
|
public function load($file){
|
||||||
@ -95,6 +92,8 @@ class PluginAPI extends stdClass{
|
|||||||
console("[WARNING] Plugin \"".$info["name"]."\" may not be compatible with the API (".$info["apiversion"]." != ".CURRENT_API_VERSION.")! It can crash or corrupt the server!");
|
console("[WARNING] Plugin \"".$info["name"]."\" may not be compatible with the API (".$info["apiversion"]." != ".CURRENT_API_VERSION.")! It can crash or corrupt the server!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$identifier = $this->getIdentifier($info["name"], $info["author"]);
|
||||||
|
|
||||||
if($info["class"] !== "none"){
|
if($info["class"] !== "none"){
|
||||||
$object = new $className($this->server->api, false);
|
$object = new $className($this->server->api, false);
|
||||||
if(!($object instanceof Plugin)){
|
if(!($object instanceof Plugin)){
|
||||||
@ -105,18 +104,29 @@ class PluginAPI extends stdClass{
|
|||||||
$object = null;
|
$object = null;
|
||||||
unset($object);
|
unset($object);
|
||||||
}else{
|
}else{
|
||||||
$this->plugins[$className] = array($object, $info);
|
$this->plugins[$identifier] = array($object, $info);
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
$this->plugins[md5($info["name"])] = array(new DummyPlugin($this->server->api, false), $info);
|
$this->plugins[$identifier] = array(new DummyPlugin($this->server->api, false), $info);
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get(Plugin $plugin){
|
public function getIdentifier($name, $author){
|
||||||
foreach($this->plugins as &$p){
|
return sha1(trim(strtolower($name)), true) ^ sha1(trim(strtolower($author)), true) ^ sha1($this->randomNonce, true);
|
||||||
if($p[0] === $plugin){
|
}
|
||||||
return $p;
|
|
||||||
|
public function get($identifier){
|
||||||
|
if($identifier instanceof Plugin){
|
||||||
|
foreach($this->plugins as $p){
|
||||||
|
if($p[0] === $identifier){
|
||||||
|
return $p;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(isset($this->plugins[$identifier])){
|
||||||
|
return $this->plugins[$identifier];
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -176,7 +186,7 @@ class PluginAPI extends stdClass{
|
|||||||
$this->loadAll();
|
$this->loadAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loadAll(){
|
private function loadAll(){
|
||||||
$dir = dir($this->pluginsPath());
|
$dir = dir($this->pluginsPath());
|
||||||
while(false !== ($file = $dir->read())){
|
while(false !== ($file = $dir->read())){
|
||||||
if($file{0} !== "."){
|
if($file{0} !== "."){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user