Skip to content
This repository was archived by the owner on Jul 11, 2018. It is now read-only.

Commit c35b2d6

Browse files
committed
Added commands: clearchat, ycstop, ycstart
1 parent 88d8664 commit c35b2d6

File tree

3 files changed

+75
-5
lines changed

3 files changed

+75
-5
lines changed

YouChat/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ settings:
8080
8181
# Changes
8282
83+
* 1.0.2:
84+
* New command: clearchat, ycstart, ycstop
8385
* 1.0.0 : First version
8486
8587
# Copyright

YouChat/plugin.yml

+19-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ load: POSTWORLD
44

55
name: YouChat
66
description: "Chat Management: Nicknames, prefixes, muting"
7-
version: 1.0.0
7+
version: 1.0.1
88
author: aliuly
99

1010

@@ -45,8 +45,23 @@ commands:
4545
description: Disable chat
4646
usage: "/ycd"
4747
permission: youchat.cmd.op.ycx
48+
ycstop:
49+
description: Stop recieving chat messages
50+
usage: "/ycstop"
51+
permission: youchat.cmd.ycpause
52+
ycstart:
53+
description: Start recieving chat messages
54+
usage: "/ycstart"
55+
permission: youchat.cmd.ycpause
56+
clearchat:
57+
description: Clear your chat screen
58+
usage: "/clearchat"
59+
permission: youchat.cmd.clear
4860

4961
permissions:
62+
youchat.cmd.clear:
63+
default: true
64+
description: "Allow clearing your chat window"
5065
youchat.cmd.prefix:
5166
default: true
5267
description: "allow players to change their prefix"
@@ -68,3 +83,6 @@ permissions:
6883
youchat.comd.op.ycx:
6984
default: op
7085
description: Allowed to enable/disable chat
86+
youchat.comd.op.ycpause:
87+
default: true
88+
description: Allowed to pause receiving chats

YouChat/src/aliuly/youchat/Main.php

+54-4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ private function load(Player $player) {
3030
"prefix" => null,
3131
"nick" => null,
3232
"mute" => false,
33+
"pause" => false,
3334
];
3435
$this->players[$n] = (new Config($path,Config::YAML,$defaults))->getAll();
3536
}
@@ -99,7 +100,23 @@ public function onChat(PlayerChatEvent $ev) {
99100
$player->sendMessage(TextFormat::RED."[YouChat] You have been muted from chat!");
100101
return;
101102
}
103+
if ($this->players[$n]["pause"]) {
104+
$ev->setCancelled();
105+
$player->sendMessage(TextFormat::RED."[YouChat] You have paused chat!");
106+
return;
107+
}
108+
}
109+
110+
$recvr = [];
111+
foreach ($ev->getRecipients() as $to) {
112+
$m = strtolower($to->getName());
113+
if (isset($this->players[$m])) {
114+
if ($this->players[$m]["pause"]) continue;
115+
}
116+
$recvr[] = $to;
102117
}
118+
$ev->setRecipients($recvr);
119+
103120
$vars = [
104121
"{YouChat}" => $this->getDescription()->getFullName(),
105122
"{player}" => $player->getName(),
@@ -170,7 +187,14 @@ private function findPlayer($pn) {
170187
echo __METHOD__.",".__LINE__."\n";//##DEBUG
171188
return $target;
172189
}
190+
private function chgUsrCfg($target,$setting,$value) {
191+
$this->load($target); // Make sure defautls are there
192+
$n = trim(strtolower($target->getName()));
193+
$this->players[$n][$setting] = $value;
194+
$this->save($target);
195+
return true;
173196

197+
}
174198
private function checkOther($sender,$setting,$args,$perm,$null=false) {
175199
if (count($args) == 0
176200
|| ($target = $this->findPlayer($args[0])) === null) {
@@ -198,10 +222,7 @@ private function checkOther($sender,$setting,$args,$perm,$null=false) {
198222
if (count($args) == 0) return false;
199223
$value = implode(" ",$args);
200224
}
201-
$this->load($target); // Make sure defautls are there
202-
$n = trim(strtolower($target->getName()));
203-
$this->players[$n][$setting] = $value;
204-
$this->save($target);
225+
$this->chgUsrCfg($target,$setting,$value);
205226
if ($target->isOnline()) {
206227
if ($value === null) {
207228
$target->sendMessage(TextFormat::AQUA.
@@ -256,6 +277,26 @@ public function onCommand(CommandSender $sender, Command $cmd, $label, array $ar
256277
if (count($args) != 1) return false;
257278
$this->mute($sender,implode(" ",$args),false);
258279
return true;
280+
case "ycstop":
281+
if (!($sender instanceof Player)) {
282+
$sender->sendMessage(TextFormat::YELLOW.
283+
"[YouChat] In-game only command");
284+
return true;
285+
}
286+
if (count($args) != 0) return false;
287+
$this->chgUsrCfg($sender,"pause",true);
288+
$sender->sendMessage(TextFormat::RED."[YouChat] Chat suspended");
289+
return true;
290+
case "ycstart":
291+
if (!($sender instanceof Player)) {
292+
$sender->sendMessage(TextFormat::YELLOW.
293+
"[YouChat] In-game only command");
294+
return true;
295+
}
296+
if (count($args) != 0) return false;
297+
$this->chgUsrCfg($sender,"pause",false);
298+
$sender->sendMessage(TextFormat::GREEN."[YouChat] Chat resumed");
299+
return true;
259300
case "yce": // enable chat
260301
$this->chgCfg("chat",true);
261302
$this->getServer()->broadcastMessage(TextFormat::GREEN."[YouChat] Chat is now enabled");
@@ -264,6 +305,15 @@ public function onCommand(CommandSender $sender, Command $cmd, $label, array $ar
264305
$this->chgCfg("chat",false);
265306
$this->getServer()->broadcastMessage(TextFormat::RED."[YouChat] Chat is now disabled");
266307
return true;
308+
case "clearchat": // Clear chat window
309+
if (!($sender instanceof Player)) {
310+
$sender->sendMessage(TextFormat::YELLOW.
311+
"[YouChat] In-game only command");
312+
return true;
313+
}
314+
if (count($args) != 0) return false;
315+
for($i=0;$i<32;++$i) $sender->sendMessage(" ");
316+
return true;
267317
}
268318
return false;
269319
}

0 commit comments

Comments
 (0)