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

Public Member Functions

 onLoad ()
 
 onEnable ()
 
 onDisable ()
 
 isEnabled ()
 
 setEnabled ($boolean=true)
 
 isDisabled ()
 
 getDataFolder ()
 
 getDescription ()
 
 init (PluginLoader $loader, Server $server, PluginDescription $description, $dataFolder, $file)
 
 getLogger ()
 
 isInitialized ()
 
 getCommand ($name)
 
 onCommand (CommandSender $sender, Command $command, $label, array $args)
 
 getResource ($filename)
 
 saveResource ($filename, $replace=false)
 
 getResources ()
 
 getConfig ()
 
 saveConfig ()
 
 saveDefaultConfig ()
 
 reloadConfig ()
 
 getServer ()
 
 getName ()
 
 getFullName ()
 
 getPluginLoader ()
 

Protected Member Functions

 isPhar ()
 
 getFile ()
 

Member Function Documentation

◆ getCommand()

getCommand (   $name)
Parameters
string$name
Returns
Command|PluginIdentifiableCommand
153  {
154  $command = $this->getServer()->getPluginCommand($name);
155  if($command === null or $command->getPlugin() !== $this){
156  $command = $this->getServer()->getPluginCommand(strtolower($this->description->getName()) . ":" . $name);
157  }
158 
159  if($command instanceof PluginIdentifiableCommand and $command->getPlugin() === $this){
160  return $command;
161  }else{
162  return null;
163  }
164  }

◆ getConfig()

getConfig ( )
Returns
Config

Implements Plugin.

251  {
252  if(!isset($this->config)){
253  $this->reloadConfig();
254  }
255 
256  return $this->config;
257  }

◆ getDataFolder()

getDataFolder ( )
final
Returns
string

Implements Plugin.

103  {
104  return $this->dataFolder;
105  }

◆ getDescription()

getDescription ( )
final
Returns
PluginDescription

Implements Plugin.

110  {
111  return $this->description;
112  }

◆ getFile()

getFile ( )
protected
Returns
mixed
312  {
313  return $this->file;
314  }

◆ getFullName()

getFullName ( )
final
Returns
string
305  {
306  return $this->description->getFullName();
307  }

◆ getLogger()

getLogger ( )
Returns
PluginLogger

Implements Plugin.

137  {
138  return $this->logger;
139  }

◆ getName()

getName ( )
final
Returns
string

Implements Plugin.

298  {
299  return $this->description->getName();
300  }

◆ getPluginLoader()

getPluginLoader ( )
Returns
PluginLoader

Implements Plugin.

319  {
320  return $this->loader;
321  }

◆ getResource()

getResource (   $filename)

Gets an embedded resource on the plugin file. WARNING: You must close the resource given using fclose()

Parameters
string$filename
Returns
resource Resource data, or null

Implements Plugin.

193  {
194  $filename = rtrim(str_replace("\\", "/", $filename), "/");
195  if(file_exists($this->file . "resources/" . $filename)){
196  return fopen($this->file . "resources/" . $filename, "rb");
197  }
198 
199  return null;
200  }

◆ getResources()

getResources ( )

Returns all the resources packaged with the plugin

Returns
string[]

Implements Plugin.

237  {
238  $resources = [];
239  if(is_dir($this->file . "resources/")){
240  foreach(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->file . "resources/")) as $resource){
241  $resources[] = $resource;
242  }
243  }
244 
245  return $resources;
246  }

◆ getServer()

getServer ( )
final
Returns
Server

Implements Plugin.

291  {
292  return $this->server;
293  }

◆ init()

init ( PluginLoader  $loader,
Server  $server,
PluginDescription  $description,
  $dataFolder,
  $file 
)
final
Parameters
PluginLoader$loader
Server$server
PluginDescription$description
$dataFolder
$file
121  {
122  if($this->initialized === false){
123  $this->initialized = true;
124  $this->loader = $loader;
125  $this->server = $server;
126  $this->description = $description;
127  $this->dataFolder = rtrim($dataFolder, "\\/") . "/";
128  $this->file = rtrim($file, "\\/") . "/";
129  $this->configFile = $this->dataFolder . "config.yml";
130  $this->logger = new PluginLogger($this);
131  }
132  }

◆ isDisabled()

isDisabled ( )
final
Returns
bool

Implements Plugin.

96  {
97  return $this->isEnabled === false;
98  }

◆ isEnabled()

isEnabled ( )
final
Returns
bool

Implements Plugin.

75  {
76  return $this->isEnabled === true;
77  }

◆ isInitialized()

isInitialized ( )
final
Returns
bool
144  {
145  return $this->initialized;
146  }

◆ isPhar()

isPhar ( )
protected
Returns
bool
181  {
182  return substr($this->file, 0, 7) === "phar://";
183  }

◆ onCommand()

onCommand ( CommandSender  $sender,
Command  $command,
  $label,
array  $args 
)
Parameters
CommandSender$sender
Command$command
string$label
array$args
Returns
bool

Implements CommandExecutor.

174  {
175  return false;
176  }

◆ onDisable()

onDisable ( )

Called when the plugin is disabled Use this to free open things and finish actions

Implements Plugin.

68  {
69 
70  }

◆ onEnable()

onEnable ( )

Called when the plugin is enabled

Implements Plugin.

64  {
65 
66  }

◆ onLoad()

onLoad ( )

Called when the plugin is loaded, before calling onEnable()

Implements Plugin.

60  {
61 
62  }

◆ reloadConfig()

reloadConfig ( )
Returns
mixed

Implements Plugin.

280  {
281  $this->config = new Config($this->configFile);
282  if(($configStream = $this->getResource("config.yml")) !== null){
283  $this->config->setDefaults(yaml_parse(Config::fixYAMLIndexes(stream_get_contents($configStream))));
284  fclose($configStream);
285  }
286  }

◆ saveConfig()

saveConfig ( )
Returns
mixed

Implements Plugin.

262  {
263  if($this->getConfig()->save() === false){
264  $this->getLogger()->critical("Could not save config to " . $this->configFile);
265  }
266  }

◆ saveDefaultConfig()

saveDefaultConfig ( )
Returns
mixed

Implements Plugin.

271  {
272  if(!file_exists($this->configFile)){
273  $this->saveResource("config.yml", false);
274  }
275  }

◆ saveResource()

saveResource (   $filename,
  $replace = false 
)
Parameters
string$filename
bool$replace
Returns
bool

Implements Plugin.

208  {
209  if(trim($filename) === ""){
210  return false;
211  }
212 
213  if(($resource = $this->getResource($filename)) === null){
214  return false;
215  }
216 
217  $out = $this->dataFolder . $filename;
218  if(!file_exists(dirname($out))){
219  mkdir(dirname($out), 0755, true);
220  }
221 
222  if(file_exists($out) and $replace !== true){
223  return false;
224  }
225 
226  $ret = stream_copy_to_stream($resource, $fp = fopen($out, "wb")) > 0;
227  fclose($fp);
228  fclose($resource);
229  return $ret;
230  }

◆ setEnabled()

setEnabled (   $boolean = true)
final
Parameters
bool$boolean
82  {
83  if($this->isEnabled !== $boolean){
84  $this->isEnabled = $boolean;
85  if($this->isEnabled === true){
86  $this->onEnable();
87  }else{
88  $this->onDisable();
89  }
90  }
91  }

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