Skip to content

Instantly share code, notes, and snippets.

@PJZ9n
Created June 4, 2020 21:39
Show Gist options
  • Save PJZ9n/b42946f8ab823336d6f3034f51db94a3 to your computer and use it in GitHub Desktop.
Save PJZ9n/b42946f8ab823336d6f3034f51db94a3 to your computer and use it in GitHub Desktop.
<?php
declare(strict_types=1);
start($this)->run(function (EventStream $eventStream) {
while (true) {
/** @var PlayerJoinEvent $event */
$event = yield listen(PlayerJoinEvent::class);
$player = $event->getPlayer();
$playerStream = $eventStream->filter(function ($ev) use ($player) {
return !($ev instanceof PlayerEvent) || $ev->getPlayer() === $player;
})->stream();
$playerStream->run(function ($stream) {
$lastTick = 0;
while (true) {
/** @var PlayerInteractEvent $event */
$event = yield listen(PlayerInteractEvent::class);
$currentTick = $this->getServer()->getTick();
if ($currentTick - $lastTick < 10) {
$event->setCancelled();
}
$lastTick = $currentTick;
$event->getPlayer()->sendMessage("Tap! - " . uniqid());
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment