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: //= api-features
 3: //: - Player session and state management
 4: 
 5: namespace aliuly\common;
 6: use pocketmine\event\Listener;
 7: use pocketmine\event\player\PlayerQuitEvent;
 8: use pocketmine\plugin\PluginBase;
 9: 
10: use aliuly\common\MPMU;
11: 
12: /**
13:  * Basic Session Manager functionality
14:  */
15: class Session implements Listener {
16:   protected $plugin;
17:   protected $state;
18:   /**
19:    * @param PluginBase $owner - plugin that owns this session
20:    */
21:   public function __construct(PluginBase $owner) {
22:     $this->plugin = $owner;
23:     $this->plugin->getServer()->getPluginManager()->registerEvents($this,$this->plugin);
24:     $this->state = [];
25:   }
26:   /**
27:      * Handle player quit events.  Free's data used by the state tracking
28:      * code.
29:    *
30:    * @param PlayerQuitEvent $ev - Quit event
31:      */
32:     public function onPlayerQuit(PlayerQuitEvent $ev) {
33:     //echo __METHOD__.",".__LINE__."\n";//##DEBUG
34:         $n = MPMU::iName($ev->getPlayer());
35:         if (isset($this->state[$n])) unset($this->state[$n]);
36:     //echo __METHOD__.",".__LINE__."\n";//##DEBUG
37:     }
38:   /**
39:      * Get a player state for the desired module/$label.
40:      *
41:      * @param str $label - state variable to get
42:      * @param Player|str $player - Player instance or name
43:      * @param mixed $default - default value to return is no state found
44:      * @return mixed
45:      */
46:     public function getState($label,$player,$default) {
47:     $player = MPMU::iName($player);
48:         if (!isset($this->state[$player])) return $default;
49:         if (!isset($this->state[$player][$label])) return $default;
50:         return $this->state[$player][$label];
51:     }
52:     /**
53:      * Set a player related state
54:      *
55:      * @param str $label - state variable to set
56:      * @param Player|str $player - player instance or their name
57:      * @param mixed $val - value to set
58:      * @return mixed
59:      */
60:     public function setState($label,$player,$val) {
61:     $player = MPMU::iName($player);
62:         if (!isset($this->state[$player])) $this->state[$player] = [];
63:         $this->state[$player][$label] = $val;
64:         return $val;
65:     }
66:     /**
67:      * Clears a player related state
68:      *
69:      * @param str $label - state variable to clear
70:      * @param Player|str $player - intance of Player or their name
71:      */
72:     public function unsetState($label,$player) {
73:     $player = MPMU::iName($player);
74:         if (!isset($this->state[$player])) return;
75:         if (!isset($this->state[$player][$label])) return;
76:         unset($this->state[$player][$label]);
77:     }
78: 
79: }
80: 
API documentation generated by ApiGen