diff --git a/plugin.yml b/plugin.yml new file mode 100644 index 0000000..d78a6b9 --- /dev/null +++ b/plugin.yml @@ -0,0 +1,8 @@ +name: PureChat +main: _64FF00\PureChat\PureChat +version: "1.0.0" +api: [1.9.0] +load: STARTUP +author: 64FF00 +website: https://github.com/64FF00/PureChat +depend: [PurePerms] \ No newline at end of file diff --git a/resources/config.yml b/resources/config.yml new file mode 100644 index 0000000..fee89e5 --- /dev/null +++ b/resources/config.yml @@ -0,0 +1,3 @@ +--- +chat-format: "<[%group%] %user_name%}> %message%" +... \ No newline at end of file diff --git a/src/_64FF00/PureChat/ChatListener.php b/src/_64FF00/PureChat/ChatListener.php new file mode 100644 index 0000000..da58cd5 --- /dev/null +++ b/src/_64FF00/PureChat/ChatListener.php @@ -0,0 +1,35 @@ +plugin = $plugin; + } + + public function onPlayerChat(PlayerChatEvent $event) + { + $player = $event->getPlayer(); + + $chatFormat = $this->plugin->formatMessage($player, $event->getMessage()); + + $event->setFormat($chatFormat); + } +} \ No newline at end of file diff --git a/src/_64FF00/PureChat/Configuration.php b/src/_64FF00/PureChat/Configuration.php new file mode 100644 index 0000000..7e4a9f5 --- /dev/null +++ b/src/_64FF00/PureChat/Configuration.php @@ -0,0 +1,44 @@ +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 new file mode 100644 index 0000000..780d9b0 --- /dev/null +++ b/src/_64FF00/PureChat/PureChat.php @@ -0,0 +1,58 @@ +config = new Configuration($this); + } + + public function onEnable() + { + $this->plugin = $this->getServer()->getPluginManager()->getPlugin("PurePerms"); + + $this->getServer()->getPluginManager()->registerEvents(new ChatListener($this), $this); + } + + public function formatMessage(Player $player, $message) + { + $chatFormat = $this->config->getValue("chat-format"); + + $isMultiWorldPermsEnabled = $this->plugin->getPPConfig()->getValue("enable-multiworld-perms"); + + $levelName = $isMultiWorldPermsEnabled ? $player->getLevel()->getName() : null; + + $chatFormat = str_replace("%world_name%", $levelName, $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; + } + + public function onDisable() + { + } +} \ No newline at end of file