-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.php
42 lines (30 loc) · 1.01 KB
/
Main.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
declare(strict_types=1);
namespace MonoAdrian23\KickAFK;
use pocketmine\event\Listener;
use pocketmine\event\player\PlayerJoinEvent;
use pocketmine\event\player\PlayerMoveEvent;
use pocketmine\event\player\PlayerQuitEvent;
use pocketmine\plugin\PluginBase;
class Main extends PluginBase implements Listener {
/** @var array */
public static $times = [];
public function onEnable()
{
$this->getServer()->getPluginManager()->registerEvents($this, $this);
$this->getScheduler()->scheduleRepeatingTask(new AfkTask($this), 20 * 60);
}
public function onJoin(PlayerJoinEvent $event): void
{
self::$times[$event->getPlayer()->getName()] = time();
}
public function onQuit(PlayerQuitEvent $event): void
{
unset(self::$times[$event->getPlayer()->getName()]);
}
public function onMove(PlayerMoveEvent $event): void
{
if($event->getFrom() === $event->getTo()) return;
self::$times[$event->getPlayer()->getName()] = time();
}
}