Skip to content

PluginAPI

Ace Sobremont edited this page Jul 29, 2024 · 3 revisions

PluginAPI for Plugin Developers

PluginAPI is important if you make a plugin which has any affects to the gameplay including block breaking, exploits, or any kind of features that flags to the Zuri.

Getting started with PluginAPI to your plugin

You need to import these following class:

use ReinfyTeam\Zuri\API;

After API is imported, you can use the following functions that are available to 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 some example on 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();
    	
    	$player->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();