GenisysPro  for Minecraft PE/Windows 10 v1.1.x
Feature-rich server software for Minecraft PE and Windows 10 Edition
ScriptPluginLoader Class Reference

Public Member Functions

 __construct (Server $server)
 
 loadPlugin ($file)
 
 getPluginDescription ($file)
 
 getPluginFilters ()
 
 enablePlugin (Plugin $plugin)
 
 disablePlugin (Plugin $plugin)
 

Detailed Description

Simple script loader, not for plugin development For an example see https://gist.github.com/shoghicp/516105d470cf7d140757

Constructor & Destructor Documentation

◆ __construct()

__construct ( Server  $server)
Parameters
Server$server
40  {
41  $this->server = $server;
42  }

Member Function Documentation

◆ disablePlugin()

disablePlugin ( Plugin  $plugin)
Parameters
Plugin$plugin

Implements PluginLoader.

154  {
155  if($plugin instanceof PluginBase and $plugin->isEnabled()){
156  $this->server->getLogger()->info($this->server->getLanguage()->translateString("pocketmine.plugin.disable", [$plugin->getDescription()->getFullName()]));
157 
158  $this->server->getPluginManager()->callEvent(new PluginDisableEvent($plugin));
159 
160  $plugin->setEnabled(false);
161  }
162  }

◆ enablePlugin()

enablePlugin ( Plugin  $plugin)
Parameters
Plugin$plugin

Implements PluginLoader.

141  {
142  if($plugin instanceof PluginBase and !$plugin->isEnabled()){
143  $this->server->getLogger()->info($this->server->getLanguage()->translateString("pocketmine.plugin.enable", [$plugin->getDescription()->getFullName()]));
144 
145  $plugin->setEnabled(true);
146 
147  $this->server->getPluginManager()->callEvent(new PluginEnableEvent($plugin));
148  }
149  }

◆ getPluginDescription()

getPluginDescription (   $file)

Gets the PluginDescription from the file

Parameters
string$file
Returns
PluginDescription

Implements PluginLoader.

85  {
86  $content = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
87 
88  $data = [];
89 
90  $insideHeader = false;
91  foreach($content as $line){
92  if(!$insideHeader and strpos($line, "/**") !== false){
93  $insideHeader = true;
94  }
95 
96  if(preg_match("/^[ \t]+\\*[ \t]+@([a-zA-Z]+)([ \t]+(.*))?$/", $line, $matches) > 0){
97  $key = $matches[1];
98  $content = trim($matches[3] ?? "");
99 
100  if($key === "notscript"){
101  return null;
102  }
103 
104  $data[$key] = $content;
105  }
106 
107  if($insideHeader and strpos($line, "**/") !== false){
108  break;
109  }
110  }
111  if($insideHeader){
112  return new PluginDescription($data);
113  }
114 
115  return null;
116  }

◆ getPluginFilters()

getPluginFilters ( )

Returns the filename patterns that this loader accepts

Returns
string

Implements PluginLoader.

123  {
124  return "/\\.php$/i";
125  }

◆ loadPlugin()

loadPlugin (   $file)

Loads the plugin contained in $file

Parameters
string$file
Returns
Plugin
Exceptions

Implements PluginLoader.

53  {
54  if(($description = $this->getPluginDescription($file)) instanceof PluginDescription){
55  $this->server->getLogger()->info($this->server->getLanguage()->translateString("pocketmine.plugin.load", [$description->getFullName()]));
56  $dataFolder = dirname($file) . DIRECTORY_SEPARATOR . $description->getName();
57  if(file_exists($dataFolder) and !is_dir($dataFolder)){
58  throw new \InvalidStateException("Projected dataFolder '" . $dataFolder . "' for " . $description->getName() . " exists and is not a directory");
59  }
60 
61  include_once($file);
62 
63  $className = $description->getMain();
64 
65  if(class_exists($className, true)){
66  $plugin = new $className();
67  $this->initPlugin($plugin, $description, $dataFolder, $file);
68 
69  return $plugin;
70  }else{
71  throw new PluginException("Couldn't load plugin " . $description->getName() . ": main class not found");
72  }
73  }
74 
75  return null;
76  }

The documentation for this class was generated from the following file: