Skip to content

Conversation

@PJZ9n
Copy link

@PJZ9n PJZ9n commented Feb 10, 2022

Introduction

Make Flowy compatible with PocketMine-MP API 4.0.0

test

PocketMine-MP Version: 4.0.8 (git hash: 8a4bc72b3443a61db9a58c51f7aeac14c3d6e42d)

<?php

declare(strict_types=1);

/**
 * @name FlowyPM4Test
 * @version 0.0.1
 * @main pjz9n\flowypm4test\Main
 * @api 4.0.0
 */

namespace pjz9n\flowypm4test;

use flowy\Flowy;
use flowy\standard\Standard;
use pocketmine\event\Event;
use pocketmine\plugin\PluginBase;
use function flowy\listen;
use function flowy\standard\delay;
use function flowy\start;

class Main extends PluginBase
{
    protected function onEnable(): void
    {
        Flowy::bootstrap();
        Standard::bootstrap();

        $stream = start($this);
        $stream->run(function ($stream) {
            $this->getLogger()->info("Hello! test starting...");

            $this->getLogger()->info("Event handle test");
            /** @var TestEvent $event */
            $event = yield listen(TestEvent::class);
            $this->getLogger()->info("Event handle test: OK");

            $this->getLogger()->info("Delay test");
            $startTick = $this->getServer()->getTick();
            $delayTick = 20;
            $this->getLogger()->info("Delay test: Delay $delayTick tick...");
            yield from delay($this->getScheduler(), $delayTick);
            $endTick = $this->getServer()->getTick();
            $diff = $endTick - $startTick;
            $this->getLogger()->info("Delay test: start: $startTick, end: $endTick, diff: $diff");
            if ($diff === $delayTick) {
                $this->getLogger()->info("Delay test: OK");
            } else {
                $this->getLogger()->error("Delay test: Delay is not working");
            }
        });

        $event = new TestEvent();
        $event->call();
    }
}

class TestEvent extends Event
{
    //NOOP
}

output

[Server thread/INFO]: [FlowyPM4Test] Hello! test starting...
[Server thread/INFO]: [FlowyPM4Test] Event handle test
[Server thread/INFO]: [FlowyPM4Test] Event handle test: OK
[Server thread/INFO]: [FlowyPM4Test] Delay test
[Server thread/INFO]: [FlowyPM4Test] Delay test: Delay 20 tick...
[Server thread/INFO]: [FlowyPM4Test] Delay test: start: 0, end: 20, diff: 20
[Server thread/INFO]: [FlowyPM4Test] Delay test: OK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant