Skip to content

Commit

Permalink
Multiworld Support + Customizable chat formats
Browse files Browse the repository at this point in the history
  • Loading branch information
64FF00 committed Dec 21, 2014
1 parent 1febbcc commit a62f502
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 58 deletions.
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 15 additions & 1 deletion resources/config.yml
Original file line number Diff line number Diff line change
@@ -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: []
...
8 changes: 7 additions & 1 deletion src/_64FF00/PureChat/ChatListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

class ChatListener implements Listener
{
private $plugin;

public function __construct(PureChat $plugin)
{
$this->plugin = $plugin;
Expand All @@ -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);
}
Expand Down
44 changes: 0 additions & 44 deletions src/_64FF00/PureChat/Configuration.php

This file was deleted.

23 changes: 12 additions & 11 deletions src/_64FF00/PureChat/PureChat.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class PureChat extends PluginBase

public function onLoad()
{
$this->config = new Configuration($this);
$this->saveDefaultConfig();
}

public function onEnable()
Expand All @@ -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;
}

Expand Down

0 comments on commit a62f502

Please sign in to comment.