-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatControl.php
More file actions
232 lines (218 loc) · 7.35 KB
/
Copy pathChatControl.php
File metadata and controls
232 lines (218 loc) · 7.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<?php
/*
__PocketMine Plugin__
name=ChatControl
description=Extra chat options
version=1.0
author=wiezz
class=ChatControl
apiversion=9
*/
/*
--------ChangeLog--------
1.0 : Inital release
-------------------------
*/
class ChatControl implements Plugin{
private $api;
private $server;
private $groups;
private $players;
private $config;
private $filterlist;
public function __construct(ServerAPI $api, $server = false){
$this->api = $api;
$this->server = ServerAPI::request();
}
public function init(){
$this->api->addHandler('player.chat', array($this, 'playerchat'), 100);
$this->api->addHandler('player.spawn', array($this, 'playerspawn'), 100);
$this->api->addHandler('player.quit', array($this, 'playerquit'), 100);
$this->api->console->register("cc", "Chat control commands", array($this, "command"));
$path = $this->api->plugin->configPath($this);
$this->groups = new Config($path."groups.yml", CONFIG_YAML, array(
'admin' => array(
'Prefix' => '[ADMIN] ',
'Members' => array(),
),
'op' => array(
'Prefix' => '[OP] ',
'Members' => array(),
),
'member' => array(
'Prefix' => '[MEMBER] ',
'Members' => array(),
),
));
$this->groups = $this->api->plugin->readYAML($path ."groups.yml");
$this->config = new Config($path."config.yml", CONFIG_YAML, array(
'SpamProtection' => array(
'Enabled' => true,
'MsgInterval' => 10,
),
'ChatFilter' => array(
'Enabled' => false,
'KickPlayer' => false,
'MutePlayer' => true,
),
'ChatMute' => array(
'Enabled' => true,
'MutesBroadcastMsg' => false,
),
));
$this->config = $this->api->plugin->readYAML($path ."config.yml");
if($this->config['ChatMute']['Enabled'] == true){
$this->api->console->register("mute", "Dissable chat", array($this, "mute"));
$this->api->console->register("unmute", "Enable chat", array($this, "mute"));
$this->api->ban->cmdWhitelist("mute");
$this->api->ban->cmdWhitelist("unmute");
}
if($this->config['ChatMute']['MutesBroadcastMsg'] == true){
$this->api->addHandler('server.chat', array($this, 'serverchat'), 100);
}
if($this->config['ChatFilter']['Enabled'] == true){
$this->filterlist = new Config($path."filterlist.txt", CONFIG_LIST);
$this->filterlist = $this->api->plugin->readYAML($path ."filterlist.txt");
}
$this->players = array();
}
public function mute($cmd, $args, $issuer){
$username = $issuer->username;
switch($cmd){
case 'mute': $this->players[$username]['mute'] = 1;
$this->api->chat->sendTo(false, "[ChatControl] You muted the chat", $username);
break;
case 'unmute': $this->players[$username]['mute'] = 0;
$this->api->chat->sendTo(false, "[ChatControl] You unmuted the chat", $username);
break;
}
}
public function command($cmd, $args, $issuer){
$username = $issuer->username;
switch($args[0]){
case 'apg':
case 'rpg': if(!(isset($args[1]) and isset($args[2]))){
$output = '[ChatControl] Usage: /cc <apg|rpg> <player> <group>';
return $output;
}
$name = $args[1];
$group = $args[2];
if(!isset($this->groups[$group])){
$output = "[ChatControl] Group doesn't exist";
return $output;
}
if($args[0] === 'addplayer'){
array_push($this->groups[$group]['Members'], $name);
$output = '[ChatControl] '.$name.' is added to the group '.$group;
}else{
unset($this->groups[$group]['Members'][$name]);
$output = '[ChatControl] '.$name.' is added to the group '.$group;
}
return $output;
break;
case 'ban':
case 'unban': if(!isset($args[1])){
$output = '[ChatControl] Usage: /cc <ban|unban> <player>';
return $output;
}
$name = $args[1];
if(!isset($this->players[$name])){
$output = "[ChatControl] Player doesn't exist";
return $output;
}
if($args[0] == 'ban'){
$this->players[$name]['banned'] = 1;
$output = '[ChatControl] '.$name." can't chat anymore";
}else{
$this->players[$name]['banned'] = 0;
$output = '[ChatControl] '.$name." can chat";
}
return $output;
break;
case 'reload': $this->groups = $this->api->plugin->readYAML($path ."groups.yml");
$this->config = $this->api->plugin->readYAML($path ."config.yml");
$output = '[ChatControl] config file and group file reloaded';
return $output;
break;
case 'help':
case '?': $issuer->sendChat('===[ChatControl Commands]===');
$issuer->sendChat('/mute - Mutes the chat');
$issuer->sendChat('/unmute - Unmutes the chat');
$issuer->sendChat('/cc apg <player> <group> - Add player to a group');
$issuer->sendChat('/cc rpg <player> <group> - Remove player from a group');
$issuer->sendChat('/cc <ban|unban> <player> - Dissallow a player from chatting');
$issuer->sendChat('/cc reload - Reload the config file');
default: $output = 'ChatControl v1.0 made by Wies';
return $output;
}
}
public function serverchat($data){
$message = $data['message'];
$players = $this->api->player->getAll();
foreach($players as $player){
$username = $player->username;
if($this->players[$username]['mute'] === 0){
$this->api->chat->sendTo(false, $message, $username);
}
}
return false;
}
public function playerchat($data){
$username = $data['player']->username;
if($username == 'console') return true;
if($this->players[$username]['banned'] === 1){
$this->api->chat->sendTo(false, 'You are not allowed to chat!', $username);
return false;
}
$message = $data['message'];
if(isset($this->filterlist) and !$this->api->ban->isOp($username)){
foreach($this->filterlist as $key => $val){
if(!strpos($message, $val)){
$this->api->chat->sendTo(false, 'Your message contains forbidden words', $username);
if($this->config['ChatFilter']['MutePlayer'] == true){
$this->players[$username]['banned'] = 1;
}
if($this->config['ChatFilter']['KickPlayer'] == true){
$this->api->console->run('kick '.$username." Don't use these words again", "console", false);
}
return false;
}
}
}
foreach($this->groups as $key => $val){
if(in_array($username, $val['Members'])){
$message = (string)('<'.$val['Prefix'].$username.'> '.$message);
}
}
if(($this->config['SpamProtection']['Enabled'] and (time() - $this->players[$username]['lastmsg']) < $this->config['SpamProtection']['MsgInterval']) and !$this->api->ban->isOp($username)){
$this->api->chat->sendTo(false, "Don't send more than one msg in ".$this->config['SpamProtection']['MsgInterval'].' seconds', $username);
return false;
}
$this->players[$username]['lastmsg'] = time();
$players = $this->api->player->getAll();
console('[CHAT] '.$message);
foreach($players as $player){
$username = $player->username;
if($this->players[$username]['mute'] === 0){
$this->api->chat->sendTo(false, $message, $username);
}
}
return false;
}
public function playerquit($data){
$username = (string)$data->username;
if(isset($this->players[$username])){
unset($this->players[$username]);
}
}
public function playerspawn($data){
$username = (string)$data->username;
$this->players[$username] = array(
'lastmsg' => 0,
'mute' => 0,
'banned' => 0,
);
}
public function __destruct(){
}
}