From e792e1d9577b89e4e16718af99b7d2605cc19107 Mon Sep 17 00:00:00 2001 From: MohamadRZ4 <140262112+MohamadRZ4@users.noreply.github.com> Date: Sat, 29 Mar 2025 11:28:38 +0330 Subject: [PATCH] PlaceholderAPI is supported --- README.md | 1 + src/IvanCraft623/RankSystem/RankSystem.php | 6 ++ .../RankSystem/utils/PlaceholderUtils.php | 57 +++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 src/IvanCraft623/RankSystem/utils/PlaceholderUtils.php diff --git a/README.md b/README.md index c02784e..abeecdf 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ Examples and tutorials can be found on the [RankSystem Wiki](https://github.com/ - Multi-rank inheritance system to allow you to inherit rank permissions - Temp-ranks - Temp-permissions +- PlaceholderAPI Support - SQLite3 Provider Support - MySQL Provider Support - Easy Rank Creation / Edit System diff --git a/src/IvanCraft623/RankSystem/RankSystem.php b/src/IvanCraft623/RankSystem/RankSystem.php index 31c4333..7ef38dc 100644 --- a/src/IvanCraft623/RankSystem/RankSystem.php +++ b/src/IvanCraft623/RankSystem/RankSystem.php @@ -35,9 +35,11 @@ use IvanCraft623\RankSystem\provider\Provider; use IvanCraft623\RankSystem\provider\libasynql as libasynqlProvider; +use IvanCraft623\RankSystem\utils\PlaceholderUtils; use JackMD\ConfigUpdater\ConfigUpdater; use JackMD\UpdateNotifier\UpdateNotifier; +use MohamadRZ4\Placeholder\PlaceholderAPI; use pocketmine\permission\PermissionManager; use pocketmine\permission\DefaultPermissions; use pocketmine\plugin\DisablePluginException; @@ -81,6 +83,10 @@ public function onEnable() : void { PacketHooker::register($this); } + if ($this->getServer()->getPluginManager()->getPlugin("PlaceholderAPI") !== null) { + PlaceholderAPI::getInstance()->registerExpansion(new PlaceholderUtils($this)); + } + $this->loadCommands(); $this->loadListeners(); $this->loadProvider(); diff --git a/src/IvanCraft623/RankSystem/utils/PlaceholderUtils.php b/src/IvanCraft623/RankSystem/utils/PlaceholderUtils.php new file mode 100644 index 0000000..87a279e --- /dev/null +++ b/src/IvanCraft623/RankSystem/utils/PlaceholderUtils.php @@ -0,0 +1,57 @@ +rankSystem = $rankSystem; + } + + public function getIdentifier(): string + { + return "RankSystem"; + } + + public function getAuthor(): string + { + return "IvanCraft623"; + } + + public function getVersion(): string + { + return "1.0.0"; + } + + + public function onPlaceholderRequest(?Player $player, string $params): ?string + { + if ($player === null) return null; + + $ranksystem = $this->rankSystem; + $sessionmanager = $ranksystem->getSessionManager(); + + $session = $sessionmanager->get("IvanCraft236"); + if ($session === null) return null; + + switch ($params) { + case "ranks": + return implode(", ", $session->getRanks()); + case "highest_rank": + return $session->getHighestRank()->getName(); + case "nametag": + return $session->getNameTagFormat(); + default: + return null; + } + } +} \ No newline at end of file