Skip to content

Commit

Permalink
Updated things, fixed commands, updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
Humerus committed Aug 29, 2016
1 parent ee67bc6 commit fa7a91c
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 16 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
LBChatFilter - A (not so) simple plugin for adding an awesome chat filter to your server
======
======

## This plugin allows a user to add a chatfilter to their server. The commands are simple:

| Command | Sub Command | User | Description |
|:-------:|:-----------:|:----:|:-----------:|
|`lbchatfilter`|`adduser`|`<name>`| Adds a player to the whitelist |
|`lbchatfilter`|`remuser`|`<name>`| Removes a player from the whitelist |
|`lbchatfilter`|`listusers`| | Lists players currently on the whitelist |
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ author: LBSG
description: Lifeboat ChatFilter Plugin For All
website: https://lbsg.net
commands:
lbantihacks:
lbchatfilter:
description: "Manages LBChatFilter"
aliases: [cf, chatfilter]
usage: "/lbchatfilter <command> <args>"
Expand Down
6 changes: 3 additions & 3 deletions resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ onlyOp: true

# Array of usernames to a whitelist
users:
humerusj
williamtdr
brandon15811
- humerusj
- williamtdr
- brandon15811
5 changes: 5 additions & 0 deletions src/ChatFilter/ChatFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public function __construct($enableMsgFrequency = true) {
$this->enableMessageFrequency = $enableMsgFrequency;
}

/**
* Clears the recent chat filter (for spam protection)
*
* @return null
*/
public function clearRecentChat() {
$this->recentChat = array();
}
Expand Down
42 changes: 31 additions & 11 deletions src/LBChatFilter/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
*/
class Main extends PluginBase implements Listener {

/**
* The main users array
*
* @var array
*/
public $users = [];

/**
* Loads the plugin
*
Expand Down Expand Up @@ -44,10 +51,13 @@ public function onEnable() {
return;
}

$this->users = $this->getConfig()->get('users');
foreach($this->getConfig()->get('users') as $v => $k) {
$this->users[] = $k;
}

/**
* Initalize the ChatFilter
*
* @type ChatFilter
*/
$this->filter = new ChatFilter();
Expand All @@ -70,33 +80,43 @@ public function onCommand(CommandSender $sender, Command $command, $label, array
$subcommand = strtolower(array_shift($args));
switch ($subcommand) {
case "adduser":
if(isset($args[1])) {
if(($player = $this->getServer()->getPlayerExact($args[1])) instanceof Player) {
if(isset($args[0])) {
if(($player = $this->getServer()->getPlayerExact($args[0])) instanceof Player) {
$this->users[] = $player->getDisplayName();
} else {
$this->users[] = $args[1];
$this->users[] = $args[0];
}
$sender->sendMessage(TextFormat::BLUE . '[LBChatFilter] Added user: ' . $args[0]);
return true;
} else {
return false;
}
break;
case "remuser":
if(isset($args[1])) {
if(($player = $this->getServer()->getPlayerExact($args[1])) instanceof Player) {
if(isset($this->users[$player->getDisplayName()]))
unset($this->users[$player->getDisplayName()]);
if(isset($args[0])) {
if(($player = $this->getServer()->getPlayerExact($args[0])) instanceof Player) {
if(($key = array_search($player->getDisplayName(), $this->users)) !== false)
unset($this->users[$key]);
} else {
if(isset($this->users[$args[1]]))
unset($this->users[$args[1]]);
if(($key = array_search($args[0], $this->users)) !== false)
unset($this->users[$key]);
}
$sender->sendMessage(TextFormat::RED . '[LBChatFilter] Removed user: ' . $args[0]);
return true;
} else {
return false;
}
break;
default:
case "listusers":
$sender->sendMessage(TextFormat::GREEN . '[LBChatFilter] Users on the whitelist: ' . implode(', ', $this->users));
return true;
break;
case "help":
$sender->sendMessage(TextFormat::GREEN . '[LBChatFilter] Available commands: adduser, listusers, remuser');
return true;
break;
default:
return false;
}
}

Expand Down

0 comments on commit fa7a91c

Please sign in to comment.