Skip to content
This repository was archived by the owner on May 24, 2018. It is now read-only.

Commit df6efa3

Browse files
committed
Added scheduler example
1 parent 9d86adf commit df6efa3

3 files changed

Lines changed: 29 additions & 23 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace ExamplePlugin;
4+
5+
use PocketMine\Player;
6+
use PocketMine\Scheduler\PluginTask;
7+
8+
class BroadcastPluginTask extends PluginTask{
9+
10+
public function onRun($currentTick){
11+
Player::broadcastMessage("[ExamplePlugin] I've ran on tick " . $currentTick);
12+
}
13+
}

src/ExamplePlugin/MainClass.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,20 @@
55
use PocketMine\Command\Command;
66
use PocketMine\Command\CommandSender;
77
use PocketMine\Event\Listener;
8-
use PocketMine\Plugin\EventExecutor;
8+
use PocketMine\Event\Player\PlayerRespawnEvent;
9+
use PocketMine\Player;
910
use PocketMine\Plugin\PluginBase;
1011
use PocketMine\Utils\TextFormat;
1112

12-
class MainClass extends PluginBase{
13-
13+
class MainClass extends PluginBase implements Listener{
14+
1415
public function onLoad(){
1516
console(TextFormat::WHITE . "[ExamplePlugin] I've been loaded!");
1617
}
1718

1819
public function onEnable(){
19-
$this->getServer()->getPluginManager()->registerEvents(new PlayerEventListener(), $this);
20+
$this->getServer()->getPluginManager()->registerEvents($this, $this);
21+
$this->getServer()->getScheduler()->scheduleRepeatingTask(new BroadcastPluginTask($this), 120);
2022
console(TextFormat::DARK_GREEN . "[ExamplePlugin] I've been enabled!");
2123
}
2224

@@ -33,4 +35,14 @@ public function onCommand(CommandSender $sender, Command $command, $label, array
3335
return false;
3436
}
3537
}
38+
39+
/**
40+
* @param PlayerRespawnEvent $event
41+
*
42+
* @priority NORMAL
43+
* @ignoreCancelled false
44+
*/
45+
public function onSpawn(PlayerRespawnEvent $event){
46+
Player::broadcastMessage($event->getPlayer()->getDisplayName() . " has just spawned!");
47+
}
3648
}

src/ExamplePlugin/PlayerEventListener.php

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)