From 955833b337736ace206eaa7418bc3713d7853499 Mon Sep 17 00:00:00 2001 From: DemonicDev <61244099+DemonicDev@users.noreply.github.com> Date: Sat, 10 Jun 2023 20:59:01 +0200 Subject: [PATCH 1/3] Bump to API5 This Update brings PureChat to Pocketmine 5 --- plugin.yml | 6 +- src/_64FF00/PureChat/ChatFormat.php | 236 ++++++++++++++++++++++++++++ src/_64FF00/PureChat/PCListener.php | 7 +- src/_64FF00/PureChat/PureChat.php | 140 +++++++++-------- 4 files changed, 320 insertions(+), 69 deletions(-) create mode 100644 src/_64FF00/PureChat/ChatFormat.php diff --git a/plugin.yml b/plugin.yml index 88a0fc3..cb02a3b 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,9 +1,11 @@ name: PureChat main: _64FF00\PureChat\PureChat -version: 2.0.2 -api: [4.0.0] +version: 2.0.3 +api: [5.0.0] load: POSTWORLD author: [Vecnavium , 64FF00] +authors: + - "DemonicDev (bump to API5)" depend: [PurePerms] softdepend: [FactionsPro, XeviousPE-Factions] commands: diff --git a/src/_64FF00/PureChat/ChatFormat.php b/src/_64FF00/PureChat/ChatFormat.php new file mode 100644 index 0000000..47f334f --- /dev/null +++ b/src/_64FF00/PureChat/ChatFormat.php @@ -0,0 +1,236 @@ +PureChat = $PureChat; + $this->player = $player; + $this->WorldName = $WorldName; + $this->format("", $message); + } + + public function format($username, $message): Translatable|string{ + $msg = $this->getChatFormat($this->player, $message, $this->WorldName); + return $msg; + } + + public function getNametag(Player $player, ?string $WorldName = null): string + { + $originalNametag = $this->getOriginalNametag($player, $WorldName); + $nameTag = $this->applyColors($originalNametag); + $nameTag = $this->applyPCTags($nameTag, $player, null, $WorldName); + return $nameTag; + } + + + + public function getOriginalNametag(Player $player, ?string $WorldName = null): string + { + /** @var \_64FF00\PurePerms\PPGroup $group */ + $group = $this->PureChat->getPurePerms()->getUserDataMgr()->getGroup($player, $WorldName); + if($WorldName === null) + { + $originalNametag = $this->PureChat->getthisConfig()->getNested("groups." . $group->getName() . ".nametag"); + if(!is_string($originalNametag)) + { + $this->getLogger()->critical("Invalid nametag found in config.yml (Group: " . $group->getName() . ") / Setting it to default value."); + $this->PureChat->getthisConfig()->setNested("groups." . $group->getName() . ".nametag", $originalNametag = "&8&l[" . $group->getName() . "]&f&r {display_name}"); + $this->PureChat->getthisConfig()->save(); + $this->PureChat->getthisConfig()->reload(); + } + return $originalNametag; + } + else + { + $originalNametag = $this->PureChat->getthisConfig()->getNested("groups." . $group->getName() . "worlds.$WorldName.nametag"); + if(!is_string(($originalNametag))) + { + $this->getLogger()->critical("Invalid nametag found in config.yml (Group: " . $group->getName() . ", WorldName = $WorldName) / Setting it to default value."); + $this->PureChat->getthisConfig()->setNested("groups." . $group->getName() . "worlds.$WorldName.nametag", $originalNametag = "&8&l[" . $group->getName() . "]&f&r {display_name}"); + $this->PureChat->getthisConfig()->save(); + $this->PureChat->getthisConfig()->reload(); + } + return $originalNametag; + } + } + + public function getPrefix(Player $player, ?string $WorldName = null): string + { + if($WorldName === null) + { + $prefix = $this->PureChat->getPurePerms()->getUserDataMgr()->getNode($player, "prefix"); + return is_string($prefix) ? $prefix : ''; + } + else + { + $worldData = $this->PureChat->getPurePerms()->getUserDataMgr()->getWorldData($player, $WorldName); + if(!isset($worldData["prefix"]) || !is_string($worldData["prefix"])) + return ""; + return $worldData["prefix"]; + } + } + + public function getSuffix(Player $player, ?string $WorldName = null): string + { + if($WorldName === null) + { + $suffix = $this->PureChat->getPurePerms()->getUserDataMgr()->getNode($player, "suffix"); + return is_string($suffix) ? $suffix : ''; + } + else + { + $worldData = $this->PureChat->getPurePerms()->getUserDataMgr()->getWorldData($player, $WorldName); + + if(!isset($worldData["suffix"]) || !is_string($worldData["suffix"])) + return ""; + return $worldData["suffix"]; + } + } + + public function setOriginalChatFormat(PPGroup $group, string $chatFormat, ?string $WorldName = null): bool + { + if($WorldName === null) + { + $this->PureChat->getthisConfig()->setNested("groups." . $group->getName() . ".chat", $chatFormat); + } + else + { + $this->PureChat->getthisConfig()->setNested("groups." . $group->getName() . "worlds.$WorldName.chat", $chatFormat); + } + $this->PureChat->getthisConfig()->save(); + $this->PureChat->getthisConfig()->reload(); + return true; + } + + public function setOriginalNametag(PPGroup $group, string $nameTag, ?string $WorldName = null): bool + { + if($WorldName === null) + { + $this->PureChat->getthisConfig()->setNested("groups." . $group->getName() . ".nametag", $nameTag); + } + else + { + $this->PureChat->getthisConfig()->setNested("groups." . $group->getName() . "worlds.$WorldName.nametag", $nameTag); + } + $this->PureChat->getthisConfig()->save(); + $this->PureChat->getthisConfig()->reload(); + return true; + } + + public function setPrefix(string $prefix, Player $player, ?string $WorldName = null): bool + { + if($WorldName === null) + { + $this->PureChat->getPurePerms()->getUserDataMgr()->setNode($player, "prefix", $prefix); + } + else + { + $worldData = $this->PureChat->getPurePerms()->getUserDataMgr()->getWorldData($player, $WorldName); + $worldData["prefix"] = $prefix; + $this->PureChat->getPurePerms()->getUserDataMgr()->setWorldData($player, $WorldName, $worldData); + } + + return true; + } + + public function setSuffix(string $suffix, Player $player, ?string $WorldName = null): bool + { + if($WorldName === null) + { + $this->PureChat->getPurePerms()->getUserDataMgr()->setNode($player, "suffix", $suffix); + } + else + { + $worldData = $this->PureChat->getPurePerms()->getUserDataMgr()->getWorldData($player, $WorldName); + $worldData["suffix"] = $suffix; + $this->PureChat->getPurePerms()->getUserDataMgr()->setWorldData($player, $WorldName, $worldData); + } + + return true; + } + + public function stripColors(string $string): string + { + return TextFormat::clean($string); + } + + public function applyColors(string $string): string + { + return TextFormat::colorize($string); + } + + public function applyPCTags(string $string, Player $player, ?string $message, ?string $WorldName): string + { + // TODO + $string = str_replace("{display_name}", $player->getDisplayName(), $string); + if($message === null) + $message = ""; + if($player->hasPermission("pchat.coloredMessages")) + { + $string = str_replace("{msg}", $this->applyColors($message), $string); + } + else + { + $string = str_replace("{msg}", $this->stripColors($message), $string); + } + { + $string = str_replace("{fac_name}", '', $string); + $string = str_replace("{fac_rank}", '', $string); + } + $string = str_replace("{world}", ($WorldName === null ? "" : $WorldName), $string); + $string = str_replace("{prefix}", $this->getPrefix($player, $WorldName), $string); + $string = str_replace("{suffix}", $this->getSuffix($player, $WorldName), $string); + return $string; + } + public function getChatFormat(Player $player, ?string $message, ?string $WorldName = null): string + { + $originalChatFormat = $this->getOriginalChatFormat($player, $WorldName); + $chatFormat = $this->applyColors($originalChatFormat); + $chatFormat = $this->applyPCTags($chatFormat, $player, $message, $WorldName); + return $chatFormat; + } + public function getOriginalChatFormat(Player $player, ?string $WorldName = null): string + { + /** @var \_64FF00\PurePerms\PPGroup $group */ + $group = $this->PureChat->getPurePerms()->getUserDataMgr()->getGroup($player, $WorldName); + if($WorldName === null) + { + $originalChatFormat = $this->PureChat->getthisConfig()->getNested("groups." . $group->getName() . ".chat"); + if(!is_string($originalChatFormat)) + { + $this->getLogger()->critical("Invalid chat format found in config.yml (Group: " . $group->getName() . ") / Setting it to default value."); + $this->PureChat->getthisConfig()->setNested("groups." . $group->getName() . ".chat", $originalChatFormat = "&8&l[" . $group->getName() . "]&f&r {display_name} &7> {msg}"); + $this->PureChat->getthisConfig()->save(); + $this->PureChat->getthisConfig()->reload(); + } + + return $originalChatFormat; + } + else + { + $originalChatFormat = $this->PureChat->getthisConfig()->getNested("groups." . $group->getName() . "worlds.$WorldName.chat"); + if(!is_string($originalChatFormat)) + { + $this->getLogger()->critical("Invalid chat format found in config.yml (Group: " . $group->getName() . ", WorldName = $WorldName) / Setting it to default value."); + $this->PureChat->getthisConfig()->setNested("groups." . $group->getName() . "worlds.$WorldName.chat", $originalChatFormat = "&8&l[" . $group->getName() . "]&f&r {display_name} &7> {msg}"); + $this->PureChat->getthisConfig()->save(); + $this->PureChat->getthisConfig()->reload(); + } + + return $originalChatFormat; + } + } + +} \ No newline at end of file diff --git a/src/_64FF00/PureChat/PCListener.php b/src/_64FF00/PureChat/PCListener.php index 7d78674..60754e1 100644 --- a/src/_64FF00/PureChat/PCListener.php +++ b/src/_64FF00/PureChat/PCListener.php @@ -8,7 +8,7 @@ use pocketmine\event\player\PlayerJoinEvent; use pocketmine\player\IPlayer; use pocketmine\player\Player; - +use _64FF00\PureChat\ChatFormat; class PCListener implements Listener { /* @@ -69,7 +69,8 @@ public function onPlayerChat(PlayerChatEvent $event) $player = $event->getPlayer(); $message = $event->getMessage(); $WorldName = $this->plugin->getConfig()->get("enable-multiworld-chat") ? $player->getWorld()->getDisplayName() : null; - $chatFormat = $this->plugin->getChatFormat($player, $message, $WorldName); - $event->setFormat($chatFormat); + $ChatFormat = new ChatFormat($player, $message, $WorldName, $this->plugin); + $event->setFormatter($ChatFormat); } + } diff --git a/src/_64FF00/PureChat/PureChat.php b/src/_64FF00/PureChat/PureChat.php index ab5820e..c0b2fda 100644 --- a/src/_64FF00/PureChat/PureChat.php +++ b/src/_64FF00/PureChat/PureChat.php @@ -32,6 +32,13 @@ class PureChat extends PluginBase private Config $config; private PurePerms $purePerms; + public function getPurePerms(){ + return $this->purePerms; + } + public function getthisConfig(){ + return $this->config; + } + public function onLoad(): void { @@ -234,42 +241,8 @@ private function fixOldData(string $string): string 888 888 d88P 888 888 8888888 */ - public function applyColors(string $string): string - { - return TextFormat::colorize($string); - } - public function applyPCTags(string $string, Player $player, ?string $message, ?string $WorldName): string - { - // TODO - $string = str_replace("{display_name}", $player->getDisplayName(), $string); - if($message === null) - $message = ""; - if($player->hasPermission("pchat.coloredMessages")) - { - $string = str_replace("{msg}", $this->applyColors($message), $string); - } - else - { - $string = str_replace("{msg}", $this->stripColors($message), $string); - } - { - $string = str_replace("{fac_name}", '', $string); - $string = str_replace("{fac_rank}", '', $string); - } - $string = str_replace("{world}", ($WorldName === null ? "" : $WorldName), $string); - $string = str_replace("{prefix}", $this->getPrefix($player, $WorldName), $string); - $string = str_replace("{suffix}", $this->getSuffix($player, $WorldName), $string); - return $string; - } - public function getChatFormat(Player $player, ?string $message, ?string $WorldName = null): string - { - $originalChatFormat = $this->getOriginalChatFormat($player, $WorldName); - $chatFormat = $this->applyColors($originalChatFormat); - $chatFormat = $this->applyPCTags($chatFormat, $player, $message, $WorldName); - return $chatFormat; - } public function getNametag(Player $player, ?string $WorldName = null): string { @@ -279,37 +252,7 @@ public function getNametag(Player $player, ?string $WorldName = null): string return $nameTag; } - public function getOriginalChatFormat(Player $player, ?string $WorldName = null): string - { - /** @var \_64FF00\PurePerms\PPGroup $group */ - $group = $this->purePerms->getUserDataMgr()->getGroup($player, $WorldName); - if($WorldName === null) - { - $originalChatFormat = $this->config->getNested("groups." . $group->getName() . ".chat"); - if(!is_string($originalChatFormat)) - { - $this->getLogger()->critical("Invalid chat format found in config.yml (Group: " . $group->getName() . ") / Setting it to default value."); - $this->config->setNested("groups." . $group->getName() . ".chat", $originalChatFormat = "&8&l[" . $group->getName() . "]&f&r {display_name} &7> {msg}"); - $this->config->save(); - $this->config->reload(); - } - return $originalChatFormat; - } - else - { - $originalChatFormat = $this->config->getNested("groups." . $group->getName() . "worlds.$WorldName.chat"); - if(!is_string($originalChatFormat)) - { - $this->getLogger()->critical("Invalid chat format found in config.yml (Group: " . $group->getName() . ", WorldName = $WorldName) / Setting it to default value."); - $this->config->setNested("groups." . $group->getName() . "worlds.$WorldName.chat", $originalChatFormat = "&8&l[" . $group->getName() . "]&f&r {display_name} &7> {msg}"); - $this->config->save(); - $this->config->reload(); - } - - return $originalChatFormat; - } - } public function getOriginalNametag(Player $player, ?string $WorldName = null): string { @@ -440,4 +383,73 @@ public function stripColors(string $string): string { return TextFormat::clean($string); } + + public function applyColors(string $string): string + { + return TextFormat::colorize($string); + } + + public function applyPCTags(string $string, Player $player, ?string $message, ?string $WorldName): string + { + // TODO + $string = str_replace("{display_name}", $player->getDisplayName(), $string); + if($message === null) + $message = ""; + if($player->hasPermission("pchat.coloredMessages")) + { + $string = str_replace("{msg}", $this->applyColors($message), $string); + } + else + { + $string = str_replace("{msg}", $this->stripColors($message), $string); + } + { + $string = str_replace("{fac_name}", '', $string); + $string = str_replace("{fac_rank}", '', $string); + } + $string = str_replace("{world}", ($WorldName === null ? "" : $WorldName), $string); + $string = str_replace("{prefix}", $this->getPrefix($player, $WorldName), $string); + $string = str_replace("{suffix}", $this->getSuffix($player, $WorldName), $string); + return $string; + } + public function getChatFormat(Player $player, ?string $message, ?string $WorldName = null): string + { + $originalChatFormat = $this->getOriginalChatFormat($player, $WorldName); + $chatFormat = $this->applyColors($originalChatFormat); + $chatFormat = $this->applyPCTags($chatFormat, $player, $message, $WorldName); + return $chatFormat; + } + public function getOriginalChatFormat(Player $player, ?string $WorldName = null): string + { + /** @var \_64FF00\PurePerms\PPGroup $group */ + $group = $this->purePerms->getUserDataMgr()->getGroup($player, $WorldName); + if($WorldName === null) + { + $originalChatFormat = $this->config->getNested("groups." . $group->getName() . ".chat"); + if(!is_string($originalChatFormat)) + { + $this->getLogger()->critical("Invalid chat format found in config.yml (Group: " . $group->getName() . ") / Setting it to default value."); + $this->config->setNested("groups." . $group->getName() . ".chat", $originalChatFormat = "&8&l[" . $group->getName() . "]&f&r {display_name} &7> {msg}"); + $this->config->save(); + $this->config->reload(); + } + + return $originalChatFormat; + } + else + { + $originalChatFormat = $this->config->getNested("groups." . $group->getName() . "worlds.$WorldName.chat"); + if(!is_string($originalChatFormat)) + { + $this->getLogger()->critical("Invalid chat format found in config.yml (Group: " . $group->getName() . ", WorldName = $WorldName) / Setting it to default value."); + $this->config->setNested("groups." . $group->getName() . "worlds.$WorldName.chat", $originalChatFormat = "&8&l[" . $group->getName() . "]&f&r {display_name} &7> {msg}"); + $this->config->save(); + $this->config->reload(); + } + + return $originalChatFormat; + } + } + + } From a015eb2c55730dd17908f6a28f3c67500b637758 Mon Sep 17 00:00:00 2001 From: DemonicDev <61244099+DemonicDev@users.noreply.github.com> Date: Sat, 10 Jun 2023 21:04:25 +0200 Subject: [PATCH 2/3] removes useless code from ChatFormat.php --- plugin.yml | 2 +- src/_64FF00/PureChat/ChatFormat.php | 99 ----------------------------- 2 files changed, 1 insertion(+), 100 deletions(-) diff --git a/plugin.yml b/plugin.yml index cb02a3b..443d92a 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,6 +1,6 @@ name: PureChat main: _64FF00\PureChat\PureChat -version: 2.0.3 +version: 2.1.1 api: [5.0.0] load: POSTWORLD author: [Vecnavium , 64FF00] diff --git a/src/_64FF00/PureChat/ChatFormat.php b/src/_64FF00/PureChat/ChatFormat.php index 47f334f..712d332 100644 --- a/src/_64FF00/PureChat/ChatFormat.php +++ b/src/_64FF00/PureChat/ChatFormat.php @@ -26,46 +26,8 @@ public function format($username, $message): Translatable|string{ return $msg; } - public function getNametag(Player $player, ?string $WorldName = null): string - { - $originalNametag = $this->getOriginalNametag($player, $WorldName); - $nameTag = $this->applyColors($originalNametag); - $nameTag = $this->applyPCTags($nameTag, $player, null, $WorldName); - return $nameTag; - } - - public function getOriginalNametag(Player $player, ?string $WorldName = null): string - { - /** @var \_64FF00\PurePerms\PPGroup $group */ - $group = $this->PureChat->getPurePerms()->getUserDataMgr()->getGroup($player, $WorldName); - if($WorldName === null) - { - $originalNametag = $this->PureChat->getthisConfig()->getNested("groups." . $group->getName() . ".nametag"); - if(!is_string($originalNametag)) - { - $this->getLogger()->critical("Invalid nametag found in config.yml (Group: " . $group->getName() . ") / Setting it to default value."); - $this->PureChat->getthisConfig()->setNested("groups." . $group->getName() . ".nametag", $originalNametag = "&8&l[" . $group->getName() . "]&f&r {display_name}"); - $this->PureChat->getthisConfig()->save(); - $this->PureChat->getthisConfig()->reload(); - } - return $originalNametag; - } - else - { - $originalNametag = $this->PureChat->getthisConfig()->getNested("groups." . $group->getName() . "worlds.$WorldName.nametag"); - if(!is_string(($originalNametag))) - { - $this->getLogger()->critical("Invalid nametag found in config.yml (Group: " . $group->getName() . ", WorldName = $WorldName) / Setting it to default value."); - $this->PureChat->getthisConfig()->setNested("groups." . $group->getName() . "worlds.$WorldName.nametag", $originalNametag = "&8&l[" . $group->getName() . "]&f&r {display_name}"); - $this->PureChat->getthisConfig()->save(); - $this->PureChat->getthisConfig()->reload(); - } - return $originalNametag; - } - } - public function getPrefix(Player $player, ?string $WorldName = null): string { if($WorldName === null) @@ -99,67 +61,6 @@ public function getSuffix(Player $player, ?string $WorldName = null): string } } - public function setOriginalChatFormat(PPGroup $group, string $chatFormat, ?string $WorldName = null): bool - { - if($WorldName === null) - { - $this->PureChat->getthisConfig()->setNested("groups." . $group->getName() . ".chat", $chatFormat); - } - else - { - $this->PureChat->getthisConfig()->setNested("groups." . $group->getName() . "worlds.$WorldName.chat", $chatFormat); - } - $this->PureChat->getthisConfig()->save(); - $this->PureChat->getthisConfig()->reload(); - return true; - } - - public function setOriginalNametag(PPGroup $group, string $nameTag, ?string $WorldName = null): bool - { - if($WorldName === null) - { - $this->PureChat->getthisConfig()->setNested("groups." . $group->getName() . ".nametag", $nameTag); - } - else - { - $this->PureChat->getthisConfig()->setNested("groups." . $group->getName() . "worlds.$WorldName.nametag", $nameTag); - } - $this->PureChat->getthisConfig()->save(); - $this->PureChat->getthisConfig()->reload(); - return true; - } - - public function setPrefix(string $prefix, Player $player, ?string $WorldName = null): bool - { - if($WorldName === null) - { - $this->PureChat->getPurePerms()->getUserDataMgr()->setNode($player, "prefix", $prefix); - } - else - { - $worldData = $this->PureChat->getPurePerms()->getUserDataMgr()->getWorldData($player, $WorldName); - $worldData["prefix"] = $prefix; - $this->PureChat->getPurePerms()->getUserDataMgr()->setWorldData($player, $WorldName, $worldData); - } - - return true; - } - - public function setSuffix(string $suffix, Player $player, ?string $WorldName = null): bool - { - if($WorldName === null) - { - $this->PureChat->getPurePerms()->getUserDataMgr()->setNode($player, "suffix", $suffix); - } - else - { - $worldData = $this->PureChat->getPurePerms()->getUserDataMgr()->getWorldData($player, $WorldName); - $worldData["suffix"] = $suffix; - $this->PureChat->getPurePerms()->getUserDataMgr()->setWorldData($player, $WorldName, $worldData); - } - - return true; - } public function stripColors(string $string): string { From 42f0bd725c10c3d85662ffae8566bd0b895dbe04 Mon Sep 17 00:00:00 2001 From: DemonicDev <61244099+DemonicDev@users.noreply.github.com> Date: Sat, 10 Jun 2023 21:37:33 +0200 Subject: [PATCH 3/3] reduce useless/duplicated code this update reduces duplicated and useless code, this reduces the size of the Plugin and the size of ChatFormat.php. This should increase The Performance --- plugin.yml | 2 +- src/_64FF00/PureChat/ChatFormat.php | 111 +--------------------------- 2 files changed, 2 insertions(+), 111 deletions(-) diff --git a/plugin.yml b/plugin.yml index 443d92a..2b7cc78 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,6 +1,6 @@ name: PureChat main: _64FF00\PureChat\PureChat -version: 2.1.1 +version: 2.1.2 api: [5.0.0] load: POSTWORLD author: [Vecnavium , 64FF00] diff --git a/src/_64FF00/PureChat/ChatFormat.php b/src/_64FF00/PureChat/ChatFormat.php index 712d332..eb3d6c1 100644 --- a/src/_64FF00/PureChat/ChatFormat.php +++ b/src/_64FF00/PureChat/ChatFormat.php @@ -22,116 +22,7 @@ public function __construct($player, $message, $WorldName, $PureChat) } public function format($username, $message): Translatable|string{ - $msg = $this->getChatFormat($this->player, $message, $this->WorldName); + $msg = $this->PureChat->getChatFormat($this->player, $message, $this->WorldName); return $msg; } - - - - public function getPrefix(Player $player, ?string $WorldName = null): string - { - if($WorldName === null) - { - $prefix = $this->PureChat->getPurePerms()->getUserDataMgr()->getNode($player, "prefix"); - return is_string($prefix) ? $prefix : ''; - } - else - { - $worldData = $this->PureChat->getPurePerms()->getUserDataMgr()->getWorldData($player, $WorldName); - if(!isset($worldData["prefix"]) || !is_string($worldData["prefix"])) - return ""; - return $worldData["prefix"]; - } - } - - public function getSuffix(Player $player, ?string $WorldName = null): string - { - if($WorldName === null) - { - $suffix = $this->PureChat->getPurePerms()->getUserDataMgr()->getNode($player, "suffix"); - return is_string($suffix) ? $suffix : ''; - } - else - { - $worldData = $this->PureChat->getPurePerms()->getUserDataMgr()->getWorldData($player, $WorldName); - - if(!isset($worldData["suffix"]) || !is_string($worldData["suffix"])) - return ""; - return $worldData["suffix"]; - } - } - - - public function stripColors(string $string): string - { - return TextFormat::clean($string); - } - - public function applyColors(string $string): string - { - return TextFormat::colorize($string); - } - - public function applyPCTags(string $string, Player $player, ?string $message, ?string $WorldName): string - { - // TODO - $string = str_replace("{display_name}", $player->getDisplayName(), $string); - if($message === null) - $message = ""; - if($player->hasPermission("pchat.coloredMessages")) - { - $string = str_replace("{msg}", $this->applyColors($message), $string); - } - else - { - $string = str_replace("{msg}", $this->stripColors($message), $string); - } - { - $string = str_replace("{fac_name}", '', $string); - $string = str_replace("{fac_rank}", '', $string); - } - $string = str_replace("{world}", ($WorldName === null ? "" : $WorldName), $string); - $string = str_replace("{prefix}", $this->getPrefix($player, $WorldName), $string); - $string = str_replace("{suffix}", $this->getSuffix($player, $WorldName), $string); - return $string; - } - public function getChatFormat(Player $player, ?string $message, ?string $WorldName = null): string - { - $originalChatFormat = $this->getOriginalChatFormat($player, $WorldName); - $chatFormat = $this->applyColors($originalChatFormat); - $chatFormat = $this->applyPCTags($chatFormat, $player, $message, $WorldName); - return $chatFormat; - } - public function getOriginalChatFormat(Player $player, ?string $WorldName = null): string - { - /** @var \_64FF00\PurePerms\PPGroup $group */ - $group = $this->PureChat->getPurePerms()->getUserDataMgr()->getGroup($player, $WorldName); - if($WorldName === null) - { - $originalChatFormat = $this->PureChat->getthisConfig()->getNested("groups." . $group->getName() . ".chat"); - if(!is_string($originalChatFormat)) - { - $this->getLogger()->critical("Invalid chat format found in config.yml (Group: " . $group->getName() . ") / Setting it to default value."); - $this->PureChat->getthisConfig()->setNested("groups." . $group->getName() . ".chat", $originalChatFormat = "&8&l[" . $group->getName() . "]&f&r {display_name} &7> {msg}"); - $this->PureChat->getthisConfig()->save(); - $this->PureChat->getthisConfig()->reload(); - } - - return $originalChatFormat; - } - else - { - $originalChatFormat = $this->PureChat->getthisConfig()->getNested("groups." . $group->getName() . "worlds.$WorldName.chat"); - if(!is_string($originalChatFormat)) - { - $this->getLogger()->critical("Invalid chat format found in config.yml (Group: " . $group->getName() . ", WorldName = $WorldName) / Setting it to default value."); - $this->PureChat->getthisConfig()->setNested("groups." . $group->getName() . "worlds.$WorldName.chat", $originalChatFormat = "&8&l[" . $group->getName() . "]&f&r {display_name} &7> {msg}"); - $this->PureChat->getthisConfig()->save(); - $this->PureChat->getthisConfig()->reload(); - } - - return $originalChatFormat; - } - } - } \ No newline at end of file