-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
64FF00
committed
Dec 13, 2014
1 parent
909b188
commit 1febbcc
Showing
5 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
chat-format: "<[%group%] %user_name%}> %message%" | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace _64FF00\PureChat; | ||
|
||
use pocketmine\event\Listener; | ||
|
||
use pocketmine\event\player\PlayerChatEvent; | ||
|
||
/* | ||
# # ##### # ####### ####### ### ### | ||
# # # # # # # # # # # # | ||
####### # # # # # # # # # | ||
# # ###### # # ##### ##### # # # # | ||
####### # # ####### # # # # # # | ||
# # # # # # # # # # # | ||
# # ##### # # # ### ### | ||
*/ | ||
|
||
class ChatListener implements Listener | ||
{ | ||
public function __construct(PureChat $plugin) | ||
{ | ||
$this->plugin = $plugin; | ||
} | ||
|
||
public function onPlayerChat(PlayerChatEvent $event) | ||
{ | ||
$player = $event->getPlayer(); | ||
|
||
$chatFormat = $this->plugin->formatMessage($player, $event->getMessage()); | ||
|
||
$event->setFormat($chatFormat); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
namespace _64FF00\PureChat; | ||
|
||
use pocketmine\utils\Config; | ||
|
||
class Configuration | ||
{ | ||
private $config; | ||
|
||
public function __construct(PureChat $plugin) | ||
{ | ||
$this->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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace _64FF00\PureChat; | ||
|
||
use pocketmine\Player; | ||
|
||
use pocketmine\plugin\PluginBase; | ||
|
||
/* | ||
# # ##### # ####### ####### ### ### | ||
# # # # # # # # # # # # | ||
####### # # # # # # # # # | ||
# # ###### # # ##### ##### # # # # | ||
####### # # ####### # # # # # # | ||
# # # # # # # # # # # | ||
# # ##### # # # ### ### | ||
*/ | ||
|
||
class PureChat extends PluginBase | ||
{ | ||
private $config, $plugin; | ||
|
||
public function onLoad() | ||
{ | ||
$this->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() | ||
{ | ||
} | ||
} |