diff --git a/README.md b/README.md index a129d7d..d313d24 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,10 @@ LBChatFilter - A (not so) simple plugin for adding an awesome chat filter to your server -====== \ No newline at end of file +====== + +## This plugin allows a user to add a chatfilter to their server. The commands are simple: + +| Command | Sub Command | User | Description | +|:-------:|:-----------:|:----:|:-----------:| +|`lbchatfilter`|`adduser`|``| Adds a player to the whitelist | +|`lbchatfilter`|`remuser`|``| Removes a player from the whitelist | +|`lbchatfilter`|`listusers`| | Lists players currently on the whitelist | diff --git a/plugin.yml b/plugin.yml index aba08e5..4a26fcc 100644 --- a/plugin.yml +++ b/plugin.yml @@ -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 " diff --git a/resources/config.yml b/resources/config.yml index 7c9308f..6b47eb6 100644 --- a/resources/config.yml +++ b/resources/config.yml @@ -7,6 +7,6 @@ onlyOp: true # Array of usernames to a whitelist users: - humerusj - williamtdr - brandon15811 +- humerusj +- williamtdr +- brandon15811 diff --git a/src/ChatFilter/ChatFilter.php b/src/ChatFilter/ChatFilter.php index e27c54b..02d3558 100644 --- a/src/ChatFilter/ChatFilter.php +++ b/src/ChatFilter/ChatFilter.php @@ -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(); } diff --git a/src/LBChatFilter/Main.php b/src/LBChatFilter/Main.php index a117977..4aae489 100644 --- a/src/LBChatFilter/Main.php +++ b/src/LBChatFilter/Main.php @@ -17,6 +17,13 @@ */ class Main extends PluginBase implements Listener { + /** + * The main users array + * + * @var array + */ + public $users = []; + /** * Loads the plugin * @@ -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(); @@ -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; } }