-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f6f9f05
commit 47af74e
Showing
5 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!" | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
... |