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: use aliuly\common\Session;
  5: use pocketmine\event\player\PlayerMoveEvent;
  6: use pocketmine\plugin\PluginBase;
  7: use pocketmine\Player;
  8: use aliuly\common\MPMU;
  9: 
 10: /**
 11:  * Frozen Player sessions
 12:  *
 13:  * NOTE, if GrabBag is available, it will use the GrabBag freeze-thaw
 14:  * implementation.  This gives you a command line interface and also
 15:  * reduces the number of listeners in use.
 16:  */
 17: class FreezeSession extends Session {
 18:   protected $hard;
 19:   protected $api;
 20:   /**
 21:    * @param PluginBase $owner - plugin that owns this session
 22:    * @param bool $hard - hard freeze option
 23:    */
 24:   public function __construct(PluginBase $owner, $hard = true) {
 25:     $bag = $owner->getServer()->getPluginManager()->getPlugin("GrabBag");
 26:     if ($bag && $bag->isEnabled() && MPMU::apiCheck($bag->getDescription()->getVersion(),"2.3") && $bag->api->getFeature("freeze-thaw")) {
 27:       $this->api = $bag->api;
 28:       return;
 29:     }
 30:     parent::__construct($owner);    // We do it here so to prevent the registration of listeners
 31:     $this->api = null;
 32:     $this->hard = $hard;
 33:   }
 34:   /**
 35:      * Handle player move events.
 36:    * @param PlayerMoveEvent $ev - Move event
 37:      */
 38:   public function onMove(PlayerMoveEvent $ev) {
 39:     //echo __METHOD__.",".__LINE__."\n";//##DEBUG
 40:     if ($ev->isCancelled()) return;
 41:     $p = $ev->getPlayer();
 42:     if (!$this->getState("fz",$p,false)) return;
 43:     if ($this->hard) {
 44:       $ev->setCancelled();
 45:     } else {
 46:       // Lock position but still allow to turn around
 47:       $to = clone $ev->getFrom();
 48:       $to->yaw = $ev->getTo()->yaw;
 49:       $to->pitch = $ev->getTo()->pitch;
 50:       $ev->setTo($to);
 51:     }
 52:   }
 53:   /**
 54:    * Checks if hard or soft freezing
 55:    * @return bool
 56:    */
 57:   public function isHardFreeze() {
 58:     if ($this->api !== null) return $this->api->isHardFreeze();
 59:     return $this->hard;
 60:   }
 61:   /**
 62:    * Sets hard or soft freezing
 63:    * @param bool $hard - if true (default) hard freeze is in effect.
 64:    */
 65:   public function setHardFreeze($hard = true) {
 66:     if ($this->api !== null) {
 67:       $this->api->setHardFreeze($hard);
 68:     } else {
 69:       $this->hard = $hard;
 70:     }
 71:   }
 72:   /**
 73:    * Freeze given player
 74:    * @param Player $player - player to freeze
 75:    * @param bool $freeze - if true (default) freeze, if false, thaw.
 76:    */
 77:   public function freeze(Player $player, $freeze = true) {
 78:     if ($this->api !== null) {
 79:       $this->api->freeze($player,$freeze);
 80:       return;
 81:     }
 82:     if ($freeze) {
 83:       $this->setState("fz",$player,true);
 84:     } else {
 85:       $this->unsetState("fz",$player);
 86:     }
 87:   }
 88:   /**
 89:    * Return a list of frozen players
 90:    * @return str[]
 91:    */
 92:   public function getFrosties() {
 93:     if ($this->api !== null) return $this->api->getFrosties();
 94:     $s = [];
 95:     foreach ($this->state as $n=>$d) {
 96:       if (isset($d["fz"])) $s[] = $n;
 97:     }
 98:     return $s;
 99:   }
100: }
101: 
API documentation generated by ApiGen