[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.

  • Verify that EssentialsPE is working:

    • The getPlugin() function can return false or a Plugin Object so we will check it with anticipation.

      • First checkout that the value of the variable (returned by the getPlugin() function) is a Plugin Object:

      • Then let's check if the Plugin Object has been enabled by PocketMine:

  • Add the returning values:

    • At this point we will add the specific values to be returned. A false value if EssentialsPE is not available, or the EssentialsPE API if it is available.

  • 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 generated getEssentialsPEAPI() function!

=

NOTE: Remember to always check if the getEssentialsPEAPI() function doesn't equal to false to be able to use the API correctly, else the server will crash