Hey there, how can I create an API for my own plugins (like Specter: http://forums.pocketmine.net/plugins/specter.894/) so that I can use the functions of this plugin in other plugins too? Thanks in advance.
if you know PHP, you can. PHP: public function functionNameOfAPI(){echo "my first API function is ran!";} and when doing PHP: $plugin = $this->getServer()->getPluginManager()->getPlugin("PluginName");$plugin->functionNameOfAPI(); will result on doing that echo in the function.
The way I do API uses functions too, but builds a different class in your plugin. Your API: PHP: <?phpnamespace SomePluginR;use pocketmine\plugin\PluginBase;class PluginAPI{ public function taskone($player){ $player->sendMessage("hi"); }}class SomePluginR extends PluginBase{} How others might use it (supposedly): PHP: <?phpnamespace SomeOtherPlugin;use pocketmine\plugin\PluginBase;use pocketmine\event\player\PlayerJoinEvent;use SomePluginR\SomePluginR;class SomeOtherPlugin extends PluginBase{ //suppose I registered $events($this,$this)... public function onJoin(PlayerJoinEvent $event){ $player = $event->getPlayer(); $mss = new PluginAPI(); $mss->taskone($player); return True; }}
Actually, if you have good OOP coding practices (at least I think it is good), you already have the API without noticing it. Take a look at the LegionPE plugin http://lgpe.co/tsrc - anyone can easily add a plugin to interact with the plugin using its public getters, setters and functions, although obviously I don't expect any other plugins to interact with it. This is because when you have written the code for a few months, you would completely forget about it. Only an API-style internal structure can allow you to know how to do what thing conveniently without re-reading the code. (Of course, you still need to do so if you are debugging, but the productivity is still much faster)