@@ -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