From a62f502ef06761858fdbbc36a1ac5000136f55bb Mon Sep 17 00:00:00 2001 From: 64FF00 <64ff00@gmail.com> Date: Sun, 21 Dec 2014 21:00:58 +0900 Subject: [PATCH] Multiworld Support + Customizable chat formats --- plugin.yml | 2 +- resources/config.yml | 16 +++++++++- src/_64FF00/PureChat/ChatListener.php | 8 ++++- src/_64FF00/PureChat/Configuration.php | 44 -------------------------- src/_64FF00/PureChat/PureChat.php | 23 +++++++------- 5 files changed, 35 insertions(+), 58 deletions(-) delete mode 100644 src/_64FF00/PureChat/Configuration.php diff --git a/plugin.yml b/plugin.yml index d78a6b9..bc0cacb 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,6 +1,6 @@ name: PureChat main: _64FF00\PureChat\PureChat -version: "1.0.0" +version: "1.1.0" api: [1.9.0] load: STARTUP author: 64FF00 diff --git a/resources/config.yml b/resources/config.yml index fee89e5..b5981fa 100644 --- a/resources/config.yml +++ b/resources/config.yml @@ -1,3 +1,17 @@ --- -chat-format: "<[%group%] %user_name%}> %message%" +# Allows you to use per-world chat formats +# - true / false +enable-multiworld-formats: false + +# A list of all PurePerms groups +groups: + Guest: + default: "[Guest] %user_name% > %message%" + worlds: [] + Admin: + default: "[Admin] %user_name% > %message%" + worlds: [] + Owner: + default: "[Owner] %user_name% > %message%" + worlds: [] ... \ No newline at end of file diff --git a/src/_64FF00/PureChat/ChatListener.php b/src/_64FF00/PureChat/ChatListener.php index da58cd5..426ce64 100644 --- a/src/_64FF00/PureChat/ChatListener.php +++ b/src/_64FF00/PureChat/ChatListener.php @@ -19,6 +19,8 @@ class ChatListener implements Listener { + private $plugin; + public function __construct(PureChat $plugin) { $this->plugin = $plugin; @@ -28,7 +30,11 @@ public function onPlayerChat(PlayerChatEvent $event) { $player = $event->getPlayer(); - $chatFormat = $this->plugin->formatMessage($player, $event->getMessage()); + $isMultiWorldFormatsEnabled = $this->plugin->getConfig()->get("enable-multiworld-formats"); + + $levelName = $isMultiWorldFormatsEnabled ? $player->getLevel()->getName() : null; + + $chatFormat = $this->plugin->formatMessage($player, $event->getMessage(), $levelName); $event->setFormat($chatFormat); } diff --git a/src/_64FF00/PureChat/Configuration.php b/src/_64FF00/PureChat/Configuration.php deleted file mode 100644 index 7e4a9f5..0000000 --- a/src/_64FF00/PureChat/Configuration.php +++ /dev/null @@ -1,44 +0,0 @@ -plugin = $plugin; - - $this->loadConfig(); - } - - public function getValue($key) - { - $value = $this->config->get($key); - - if($value === null) - { - $this->plugin->getLogger()->warning("Key $key not found in config.yml."); - - return null; - } - - return $value; - } - - public function loadConfig() - { - $this->plugin->saveDefaultConfig(); - - $this->config = $this->plugin->getConfig(); - } - - public function reloadConfig() - { - $this->plugin->reloadConfig(); - - $this->loadConfig(); - } -} \ No newline at end of file diff --git a/src/_64FF00/PureChat/PureChat.php b/src/_64FF00/PureChat/PureChat.php index 780d9b0..d89c5a4 100644 --- a/src/_64FF00/PureChat/PureChat.php +++ b/src/_64FF00/PureChat/PureChat.php @@ -23,7 +23,7 @@ class PureChat extends PluginBase public function onLoad() { - $this->config = new Configuration($this); + $this->saveDefaultConfig(); } public function onEnable() @@ -33,22 +33,23 @@ public function onEnable() $this->getServer()->getPluginManager()->registerEvents(new ChatListener($this), $this); } - public function formatMessage(Player $player, $message) + public function formatMessage(Player $player, $message, $levelName = null) { - $chatFormat = $this->config->getValue("chat-format"); + $groupName = $this->plugin->getUser($player)->getGroup($levelName)->getName(); - $isMultiWorldPermsEnabled = $this->plugin->getPPConfig()->getValue("enable-multiworld-perms"); - - $levelName = $isMultiWorldPermsEnabled ? $player->getLevel()->getName() : null; + if($levelName == null) + { + $chatFormat = $this->getConfig()->getNested("groups.$groupName.default"); + } + else + { + $chatFormat = $this->getConfig()->getNested("groups.$groupName.worlds.$levelName"); + } $chatFormat = str_replace("%world_name%", $levelName, $chatFormat); - $chatFormat = str_replace("%user_name%", $player->getName(), $chatFormat); + $chatFormat = str_replace("%user_name%", $player->getName(), $chatFormat); $chatFormat = str_replace("%message%", $message, $chatFormat); - $group = $this->plugin->getUser($player)->getGroup($levelName); - - $chatFormat = str_replace("%group%", $group->getName(), $chatFormat); - return $chatFormat; }