Skip to content

Sessions

GiantQuartz edited this page Mar 29, 2020 · 3 revisions

Sessions

When a player joins the server, a Session is created and loaded with a lot of useful information about them such as their island data or their rank. Sessions are used everywhere in SkyBlock.

Getting a player session

There are two ways to obtain a player session, both of them are okay as long as you made sure that SkyBlock is loaded first.

The short method

// $player must be an instance of PocketMine's Player class
$session = SessionLocator::getSession($player);

The long method

$session = $skyblock->getSessionManager()->getSession($player);

Saving session data

If you decide to change something on a session (such as their rank) unless you know perfectly what you are doing, I strongly recommend you to save that session data, otherwise, you might end up with unexpected behaviour. Example:

// $player must be an instance of PocketMine's Player class
$session = SessionLocator::getSession($player);
$session->setRank(RankIds::OFFICER); // Updates the player rank to officer
$session->save(); // Saves the changes to the database
Clone this wiki locally