My issue is I want to have a cache of spawnpoints somewhere in code or a config file. What is the best way for two plugins to reference this same info? My first thought is as static list, but will it compile? Or perhaps they can reference the same config file? Another thought is that I could have a separate plugin for storing global information between plugins, and use a "get plugin" method to get this. Before going further, I wanted to send a feeler out for who else has ran into this issue and how it was solved. Thanks in advance!
Making a variable static works in the old api but not in the current one. The best method is to make a variable public. To get the value of the variable you get the object of the other plugin with the function $this->getServer()->getPluginManager()->getPlugin($pluginName) and get the variable from that object with "->". For example, plugin 2 will display the variable $sharedData of plugin 1: PHP: <?phpnamespace Plugin1;use pocketmine\plugin\PluginBase;class MainClass extends PluginBase{ public $sharedData = "PocketMine rocks!";} PHP: <?phpnamespace Plugin2;use pocketmine\plugin\PluginBase;class MainClass extends PluginBase{ public function onEnable(){ $sharedData = $this->getServer()->getPluginManager()->getPlugin("Plugin1")->sharedData; $this->getLogger()->info("The shared data of plugin1: ".$msg); }} You can also change the value of the public variable in another plugin: PHP: $this->getServer()->getPluginManager()->getPlugin("Plugin1")->sharedData = "I <3 bacon";
The most stable method is to directly pass the PluginBase object to all classes, but this only works well when you are in the same plugin.
Well, you learn something new every day. I personally would have used a database or config to pass data between two plugins, (though those are not very good at storing objects ).