Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace MOTD;
- use pocketmine\plugin\PluginBase;
- use pocketmine\event\Listener;
- use pocketmine\event\player\PlayerJoinEvent;
- use pocketmine\event\player\PlayerQuitEvent;
- class MOTD extends PluginBase implements Listener {
- public function onEnable() {
- //Sets the amount of online players to 0
- $onlinePlayers = 0;
- //Registers the events
- $this->getServer()->getPluginManager()->registerEvents($this, $this);
- //Logs the message that the plugin was enabled
- $this->getLogger()->info("MOTD Has been enabled!");
- }
- public function onLoad() {
- //Saves config
- $this->saveDefaultConfig();
- }
- public function onDisable() {
- //Saves config
- $this->saveDefaultConfig();
- }
- //Triggered when a player joins the server
- public function playerJoin(PlayerJoinEvent $PJE) {
- $ip = $PJE->getPlayer()->getAddress();
- $details = json_decode(file_get_contents("http://ipinfo.io/" . $PJE->getPlayer()->getAddress() ."/json"));
- if(isset($details->city)) {
- $this->getLogger()->info("City:" . $details->city);
- }
- else {
- $this->getLogger()->info("NOPE.");
- }
- //Gets the variable
- global $onlinePlayers;
- //Adds 1 to the amount of players online
- $onlinePlayers++;
- //The array of strings that will be replaced
- $variablesToReplace = array("@player" => $PJE->getPlayer()->getName(), "@ip" => $PJE->getPlayer()->getAddress(), "@onlineplayers" => $onlinePlayers, "@maxplayers" => $this->getServer()->getMaxPlayers());
- //Sets the join message
- $PJE->setJoinMessage(strtr($this->getConfig()->get("JoinMessage"), $variablesToReplace));
- //Sends the player that joined the Message of the day
- $PJE->getPlayer()->sendMessage(strtr($this->getConfig()->get("MOTD"), $variablesToReplace));
- //If true, the console will show the message the server was shown when the player joined
- if($this->getConfig()->get("LogMessages") === true) {
- //Logs the message
- $this->getLogger()->info(strtr($this->getConfig()->get("JoinMessage"), $variablesToReplace));
- }
- }
- //Triggered when a player leaves the server
- public function playerQuit(PlayerQuitEvent $PQE) {
- //Gets the variable
- global $onlinePlayers;
- //Removes 1 to the amount of players online
- $onlinePlayers--;
- //The array of strings that will be replaced
- $variablesToReplace = array("@player" => $PQE->getPlayer()->getName(), "@ip" => $PQE->getPlayer()->getAddress(), "@onlineplayers" => $onlinePlayers, "@maxplayers" => $this->getServer()->getMaxPlayers());
- //Sets the quit message
- $PQE->setQuitMessage(strtr($this->getConfig()->get("QuitMessage"), $variablesToReplace));
- //If true, the console will show the message the server was shown when the player joined
- if($this->getConfig()->get("LogMessages") === true) {
- //Logs the message
- $this->getLogger()->info(strtr($this->getConfig()->get("QuitMessage"), $variablesToReplace));
- }
- }
- }
- /*Planned features:
- * The ability to retrieve a players location (Country and region only)
- * Restricted due to the fact revealing info like their home address could be
- * called IOP (Invasion of Privacy).
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement