[Tutorial] How to access EssentialsPE's API withPocketMine MP - LegendOfMCPE/EssentialsPE GitHub Wiki
PocketMine-MP allow plugin developers to make their own API inside a plugin format and let other developers access that API, it seems tricky but its pretty easy to use once you know how to.
Let's use a simple example and go Step by Step.
=
NOTE:
You should add the softdepent
property inside the Plugin.yml
file of your plugin, so Pocketmine will be able to see that your plugin can use EssentialsPE:
Also you will need to import EssentialsPE's PHAR file (or just the Loader.php
) into your IDE's external libraries to make it easier to work with.
=
- Create a new function on your Main PHP class, called
getEssentialsPEAPI()
:
- Create the base variable:
- Lets create a variable that uses PocketMine's
getPlugin()
function.
- Lets create a variable that uses PocketMine's
-
Verify that
EssentialsPE
is working:-
The
getPlugin()
function can returnfalse
or aPlugin Object
so we will check it with anticipation.- First checkout that the value of the variable (returned by the
getPlugin()
function) is aPlugin Object
:
- Then let's check if the
Plugin Object
has been enabled by PocketMine:
- First checkout that the value of the variable (returned by the
-
-
Add the returning values:
- At this point we will add the specific values to be returned. A
false
value ifEssentialsPE
is not available, or theEssentialsPE
API if it is available.
- At this point we will add the specific values to be returned. A
- Specify the values to be returned:
- The PHP Comments allow the code to understand its own functions, to see what Parameters it requires and what type of values it could return.
- Enjoy the API!
- Now you will be able to use
EssentialsPE
's API by calling the newly generatedgetEssentialsPEAPI()
function!
- Now you will be able to use
=