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

Public Member Functions

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

Detailed Description

Handles different types of plugins

Constructor & Destructor Documentation

◆ __construct()

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

Member Function Documentation

◆ disablePlugin()

disablePlugin ( Plugin  $plugin)
Parameters
Plugin$plugin

Implements PluginLoader.

131  {
132  if($plugin instanceof PluginBase and $plugin->isEnabled()){
133  $this->server->getLogger()->info($this->server->getLanguage()->translateString("pocketmine.plugin.disable", [$plugin->getDescription()->getFullName()]));
134 
135  $this->server->getPluginManager()->callEvent(new PluginDisableEvent($plugin));
136 
137  $plugin->setEnabled(false);
138  }
139  }

◆ enablePlugin()

enablePlugin ( Plugin  $plugin)
Parameters
Plugin$plugin

Implements PluginLoader.

118  {
119  if($plugin instanceof PluginBase and !$plugin->isEnabled()){
120  $this->server->getLogger()->info($this->server->getLanguage()->translateString("pocketmine.plugin.enable", [$plugin->getDescription()->getFullName()]));
121 
122  $plugin->setEnabled(true);
123 
124  $this->server->getPluginManager()->callEvent(new PluginEnableEvent($plugin));
125  }
126  }

◆ getPluginDescription()

getPluginDescription (   $file)

Gets the PluginDescription from the file

Parameters
string$file
Returns
PluginDescription

Implements PluginLoader.

83  {
84  $phar = new \Phar($file);
85  if(isset($phar["plugin.yml"])){
86  $pluginYml = $phar["plugin.yml"];
87  if($pluginYml instanceof \PharFileInfo){
88  return new PluginDescription($pluginYml->getContent());
89  }
90  }
91 
92  return null;
93  }

◆ getPluginFilters()

getPluginFilters ( )

Returns the filename patterns that this loader accepts

Returns
string

Implements PluginLoader.

100  {
101  return "/\\.phar$/i";
102  }

◆ loadPlugin()

loadPlugin (   $file)

Loads the plugin contained in $file

Parameters
string$file
Returns
Plugin
Exceptions

Implements PluginLoader.

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

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