-
-
Notifications
You must be signed in to change notification settings - Fork 39
ServerAuth API
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();
This event is handled when a player log into his account.
Event functions are:
Player getPlayer()
Description:
Get event player.
Return:
The event player
This event is handled when a player log out from his account.
Event functions are:
Player getPlayer()
Description:
Get event player.
Return:
The event player
This event is handled when a player changes his account password.
Event functions are:
Player getPlayer()
Description:
Get event player.
Return:
The event player
string getPassword()
Description:
Get the new password.
Return:
The new password
This event is handled when a player registers an account.
Event functions are:
Player getPlayer()
Description:
Get event player.
Return:
The event player
string getPassword()
Description:
Get password (it can be hashed or not).
Return:
The password
This event is handled when a player unregisters his account.
Event functions are:
Player getPlayer()
Description:
Get event player.
Return:
The event player
Description:
User not registered
Value:
0
Description:
Success
Value:
1
Description:
Wrong password error
Value:
2
Description:
User not authenticated error
Value:
3
Description:
User already authenticated error
Value:
4
Description:
User already registered error
Value:
5
Description:
Password too short error
Value:
6
Description:
Password too long error
Value:
7
Description:
Max number of same IPs reached error
Value:
8
Description:
A generic error
Value:
9
string getVersion()
Description:
Get ServerAuth plugin version
Return:
plugin version
string getAPIVersion()
Description:
Get the ServerAuth API version.
Return:
plugin API version
mysqli|boolean getDatabase()
Description:
Get ServerAuth MySQLi instance.
Return:
mysqli on success
false on MySQL connection failure
array getDatabaseConfig()
Description:
Get ServerAuth MySQL configuration array.
Return:
array
boolean getDataProvider()
Description:
Get ServerAuth data provider.
Return:
true if ServerAuth is using MySQL
false if ServerAuth is using YAML config
boolean areRegisterMessagesEnabled()
Description:
Check if register messages are enabled.
Return:
boolean
function enableRegisterMessages($bool)
Parameters:
$bool true to enable them or false to disable them
Description:
Enable\Disable register messages
boolean areLoginMessagesEnabled()
Description:
Check if login messages are enabled.
Return:
boolean
function enableLoginMessages($bool)
Parameters:
$bool true to enable them or false to disable them
Description:
Enable\Disable login messages
ServerAuth
ServerAuth Web API
ServerAuth Account Manager