-
Notifications
You must be signed in to change notification settings - Fork 0
Home
HittmanA edited this page Feb 12, 2016
·
2 revisions
Welcome to the SAM-join-messages wiki! Let me explain the code.
First here is the code:
<?php
namespace Hittmana\SAM;
use pocketmine\plugin\PluginBase;
use pocketmine\event\player\PlayerJoinEvent;
use pocketmine\Player;
use pocketmine\Server;
use pocketmine\event\Listener;
class MainClass extends PluginBase implements Listener{
public function onEnable()
{
$this->getLogger()->info("[SAM] SAM v0.0.1 enabled");
$this->getServer()->getPluginManager()->registerEvents($this, $this);
}
public function onDisable()
{
$this->getLogger()->info("[SAM] SAM v0.0.1 disabled");
}
function onJoin(PlayerJoinEvent $event)
{
$name = $event->getPlayer()->getDisplayName();
if ($registered = FALSE){
//$registered is whether or not the player is registered. Set it to retrieve the players info from the $url
$name->sendMessage("[SAM] Hello " . $name . " this server use SAM by Edwardthedog2. You must register at " . $url . " to play");
//$url is the url of the users website
}
if ($registered = TRUE){
//$registered is whether or not the player is registered. Set it to retrieve the players info from the $url
$name->sendMessage("[SAM] Hello" . $name . " To play you must login with /login (your password)");
//$url is the url of the users website
}
}
}
Now lets go over what does what :).
First:
public function onEnable()
{
$this->getLogger()->info("[SAM] SAM v0.0.1 enabled");
$this->getServer()->getPluginManager()->registerEvents($this, $this);
}
public function onDisable()
{
$this->getLogger()->info("[SAM] SAM v0.0.1 disabled");
}
This is just sending messages to the console on Enable and Disable. these can be changed safely.
Next:
if ($registered = FALSE){
//$registered is whether or not the player is registered. Set it to retrieve the players info from the $url
$name->sendMessage("[SAM] Hello " . $name . " this server use SAM by Edwardthedog2. You must register at " . $url . " to play");
//$url is the url of the users website
}
Lets break down what some of the confusing variables ($) do!
$registered
Is whether or not the player is registered. You will have to use this var as a boolean and must figure out how to retrieve whether or not the user is registered from the website yourself as I don't know how you do this.
$url
Is the url of then website they must register at. This is just so the player knows where to register.
if ($registered = TRUE){
//$registered is whether or not the player is registered. Set it to retrieve the players info from the $url
$name->sendMessage("[SAM] Hello" . $name . " To play you must login with /login (your password)");
//$url is the url of the users website
}
Is the message it sends if the player IS registered.
$name
Is the players DisplayName.