Skip to content

ServerAuth API

Flavius12 edited this page May 24, 2015 · 14 revisions

Basic Tutorial

1. Define the plugin dependency in plugin.yml (you can check if ServerAuth is installed in different ways):

depend: [ServerAuth]

2. Include ServerAuth API and ServerAuth Events in your php code:

//PocketMine Event Listener
use pocketmine\event\Listener;
//ServerAuth API
use ServerAuth\ServerAuth;
//ServerAuth Events
use ServerAuth\Events\ServerAuthRegisterEvent;

3. Create the class:

class Example extends PluginBase implements Listener {
}

4. Check if ServerAuth API is compatible (insert this code in onEnable() function)

if(ServerAuth::getAPI()->getAPIVersion() == "(used API version)"){
            //API compatible
            //Register Events
            $this->getServer()->getPluginManager()->registerEvents($this, $this);
        }else{
            //API not compatible
            $this->getPluginLoader()->disablePlugin($this);
        }
  }

5. Handle a ServerAuth event (in this tutorial we will handle the ServerAuthRegisterEvent):

public function onRegister(ServerAuthRegisterEvent $event){
  $player = $event->getPlayer();
  $player->sendMessage("You are now registered, " . $player->getName());
}

6. Call the API function:

ServerAuth::getAPI()->api_function();

ServerAuth API Events

ServerAuthAuthenticateEvent:

This event is handled when a player log into his account.

Event functions are:

Get Player:
Player getPlayer()

Description:
Get event player.
Return:
The event player

ServerAuthDeauthenticateEvent:

This event is handled when a player log out from his account.

Event functions are:

Get Player:
Player getPlayer()

Description:
Get event player.
Return:
The event player

ServerAuthPasswordChangeEvent:

This event is handled when a player changes his account password.

Event functions are:

Get Player:
Player getPlayer()

Description:
Get event player.
Return:
The event player

Get Password:
string getPassword()

Description:
Get the new password.
Return:
The new password

ServerAuthRegisterEvent:

This event is handled when a player registers an account.

Event functions are:

Get Player:
Player getPlayer()

Description:
Get event player.
Return:
The event player

Get Password:
string getPassword()

Description:
Get password (it can be hashed or not).
Return:
The password

ServerAuthUnregisterEvent:

This event is handled when a player unregisters his account.

Event functions are:

Get Player:
Player getPlayer()

Description:
Get event player.
Return:
The event player

ServerAuth API Functions