/**
  * onCommand
  *
  * @param CommandSender $sender        	
  * @param Command $command        	
  * @param unknown $label        	
  * @param array $args        	
  * @return boolean
  */
 public function onCommand(CommandSender $sender, Command $command, $label, array $args)
 {
     $this->config = ccMain::getInstance()->getCfg();
     if (strtolower($command->getName()) == "customchat") {
         $sender->sendMessage(TextFormat::RED . "-==[CustomChat]==-");
         $sender->sendMessage(TextFormat::RED . "Usage: /mute <player>");
         $sender->sendMessage(TextFormat::RED . "Usage: /unmute <player>");
         $sender->sendMessage(TextFormat::RED . "Usage: /delprefix <player>");
         $sender->sendMessage(TextFormat::RED . "Usage: /enablechat");
         $sender->sendMessage(TextFormat::RED . "Usage: /disablechat");
         $sender->sendMessage(TextFormat::RED . "Usage: /enableworld");
         $sender->sendMessage(TextFormat::RED . "Usage: /disableworld");
         $sender->sendMessage(TextFormat::RED . "Usage: /defprefix <Prefix>");
         $sender->sendMessage(TextFormat::RED . "Usage: /setprefix <Prefix> <player>");
         $sender->sendMessage(TextFormat::RED . "Usage: /setnick <Nick> <player>");
         $sender->sendMessage(TextFormat::RED . "Usage: /delnick <player>");
         return;
     }
     // disable chat for all players
     if (strtolower($command->getName()) == "disablechat") {
         $this->config = ccMain::getInstance()->getCfg();
         $this->config->set("disablechat", true);
         // config.yml
         $this->config->save();
         $sender->sendMessage(TextFormat::RED . "[CustomChat] Disable chat for all Players");
         $this->log("[CustomChat] Disable chat for all Players");
         return;
     }
     // enable chat for all players
     if (strtolower($command->getName()) == "enablechat") {
         $this->config = ccMain::getInstance()->getCfg();
         $this->config->set("disablechat", false);
         // config.yml
         $this->config->save();
         $sender->sendMessage(TextFormat::GREEN . "[CustomChat] Enable chat for all Players");
         $this->log("[CustomChat] Enable chat for all Players");
         return;
     }
     // sets default prefix for new players
     if (strtolower($command->getName()) == "defprefix" && isset($args[0])) {
         //					if(empty($args[0])) {
         //				$sender->sendMessage (TextFormat::DARK_BLUE ."Usage: /defprefix <Player> <Prefix>");
         //				return true;
         //			}
         $playerName = $args[0];
         $p = $sender->getServer()->getPlayerExact($playerName);
         if ($p == null) {
             $sender->sendMessage(TextFormat::RED . "[CustomChat] Player " . $playerName . " is not Online!");
             return true;
         }
         $prefix = $args[1];
         $this->config->set("default-player-prefix", $prefix);
         $this->config->save();
         $sender->sendMessage(TextFormat::RED . "[CustomChat] All players default prefix set to " . $args[1]);
         return;
     }
     // sets prefix for player
     if (strtolower($command->getName()) == "setprefix" && isset($args[0]) && isset($args[1])) {
         //				if(empty($args[0])) {
         //				$sender->sendMessage (TextFormat::DARK_BLUE ."Usage: /setprefix <Player> <Prefix>");
         //				return true;
         //			}
         $playerName = $args[0];
         $this->playerConfig = ccMain::getInstance()->getPlCfg($playerName);
         $p = $sender->getServer()->getPlayerExact($playerName);
         if ($p == null) {
             $sender->sendMessage(TextFormat::RED . "[CustomChat] Player " . $playerName . " is not Online!");
             return true;
         }
         $prefix = $args[1];
         $this->playerConfig->set($p->getName() . ".prefix", $prefix);
         $this->playerConfig->save();
         // $p->setDisplayName($prefix.":".$name);
         $this->plugin->formatterPlayerDisplayName($p);
         $sender->sendMessage(TextFormat::GREEN . $p->getName() . "[CustomChat] Prefix set to " . $args[1]);
         return;
     }
     // set player's prefix to default.
     if (strtolower($command->getName()) == "delprefix" && isset($args[0])) {
         //				if(empty($args[0])) {
         //				$sender->sendMessage (TextFormat::DARK_BLUE ."Usage: /delprefix <Player>");
         //				return true;
         //			}
         $playerName = $args[0];
         $this->playerConfig = ccMain::getInstance()->getPlCfg($playerName);
         $p = $sender->getServer()->getPlayerExact($playerName);
         if ($p == null) {
             $sender->sendMessage(TextFormat::RED . "[CustomChat] Player " . $playerName . " is not Online!");
             return true;
         }
         $this->playerConfig->remove($p->getName() . ".prefix");
         $this->playerConfig->save();
         $sender->sendMessage(TextFormat::RED . $p->getName() . "[CustomChat] Prefix set to Default");
         return;
     }
     // sets nick for player
     if (strtolower($command->getName()) == "setnick" && isset($args[0]) && isset($args[1])) {
         //				if(empty($args[0])) {
         //				$sender->sendMessage (TextFormat::DARK_BLUE ."Usage: /setnick <Player> <Nick>");
         //				return true;
         //			}
         $playerName = $args[0];
         $this->playerConfig = ccMain::getInstance()->getPlCfg($playerName);
         $p = $sender->getServer()->getPlayerExact($playerName);
         if ($p == null) {
             $sender->sendMessage(TextFormat::RED . "[CustomChat] Player " . $playerName . " is not Online!");
             return true;
         }
         $nick = $args[1];
         $this->playerConfig->set($p->getName() . ".nick", $nick);
         $this->playerConfig->save();
         $this->plugin->formatterPlayerDisplayName($p);
         $sender->sendMessage(TextFormat::GREEN . $p->getName() . "[CustomChat] Nick name set to " . $args[1]);
         return;
     }
     // sets nick for player
     if (strtolower($command->getName()) == "delnick" && isset($args[0]) && isset($args[1])) {
         //				if(empty($args[0])) {
         //				$sender->sendMessage (TextFormat::DARK_BLUE ."Usage: /delnick <Player>");
         //				return true;
         //			}
         $playerName = $args[0];
         $this->playerConfig = ccMain::getInstance()->getPlCfg($playerName);
         $p = $sender->getServer()->getPlayerExact($playerName);
         if ($p == null) {
             $sender->sendMessage(TextFormat::RED . "[CustomChat] Players " . $playerName . " is not Online!");
             return true;
         }
         $nick = $args[1];
         $this->playerConfig->remove($p->getName() . ".nick");
         $this->playerConfig->save();
         // save yml
         $this->plugin->formatterPlayerDisplayName($p);
         $sender->sendMessage(TextFormat::GREEN . $p->getName() . "[CustomChat] Nick removed !");
         return;
     }
     // mute player from chat
     if (strtolower($command->getName()) == "mute" && isset($args[0])) {
         //				if(empty($args[0])) {
         //				$sender->sendMessage (TextFormat::DARK_BLUE ."Usage: /mute <Player>");
         //				return true;
         //			}
         $playerName = $args[0];
         // check if the player exist
         $p = $sender->getServer()->getPlayerExact($playerName);
         if ($p == null) {
             $sender->sendMessage(TextFormat::RED . "[CustomChat] Players " . $playerName . " is not Online!");
             return true;
         }
         $perm = "chatmute";
         $p->addAttachment($this->plugin, $perm, true);
         $sender->sendMessage(TextFormat::GREEN . $p->getName() . " chat muted");
         // $this->log ( "isPermissionSet " . $p->isPermissionSet ( $perm ) );
         return;
     }
     // - unmute player from chat
     if (strtolower($command->getName()) == "unmute" && isset($args[0])) {
         //			if(empty($args[0])) {
         //				$sender->sendMessage (TextFormat::DARK_BLUE ."Usage: /unmute <Player>");
         //				return true;
         //			}
         $playerName = $args[0];
         // check if the player exist
         $p = $sender->getServer()->getPlayerExact($playerName);
         if ($p == null) {
             $sender->sendMessage(TextFormat::RED . "[CustomChat] Players " . $playerName . " is not Online!");
             return true;
         }
         $perm = "chatmute";
         foreach ($p->getEffectivePermissions() as $pm) {
             if ($pm->getPermission() == $perm) {
                 // $this->log ( "remove attachements " . $pm->getValue () );
                 $p->removeAttachment($pm->getAttachment());
                 $sender->sendMessage(TextFormat::GREEN . $p->getName() . "[CustomChat] Chat unmuted");
                 return;
             }
         }
         $sender->sendMessage(TextFormat::RED . $p->getName() . "[CustomChat] Already unmuted");
         // $this->log ( "isPermissionSet " . $p->isPermissionSet ( $perm ) );
         return;
         // next try again
     }
     // TAGS
     // sets default tags for new players
     if (strtolower($command->getName()) == "deftags" && isset($args[0])) {
         //			if(empty($args[0])) {
         //				$sender->sendMessage (TextFormat::DARK_BLUE ."Usage: /deftags <Player> <Tags>");
         //				return true;
         //			}
         $playerName = $args[0];
         $this->config = ccMain::getInstance()->getCfg();
         $p = $sender->getServer()->getPlayerExact($playerName);
         if ($p == null) {
             $sender->sendMessage(TextFormat::RED . "[CustomChat] Players " . $playerName . " is not Online!");
             return true;
         }
         $tags = $args[1];
         $this->config->set("default-player-tags", $tags);
         $this->config->save();
         $sender->sendMessage(TextFormat::RED . "[CustomChat] All players default tags set to " . $args[1]);
         return;
     }
     // sets tags for player
     if (strtolower($command->getName()) == "tags" && isset($args[0]) && isset($args[1])) {
         //			if(empty($args[0])) {
         //				$sender->sendMessage (TextFormat::DARK_BLUE ."Usage: /tags <Player> <Tags>");
         //				return true;
         //			}
         $playerName = $args[0];
         $this->playerConfig = ccMain::getInstance()->getPlCfg($playerName);
         $p = $sender->getServer()->getPlayerExact($playerName);
         if ($p == null) {
             $sender->sendMessage(TextFormat::RED . "[CustomChat] Player " . $playerName . " is not Online!");
             return true;
         }
         $tags = $args[1];
         $this->playerConfig->set($p->getName() . ".tags", $tags);
         $this->playerConfig->save();
         // $p->setDisplayName($tags.":".$name);
         $this->plugin->formatterPlayerDisplayName($p);
         $sender->sendMessage(TextFormat::GREEN . $p->getName() . "[CustomChat] Tags set to " . $args[1]);
         return;
     }
     // set player's tags to default.
     if (strtolower($command->getName()) == "deltags" && isset($args[0])) {
         //			if(empty($args[0])) {
         //				$sender->sendMessage (TextFormat::DARK_BLUE ."Usage: /tags <Player>");
         //				return true;
         //			}
         $playerName = $args[0];
         $this->playerConfig = ccMain::getInstance()->getPlCfg($playerName);
         $p = $sender->getServer()->getPlayerExact($playerName);
         if ($p == null) {
             $sender->sendMessage(TextFormat::RED . "[CustomChat] Player " . $playerName . " is not Online!");
             return true;
         }
         $this->playerConfig->remove($p->getName() . ".tags");
         $this->playerConfig->getConfig()->save();
         $sender->sendMessage(TextFormat::RED . $p->getName() . "[CustomChat] Tags set to default");
         return;
     }
     // disable PerWorldChat for all players
     if (strtolower($command->getName()) == "disableworld") {
         $this->config = ccMain::getInstance()->getCfg();
         $this->config->set("per-world-chat", false);
         // config.yml
         $this->config->save();
         $sender->sendMessage(TextFormat::RED . "[CustomChat] Disable PerWorldChat for all players");
         $this->log("[CustomChat] Disable PerWorldChat for all players");
         return;
     }
     // enable PerWorldChat for all players
     if (strtolower($command->getName()) == "enableworld") {
         $this->config = ccMain::getInstance()->getCfg();
         $this->config->set("per-world-chat", true);
         // config.yml
         $this->config->getConfig()->save();
         $sender->sendMessage(TextFormat::GREEN . "[CustomChat] Enable PerWorldChat for all players");
         $this->log("[CustomChat] Enable PerWorldChat for all players");
         return;
     }
     if (strtolower($command->getName()) == "alert") {
         $this->config_message = ccMain::getInstance()->getMCfg();
         if (isset($args[0])) {
             Server::getInstance()->broadcastMessage(" §d[SERVER] " . implode(" ", $args));
         } else {
             $sender->sendMessage("Usage: /alert <Message>");
         }
         return;
     }
 }
 public function getFormattedMessage(Player $player, $message)
 {
     $this->config = ccMain::getInstance()->getCfg();
     $format = $this->config->get("chat-format");
     $this->playerConfig = ccMain::getInstance()->getPlCfg($player->getName());
     // $format = "<{PREFIX} {USER_NAME}> {MESSAGE}";
     if (!$this->pureperms) {
         $format = str_replace("{PurePerms}", "NoGroup", $format);
     }
     if ($this->pureperms) {
         $isMultiWorldEnabled = $this->pureperms->getConfig()->get("enable-multiworld-formats");
         $levelName = $isMultiWorldEnabled ? $player->getLevel()->getName() : null;
         $format = str_replace("{PurePerms}", $this->pureperms->getUser($player)->getGroup($levelName)->getName(), $format);
     } else {
         return false;
     }
     if ($this->killchat) {
         $format = str_replace("{Kills}", KillChat::getInstance()->getKills($player->getName()), $format);
     } else {
         $format = str_replace("{Kills}", "ERROR", $format);
     }
     if ($this->killchat) {
         $format = str_replace("{Deaths}", KillChat::getInstance()->getDeaths($player->getName()), $format);
     } else {
         $format = str_replace("{Deaths}", "ERROR", $format);
     }
     if ($this->massive) {
         $format = str_replace("{Money}", MassiveEconomyAPI::getInstance()->getMoney($player->getName()), $format);
     } else {
         $format = str_replace("{Money}", "ERROR", $format);
     }
     if ($this->factionspro == true && $this->factionspro->isInFaction($player->getName())) {
         $getUserFaction = $this->factionspro->getPlayerFaction($player->getName());
         $format = str_replace("{FACTION}", $getUserFaction, $format);
     } else {
         $nofac = $this->config->get("if-player-has-no-faction");
         $format = str_replace("{FACTION}", $nofac, $format);
     }
     $format = str_replace("{WORLD_NAME}", $player->getLevel()->getName(), $format);
     $nick = $this->config->get($player->getName() > ".nick");
     if ($nick != null) {
         $format = str_replace("{DISPLAY_NAME}", $nick, $format);
     } else {
         $format = str_replace("{DISPLAY_NAME}", $player->getName(), $format);
     }
     $format = str_replace("{MESSAGE}", $message, $format);
     $level = $player->getLevel()->getName();
     // LOST FORMAT TAGS REMOVED
     $tags = null;
     $playerTags = $this->playerConfig->get($player->getName() . ".tags");
     if ($playerTags != null) {
         $tags = $playerTags;
     } else {
         //use default tags
         $tags = $this->config->get("default-player-tags");
     }
     if ($tags == null) {
         $tags = "";
     }
     $format = str_replace("{TAGS}", $tags, $format);
     $prefix = null;
     $this->playerConfig = ccMain::getInstance()->getPlCfg($player->getName());
     $playerPrefix = $this->playerConfig->get($player->getName() . ".prefix");
     if ($playerPrefix != null) {
         $prefix = $playerPrefix;
     } else {
         //use default prefix
         $prefix = $this->config->get("default-player-prefix");
     }
     if ($prefix == null) {
         $prefix = "";
     }
     $format = str_replace("{PREFIX}", $prefix, $format);
     return $format;
 }
 /**
  * OnEnable
  *
  * (non-PHPdoc)
  * 
  * @see \pocketmine\plugin\PluginBase::onEnable()
  */
 public function onEnable()
 {
     $this->enabled = true;
     // Use PurePerms by 64FF00
     if (!$this->getServer()->getPluginManager()->getPlugin("PurePerms") == false) {
         $this->pureperms = $this->getServer()->getPluginManager()->getPlugin("PurePerms ");
         $this->log(TextFormat::GREEN . "- CustomChat - Loaded With PurePerms !");
     }
     if (!$this->getServer()->getPluginManager()->getPlugin("KillChat") == false) {
         $kl_chat = Server::getInstance()->getPluginManager()->getPlugin("KillChat");
         $this->log(TextFormat::YELLOW . "- CustomChat - Loaded With KillChat !");
     }
     if (!$this->getServer()->getPluginManager()->getPlugin("MassiveEconomy") == false) {
         $me_money = Server::getInstance()->getPluginManager()->getPlugin("MassiveEconomy");
         $this->log(TextFormat::GREEN . "- CustomChat - Loaded With MassiveEconomy !");
     }
     if (!$this->getServer()->getPluginManager()->getPlugin("FactionsPro") == false) {
         $this->factionspro = $this->getServer()->getPluginManager()->getPlugin("FactionsPro");
         $this->log(TextFormat::GREEN . "- CustomChat - Loaded With FactionsPro!");
     }
     $this->getServer()->getPluginManager()->registerEvents(new ccListener($this), $this);
     $this->log(TextFormat::GREEN . "- CustomChat - Enabled!");
     @mkdir($this->getDataFolder());
     @mkdir($this->getDataFolder() . "players/");
     $this->path = $this->getDataFolder();
     if (!is_file($this->path . "config.yml")) {
         file_put_contents($this->path . "config.yml", $this->readResource("config.yml"));
     }
     $this->config = new Config($this->path . "config.yml", Config::YAML);
     if (!is_file($this->path . "config_message.yml")) {
         file_put_contents($this->path . "config_message.yml", $this->readResource("config_message.yml"));
     }
     $this->config_message = new Config($this->path . "config_message.yml", Config::YAML);
     $this->config_message = ccMain::getInstance()->getMCfg();
     $time = intval($this->config_message->get("Time_AutoMessage")) * 15;
     $this->getServer()->getScheduler()->scheduleRepeatingTask(new ccMain($this), $time);
 }