Overview

Namespaces

  • aliuly
    • common
      • selectors
    • loader
  • xPaw

Classes

  • aliuly\common\ArmorItems
  • aliuly\common\BasicCli
  • aliuly\common\BasicHelp
  • aliuly\common\BasicPlugin
  • aliuly\common\ChatSession
  • aliuly\common\Cmd
  • aliuly\common\CmdSelector
  • aliuly\common\ExpandVars
  • aliuly\common\FastTransfer
  • aliuly\common\FileUtils
  • aliuly\common\FreezeSession
  • aliuly\common\GetMotd
  • aliuly\common\GetMotdAsyncTask
  • aliuly\common\InvisibleSession
  • aliuly\common\InvUtils
  • aliuly\common\ItemName
  • aliuly\common\mc
  • aliuly\common\mc2
  • aliuly\common\MoneyAPI
  • aliuly\common\MPMU
  • aliuly\common\Npc
  • aliuly\common\PermUtils
  • aliuly\common\PluginAsyncTask
  • aliuly\common\PluginCallbackTask
  • aliuly\common\PMScript
  • aliuly\common\QueryAsyncTask
  • aliuly\common\Rcon
  • aliuly\common\RconTask
  • aliuly\common\selectors\All
  • aliuly\common\selectors\AllEntity
  • aliuly\common\selectors\BaseSelector
  • aliuly\common\selectors\Random
  • aliuly\common\Session
  • aliuly\common\ShieldSession
  • aliuly\common\ShoppingCart
  • aliuly\common\SignUtils
  • aliuly\common\SkinUtils
  • aliuly\common\SpySession
  • aliuly\common\SubCommandMap
  • aliuly\common\TPUtils
  • aliuly\loader\Main
  • xPaw\MinecraftQuery

Exceptions

  • xPaw\MinecraftQueryException
  • Overview
  • Namespace
  • Class
  1: <?php
  2: 
  3: namespace aliuly\common;
  4: 
  5: use pocketmine\Player;
  6: 
  7: use aliuly\common\Session;
  8: use aliuly\common\MPMU;
  9: 
 10: use pocketmine\plugin\PluginBase;
 11: use pocketmine\event\player\PlayerChatEvent;
 12: 
 13: 
 14: /**
 15:  * Chat Sessions
 16:  *
 17:  * NOTE, if GrabBag is available, it will use the GrabBag functions
 18:  * This gives you a command line interface and also
 19:  * reduces the number of listeners in use.
 20:  */
 21: class ChatSession extends Session {
 22:   protected $apis;
 23:   protected $chat;
 24:   /**
 25:    * @param PluginBase $owner - plugin that owns this session
 26:    */
 27:   public function __construct(PluginBase $owner) {
 28:     $bag = $owner->getServer()->getPluginManager()->getPlugin("GrabBag");
 29:     $this->apis = [ null, null ];
 30:     if ($bag && $bag->isEnabled() && MPMU::apiCheck($bag->getDescription()->getVersion(),"2.3")) {
 31:       if ($bag->api->getFeature("chat-utils")) $this->apis[0] = $bag->api;
 32:       if ($bag->api->getFeature("mute-unmute")) $this->apis[1] = $bag->api;
 33:       return;
 34:     }
 35:     parent::__construct($owner);
 36:     $this->chat = true;
 37:   }
 38: 
 39:   /**
 40:    * Enable/Disable Chat globally
 41:    * @param bool $mode - true, chat is active, false, chat is disabled
 42:    */
 43:   public function setGlobalChat($mode) {
 44:     if ($this->apis[0] !== null) {
 45:       $this->apis[0]->setGlobalChat($mode);
 46:       return;
 47:     }
 48:     $this->chat = $mode;
 49:   }
 50:   /**
 51:    * Returns global chat status
 52:    * @return bool
 53:    */
 54:   public function getGlobalChat() {
 55:     if ($this->apis[0] !== null) return $this->apis[0]->getGlobalChat();
 56:     return $this->chat;
 57:   }
 58:   /**
 59:    * Enable/Disable player's chat
 60:    * @param Player $player
 61:    * @param bool $mode - true, chat is active, false, chat is disabled
 62:    */
 63:   public function setPlayerChat(Player $player,$mode) {
 64:     if ($this->apis[0] !== null) {
 65:       $this->apis[0]->setPlayerChat($player, $mode);
 66:       return;
 67:     }
 68:     if ($mode) {
 69:       $this->unsetState("chat",$player);
 70:     } else {
 71:       $this->setState("chat",$player,false);
 72:     }
 73:   }
 74:   /**
 75:    * Returns player's chat status
 76:    * @param Player $player
 77:    * @return bool
 78:    */
 79:   public function getPlayerChat(Player $player) {
 80:     if ($this->apis[0] !== null) return $this->apis[0]->getPlayerChat($player);
 81: 
 82:     return $this->getState("chat",$player,true);
 83:   }
 84:   /**
 85:    * Mute/UnMute a player
 86:    * @param Player $player
 87:    * @param bool $mode - true is muted, false is unmuted
 88:    */
 89:   public function setMute(Player $player,$mode) {
 90:     if ($this->apis[1] !== null) {
 91:       $this->apis[1]->setMute($player, $mode);
 92:       return;
 93:     }
 94:     if ($mode) {
 95:       $this->setState("muted",$player,true);
 96:     } else {
 97:       $this->unsetState("muted",$player);
 98:     }
 99:   }
100:   /**
101:    * Returns a player mute status
102:    * @param Player $player
103:    * @return bool
104:    */
105:   public function getMute(Player $player) {
106:     if ($this->apis[1] !== null) return $this->apis[1]->getMute($player);
107:     return $this->getState("muted",$player,false);
108:   }
109: 
110:   public function onChat(PlayerChatEvent $ev) {
111:     //echo __METHOD__.",".__LINE__."\n";//##DEBUG
112:     if ($ev->isCancelled()) return;
113:     $p = $ev->getPlayer();
114: 
115:     if (!$this->chat) {
116:       $p->sendMessage(mc::_("Chat has been globally disabled!"));
117:       $ev->setCancelled();
118:       return;
119:     }
120:     if ($this->getState("muted",$p,false)) {
121:       $p->sendMessage(mc::_("You have been muted!"));
122:       $ev->setCancelled();
123:       return;
124:     }
125:     if (!$this->getState("chat",$p,true)) {
126:       $p->sendMessage(mc::_("Chat is disabled for you"));
127:       $ev->setCancelled();
128:       return;
129:     }
130:     $recvr = [];
131:     foreach ($ev->getRecipients() as $to) {
132:       if ($this->getState("chat",$to,true)) $recvr[] = $to;
133:     }
134:     $ev->setRecipients($recvr);
135:   }
136: }
137: 
API documentation generated by ApiGen