Merge branch 'dev' of Point808/PMMP_Plugins into master
This commit is contained in:
commit
6d36a6df9e
@ -5,3 +5,5 @@ PMMP plugin to email admins on some server events
|
|||||||
Tested on 3.0.0-ALPHA5.
|
Tested on 3.0.0-ALPHA5.
|
||||||
|
|
||||||
Edit config.yml with the address to send to. Your server will need to be set up to send email properly via php.
|
Edit config.yml with the address to send to. Your server will need to be set up to send email properly via php.
|
||||||
|
|
||||||
|
PNAME will be replaced with player name
|
@ -1,5 +1,5 @@
|
|||||||
name: AdminMail
|
name: AdminMail
|
||||||
main: AdminMail\AdminMail
|
main: AdminMail\Main
|
||||||
api: 3.0.0-ALPHA5
|
api: 3.0.0-ALPHA5
|
||||||
version: 0.0.1
|
version: 0.0.1
|
||||||
description: "Administrative email on events"
|
description: "Administrative email on events"
|
||||||
|
@ -1,2 +1,4 @@
|
|||||||
enabled: true
|
enabled: true
|
||||||
adminmail: youradmin@email.com
|
adminmail: youradmin@email.com
|
||||||
|
adminsubject: PMMP - Player PNAME has joined
|
||||||
|
adminmessage: Hello. This is to let you know player PNAME has joined the server.
|
45
AdminMail/src/AdminMail/EmailTask.php
Normal file
45
AdminMail/src/AdminMail/EmailTask.php
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace AdminMail;
|
||||||
|
|
||||||
|
use pocketmine\scheduler\PluginTask;
|
||||||
|
use pocketmine\Player;
|
||||||
|
use pocketmine\event\player\PlayerJoinEvent;
|
||||||
|
use pocketmine\plugin\PluginBase;
|
||||||
|
use pocketmine\event\Listener;
|
||||||
|
use pocketmine\command\Command;
|
||||||
|
use pocketmine\command\CommandSender;
|
||||||
|
use pocketmine\utils\Config;
|
||||||
|
use AdminMail\Main;
|
||||||
|
|
||||||
|
class EmailTask extends PluginTask {
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct(Main $main, string $adminmail, string $playername, string $adminsubject, string $adminmessage) {
|
||||||
|
parent::__construct($main);
|
||||||
|
$this->playername = $playername;
|
||||||
|
$this->adminmail = $adminmail;
|
||||||
|
$this->adminsubject = $adminsubject;
|
||||||
|
$this->adminmessage = $adminmessage;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onRun($tick) { //
|
||||||
|
|
||||||
|
$player = $this->getOwner()->getServer()->getPlayer($this->playername);
|
||||||
|
$name = $player->getName();
|
||||||
|
|
||||||
|
$admin = $this->adminmail;
|
||||||
|
$admin1 = $this->adminsubject;
|
||||||
|
$admin1 = str_replace("PNAME", $name, $admin1);
|
||||||
|
|
||||||
|
$admin2 = $this->adminmessage;
|
||||||
|
$admin2 = str_replace("PNAME", $name, $admin2);
|
||||||
|
|
||||||
|
|
||||||
|
// $adminmail = $this->getConfig()->get("adminmail");
|
||||||
|
|
||||||
|
|
||||||
|
mail($admin, $admin1, $admin2);
|
||||||
|
}
|
||||||
|
}
|
@ -11,7 +11,8 @@ use pocketmine\command\CommandSender;
|
|||||||
use pocketmine\utils\Config;
|
use pocketmine\utils\Config;
|
||||||
|
|
||||||
|
|
||||||
class AdminMail extends PluginBase implements Listener {
|
class Main extends PluginBase implements Listener {
|
||||||
|
|
||||||
|
|
||||||
public function onLoad() { # Called when the plugin is being loaded by the server
|
public function onLoad() { # Called when the plugin is being loaded by the server
|
||||||
$this->getLogger()->info("Loading plugin..."); # Logs to the console
|
$this->getLogger()->info("Loading plugin..."); # Logs to the console
|
||||||
@ -33,10 +34,20 @@ class AdminMail extends PluginBase implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function onJoin(PlayerJoinEvent $event) { # Called when a player joins
|
public function onJoin(PlayerJoinEvent $event) { # Called when a player joins
|
||||||
$player = $event->getPlayer();
|
$player = $event->getPlayer();
|
||||||
$name = $player->getName();
|
$name = $player->getName();
|
||||||
$adminmail = $this->getConfig()->get("adminmail");
|
$adminmail = $this->getConfig()->get("adminmail");
|
||||||
mail($adminmail, "PMMP - $name joined", "Hello, player $name has joined the server.");
|
$adminsubject = $this->getConfig()->get("adminsubject");
|
||||||
|
$adminmessage = $this->getConfig()->get("adminmessage");
|
||||||
|
|
||||||
|
|
||||||
|
//mail($adminmail, "PMMP - $name joined", "Hello, player $name has joined the server.");
|
||||||
|
//sleep(10);
|
||||||
|
$task = new EmailTask($this, $adminmail, $name, $adminsubject, $adminmessage); // Create the new class Task by calling
|
||||||
|
$this->getServer()->getScheduler()->scheduleDelayedTask($task, 5*20); // Counted in ticks (1 second = 20 ticks)
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user