diff --git a/AdminMail/README.md b/AdminMail/README.md index 5c12064..972d106 100644 --- a/AdminMail/README.md +++ b/AdminMail/README.md @@ -1,7 +1,9 @@ -# AdminMail - -PMMP plugin to email admins on some server events - -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. \ No newline at end of file +# AdminMail + +PMMP plugin to email admins on some server events + +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. + +PNAME will be replaced with player name \ No newline at end of file diff --git a/AdminMail/plugin.yml b/AdminMail/plugin.yml index ca949ac..8aa5ed3 100644 --- a/AdminMail/plugin.yml +++ b/AdminMail/plugin.yml @@ -1,5 +1,5 @@ name: AdminMail -main: AdminMail\AdminMail +main: AdminMail\Main api: 3.0.0-ALPHA5 version: 0.0.1 description: "Administrative email on events" diff --git a/AdminMail/resources/config.yml b/AdminMail/resources/config.yml index 05acf54..0858fa2 100644 --- a/AdminMail/resources/config.yml +++ b/AdminMail/resources/config.yml @@ -1,2 +1,4 @@ enabled: true adminmail: youradmin@email.com +adminsubject: PMMP - Player PNAME has joined +adminmessage: Hello. This is to let you know player PNAME has joined the server. \ No newline at end of file diff --git a/AdminMail/src/AdminMail/EmailTask.php b/AdminMail/src/AdminMail/EmailTask.php new file mode 100644 index 0000000..489698c --- /dev/null +++ b/AdminMail/src/AdminMail/EmailTask.php @@ -0,0 +1,45 @@ +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); +} +} \ No newline at end of file diff --git a/AdminMail/src/AdminMail/AdminMail.php b/AdminMail/src/AdminMail/Main.php similarity index 71% rename from AdminMail/src/AdminMail/AdminMail.php rename to AdminMail/src/AdminMail/Main.php index d4a11de..d0b8a4b 100644 --- a/AdminMail/src/AdminMail/AdminMail.php +++ b/AdminMail/src/AdminMail/Main.php @@ -11,7 +11,8 @@ use pocketmine\command\CommandSender; 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 $this->getLogger()->info("Loading plugin..."); # Logs to the console @@ -32,11 +33,21 @@ class AdminMail extends PluginBase implements Listener { $sender->sendMessage("This is an example command"); # Sends to the sender } } - + + + + public function onJoin(PlayerJoinEvent $event) { # Called when a player joins $player = $event->getPlayer(); $name = $player->getName(); $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) } } \ No newline at end of file