Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
MonoAdrian23 authored Aug 9, 2020
1 parent f6f9f05 commit 47af74e
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 0 deletions.
30 changes: 30 additions & 0 deletions AfkTask.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace MonoAdrian23\KickAFK;

use pocketmine\scheduler\Task;

class AfkTask extends Task {

private $plugin;

public function __construct(Main $plugin)
{
$this->plugin = $plugin;
}

public function onRun(int $currentTick)
{
$afk = $this->plugin->getConfig()->getNested("time");
foreach (Main::$times as $player => $time){
if(time() - $time >= $afk){
$player = $this->plugin->getServer()->getPlayer($player);
if($player){
$player->kick($this->plugin->getConfig()->getNested("kick_message"), false);
}
}
}
}
}
Binary file added KickAFK.phar
Binary file not shown.
42 changes: 42 additions & 0 deletions Main.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,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();
}

}
4 changes: 4 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
time: 600 #afk time in seconds
kick_message: "§l§o§4Du wurdest gekickt da du mehr als 10 Minuten AFK warst!"
...
6 changes: 6 additions & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
name: KickAFK
version: 0.0.1
main: MonoAdrian23\KickAFK\Main
api: 3.14.0
...

0 comments on commit 47af74e

Please sign in to comment.