pocketmine\event\player\PlayerCommandPreprocessEvent::setMessage PHP Метод

setMessage() публичный Метод

public setMessage ( string $message )
$message string
    public function setMessage($message)
    {
        $this->message = $message;
    }

Usage Example

Пример #1
0
 public function onPreprocess(PlayerCommandPreprocessEvent $event)
 {
     //query basic information in event.
     $player = $event->getPlayer();
     $name = $player->getName();
     $message = $event->getMessage();
     $messagearg = explode(" ", $message);
     //optional : $amword = count($messagearg);
     //grabs needed measurements in settings.json
     $jsons = file_get_contents($this->getDataFolder() . "/settings.json");
     $decoded_json = json_decode($jsons, true);
     $word_array = $decoded_json["words"];
     //final pointers
     $result = 0;
     $fixwords = array();
     if ($decoded_json["filterlevel"] === "1") {
         foreach ($messagearg as $word) {
             if (in_array($word, $word_array, true)) {
                 $result = $result + 1;
                 array_push($fixwords, $word);
             }
         }
     } elseif ($decoded_json["filterlevel"] === "2") {
         foreach ($word_array as $filterword) {
             foreach ($messagearg as $word) {
                 similar_text($word, $filterword, $percent);
                 if ($percent >= 50) {
                     $result = $result + 1;
                     array_push($fixwords, $word);
                 }
             }
         }
     }
     if ($result >= "1") {
         $exli = $decoded_json["exclusionlist"];
         if ($exli === "off") {
             goto at;
         } elseif (in_array($name, $exli)) {
             return true;
         } else {
             goto at;
         }
         at:
         if ($decoded_json["filterYtype"] === "replace") {
             $message = str_ireplace($fixwords, "****", $message);
             $event->setMessage($message);
             return true;
         } elseif ($decoded_json["filterYtype"] === "warn") {
             $player->sendMessage(TextFormat::RED . "Please do not swear.");
             $event->setCancelled();
             return true;
         }
     } else {
         return true;
     }
 }
All Usage Examples Of pocketmine\event\player\PlayerCommandPreprocessEvent::setMessage