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: 12: 13: 14: 15: 16:
17: class FreezeSession extends Session {
18: protected $hard;
19: protected $api;
20: 21: 22: 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);
31: $this->api = null;
32: $this->hard = $hard;
33: }
34: 35: 36: 37:
38: public function onMove(PlayerMoveEvent $ev) {
39:
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:
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: 55: 56:
57: public function isHardFreeze() {
58: if ($this->api !== null) return $this->api->isHardFreeze();
59: return $this->hard;
60: }
61: 62: 63: 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: 74: 75: 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: 90: 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: