Skip to content

PluginAPI

Ace Sobremont edited this page Apr 6, 2025 · 5 revisions

PluginAPI for Plugin Developers

PluginAPI is essential if you're creating a plugin that affects gameplay in any way, whether it's block breaking, exploits, or any features that might trigger flags in Zuri.

Getting started with PluginAPI to your plugin

You need to import these following class:

use ReinfyTeam\Zuri\API;

Once the API is imported, you can use the following functions available to your plugin:

List of all methods

You may see them on API.php

List of events are that used in PluginAPI

To create your own event listener, here’s an example of how to do it:

  1. CheckFailedEvent: When player failed a module.. Here's breif example:
    //...
    
    public function onFail(CheckFailedEvent $event) : void {
    	$playerAPI = $event->getPlayer();
    	$api = $event->getAPI();
    	
    	$playerAPI->getPlayer()->sendMessage($event->getSupplier() . " " . "(" . $event->getSubType() . ") has been canceled due to test.");
    	$event->cancel(); // cancel the failure...
    } 
    
    //...

Tutorials

These are the Tutorials on how to use PluginAPI to your plugin:

Getting the PlayerAPI

To get the PlayerAPI instance, all you need to do is call this function:

$player = API::getPlayer(<string|pocketmine\player\Player class>);

Getting a module using name and subtype

To get the module, you can use these functions:

$module = API::getModule(<module_name: (cAse SeNsItIvE) ex. Speed>, <subType: ex. A>); // returns null when module is not found.
$module->enabled = false; // disable the module.

Get all modules that are registered in Zuri

To do this, all you need to do is:

$modules = API::getAllModules(); // returns array of modules in class

// ex. display them all
foreach($modules as $module) {
	$this->getLogger()->info($module->getName() . " " . $module->getSubType());
}

Get all Module Informations

$info = API::allModulesInfo(); // returns array of modules in strings

// ex. display them all
foreach($modules as $module) {
	$this->getLogger()->info($info["name"] . " " . $info["subType"]);
}

Get the Plugin Instance

If you want to access the Zuri PluginBase just use:

$plugin = API::getPluginInstance(); // returns Zuri PluginBase if it is enabled.

Digging of Special Players

If the server you are using a method intended for the digging of special players:

// $player must instance of Player from PMMP //
$player = API::getPlayer($player);
$api->setAttackSpecial(< true or false >);
$api->setBlocksBrokeASec(< it must is number >);

Getting config from Zuri

To get ConfigManager instance, just use:

$config = API::getConfig();
// example:
$message = $config->getData($config::PREFIX . " Hello world!"); 
$player->sendMessage($message);

To get discord webhook config, just use:

$config = API::getDiscordWebhookConfig();