1: <?php
2:
3: namespace aliuly\common;
4: use aliuly\common\Session;
5: use pocketmine\event\player\PlayerJoinEvent;
6: use pocketmine\plugin\PluginBase;
7: use pocketmine\Player;
8:
9: 10: 11: 12: 13: 14: 15:
16: class InvisibleSession extends Session {
17: protected $api;
18: 19: 20:
21: public function __construct(PluginBase $owner) {
22: $bag = $owner->getServer()->getPluginManager()->getPlugin("GrabBag");
23: if ($bag && $bag->isEnabled() && MPMU::apiCheck($bag->getDescription()->getVersion(),"2.3") && $bag->api->getFeature("invisible")) {
24: $this->api = $bag->api;
25: return;
26: }
27: parent::__construct($owner);
28: $this->api = null;
29: }
30: 31: 32: 33: 34:
35: public function invisible(Player $player, $invis) {
36: if ($this->api !== null) {
37: $this->api->invisible($player,$invis);
38: return;
39: }
40: if ($invis) {
41: if ($this->getState("invis",$player,false)) return;
42: $this->setState("invis",$player,true);
43: foreach($this->owner->getServer()->getOnlinePlayers() as $online){
44: $online->hidePlayer($player);
45: }
46: } else {
47: if (!$this->getState("invis",$player,false)) return;
48: $this->unsetState("invis",$player);
49: foreach($this->owner->getServer()->getOnlinePlayers() as $online){
50: $online->showPlayer($player);
51: }
52: }
53: }
54: 55: 56: 57:
58: public function isInvisible(Player $player) {
59: if ($this->api !== null) return $this->api->isInvisible($player);
60: return $this->getState("invis",$player,false);
61: }
62: 63: 64: 65:
66: public function onPlayerJoin(PlayerJoinEvent $e) {
67: $pl = $e->getPlayer();
68: foreach($this->owner->getServer()->getOnlinePlayers() as $online){
69: if ($this->getState("invis",$online,false)) {
70: $pl->hidePlayer($online);
71: }
72: }
73: }
74: }
75: