Skip to content

The basics

Andre | xZeroMCPE edited this page Sep 27, 2020 · 2 revisions

1.) Firstly

Make sure you're using the latest version of PocketVault, ask your users to do the same too. The API is constantly being expanded, and some methods could be missing in previous versions.

2.) Check if PocketVault is installed/enabled

To utilize PocketVault API/its core, you should check if it's installed/enabled, I recommend you add a softdepend instead of a regular depend, so that way, you can show your own custom error message if PocketVault is not installed, instead of using depend, as you won't be able to do anything at all.

Let's add it to your plugin.yml, should look exactly like this:

name: TestPlugin
version: 1.0.0
api: 3.2.0
main: Test\TestPlugin
softdepend:
  - PocketVault

Now on your onEnable method, it should look something like this:

   public function onEnable()
    {
        if(($plugin = $this->getServer()->getPluginManager()->getPlugin("PocketVault")) !== null and $plugin->isEnabled()){
            /*
             * PocketVault is installed/enabled
             */
            // This is left empty
        } else {
            /*
             * PocketVault is not installed/disabled
             */
            $this->getLogger()->error("> Ouch, This plugin requires you to have PocketVault installed");
            $this->getLogger()->error("> This plugin will be disabled, download a copy of PocketVault via");
            $this->getLogger()->error("> https://www.github.com/xZeroMCPE/PocketVault");
            $this->setEnabled(false);
            return;
        }
        
    }

The good thing is that, you don't really have to include the softdepend, with that check above, it checks if it's installed/enabled, but it's always best to have that softdepend included.

Now proceed to the next page to start hooking into PocketVault