-
Notifications
You must be signed in to change notification settings - Fork 4
Developer API
supercrafter333 edited this page Oct 20, 2021
·
1 revision
theRankShop have a feature to add your own rank-management-plugin. On this page, you can see/learn how to add a custom rank-plugin.
- Create a basic plugin
- Create a file that implements
supercrafter333\theRankShop\Manager\RankManagementPlugin
The file should be have the following functions:
-
getRank(string $rankName): RankClass
- Return the class of a rank (in PurePerms: PPGroup) -
setRankOfPlayer(Player $player, string $rankName): bool
- Return bool (can set/cannot set) -
getRankOfPlayer(Player $player): ?string
- Return the rank-name of a player (own a rank and return the name/doesn't own a rank and return null) -
public function getRealPlugin(): Plugin
- Return the PluginBase-class of the rank plugin
public function onEnable(): void
{
RankManagementPluginMgr::setRankManagementClass(new PurePermsMgr()); //Set your RankManagementPlugin file a the new Rank-management-plugin
}
(PurePerms is already imported in theRankShop) Set your own class of RankManagementPlugin to the RankManagementPluginMgr (Mgr = Manager) to use your Rank-plugin.
<?php
namespace supercrafter333\theRankShop\Manager;
use _64FF00\PurePerms\PPGroup;
use _64FF00\PurePerms\PurePerms;
use pocketmine\Player;
use pocketmine\plugin\Plugin;
use pocketmine\Server;
/**
* PurePermsMgr class, implement RankManagementPlugin interface
*/
class PurePermsMgr implements RankManagementPlugin
{
/**
* @var PurePerms
*/
private $pureperms;
/**
* @var \_64FF00\PurePerms\data\UserDataManager
*/
private $ppUserMgr;
/**
*
*/
public function __construct()
{
$this->pureperms = Server::getInstance()->getPluginManager()->getPlugin("PurePerms");
$this->ppUserMgr = $this->pureperms->getUserDataMgr();
}
/**
* @param string $rankName
* @return null|PPGroup
*/
public function getRank(string $rankName): ?PPGroup
{
return $this->pureperms->getGroup($rankName);
}
/**
* @param Player $player
* @param string $rankName
* @return bool
*/
public function setRankOfPlayer(Player $player, string $rankName): bool
{
if (!$this->getRank($rankName) instanceof PPGroup) return false;
$this->ppUserMgr->setGroup($player, $this->getRank($rankName), null);
return true;
}
/**
* @param Player $player
* @return string|null
*/
public function getRankOfPlayer(Player $player): ?string
{
return $this->ppUserMgr->getGroup($player)->getName();
}
/**
* @return Plugin
*/
public function getRealPlugin(): Plugin
{
return Server::getInstance()->getPluginManager()->getPlugin("PurePerms");
}
}
I hope that this page can help you :)
Enjoy theRankShop!