pocketmine\event\player\PlayerChatEvent::setFormat PHP Method

setFormat() public method

public setFormat ( $format )
    public function setFormat($format)
    {
        //TODO: @deprecated (backwards-compativility)
        $i = 0;
        while (($pos = strpos($format, "%s")) !== false) {
            $format = substr($format, 0, $pos) . "{%{$i}}" . substr($format, $pos + 2);
            ++$i;
        }
        $this->format = $format;
    }

Usage Example

 public function onChat(PlayerChatEvent $event)
 {
     $this->plugin->event = $event;
     $extensions = $this->getAllExtensions();
     foreach ($extensions as $get) {
         if ($this->plugin->getServer()->getPluginManager()->getPlugin($get) && method_exists($this->plugin->getServer()->getPluginManager()->getPlugin($get), "onRegisterPrefix")) {
             $this->plugin->getServer()->getPluginManager()->getPlugin($get)->onRegisterPrefix();
         }
     }
     // ===========
     //	Format
     // ===========
     $this->plugin->replaceTag("{WORLD}", $event->getPlayer()->getLevel()->getName());
     //Level Tag
     $this->plugin->replaceTag("{PLAYER}", $event->getPlayer()->getName());
     //Player Tag
     $this->plugin->replaceTag("{PREFIX}", $this->plugin->getConfig()->get("prefix"));
     //Prefix Tag
     $this->plugin->replaceTag("{SUFFIX}", $this->plugin->getConfig()->get("suffix"));
     //Suffix Tag
     $this->plugin->replaceTag("{MESSAGE}", $event->getMessage());
     //Message Tag
     //Custom tags
     $tags = new Config($this->plugin->getDataFolder() . "tags.yml", Config::YAML);
     foreach ($tags->getAll() as $tag => $value) {
         $this->plugin->replaceTag("{" . strtoupper($tag) . "}", $value);
     }
     $event->setFormat($this->getFormattedMessage($this->plugin->getConfig()->get("chat-format")));
     // ===========
     //	Player Mute
     // ===========
     $mhut = $event->getRecipients();
     for ($lol = 0; $i < count($mhut); $lol++) {
         if (isset($this->leave[$mhut[$lol]->getName()])) {
             unset($mhut[$lol]);
         }
     }
     $event->setRecipients($mhut);
     $allowChat = $this->plugin->getConfig()->get("disablechat");
     if ($allowChat) {
         $event->setCancelled(true);
         return;
     }
     if (!$allowChat || $allowChat == null) {
         $player = $event->getPlayer();
         $perm = "chatmute";
         if ($player->isPermissionSet($perm)) {
             $event->setCancelled(true);
             return;
         }
         $format = $this->getFormattedMessage($player, $event->getMessage());
         $config_node = $this->plugin->getConfig()->get("enable-formatter");
         if (isset($config_node) and $config_node === true) {
             $event->setFormat($format);
         }
         return;
     }
 }
All Usage Examples Of pocketmine\event\player\PlayerChatEvent::setFormat