Skip to content

Commit

Permalink
Added some files.
Browse files Browse the repository at this point in the history
  • Loading branch information
64FF00 committed Dec 13, 2014
1 parent 909b188 commit 1febbcc
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 0 deletions.
8 changes: 8 additions & 0 deletions plugin.yml
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]
3 changes: 3 additions & 0 deletions resources/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
chat-format: "<[%group%] %user_name%}> %message%"
...
35 changes: 35 additions & 0 deletions src/_64FF00/PureChat/ChatListener.php
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);
}
}
44 changes: 44 additions & 0 deletions src/_64FF00/PureChat/Configuration.php
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();
}
}
58 changes: 58 additions & 0 deletions src/_64FF00/PureChat/PureChat.php
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()
{
}
}

0 comments on commit 1febbcc

Please sign in to comment.