PHP code example of vennv / vapm-pmmp

1. Go to this page and download the library: Download vennv/vapm-pmmp library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vennv / vapm-pmmp example snippets


protected function onEnable() : void
{
    VapmPMMP::init($this);
}

/**
* @param PluginBase $plugin
*
* This method is called by VapmPMMP::init(), it will run event loop.
*/
public static function init(PluginBase $plugin) : void;

$channel = new Channel;
Await::f2c(function() use ($channel) {
    for ($i = 0; $i < 5000000; $i++) {
        yield from $channel->sendAndWait($i);
    }
});

/**
 * @throws Throwable
 */
public function loadWorlds(): Channel
{
    $channel = new Channel();
    CoroutineGen::runNonBlocking(function () use (&$channel): Generator {
        $i = 0;
        foreach (scandir($this->plugin->getServer()->getDataPath() . "worlds") as $world) {
            if ($world === "." || $world === "..") continue;
            if ($this->plugin->getManager()->isIslandNether($world)) {
                $i++;
                yield from $channel->sendGen($i);
                $this->applyIslandNether($world);
            } elseif ($this->plugin->getManager()->isIslandEnd($world)) {
                $i++;
                yield from $channel->sendGen($i);
                $this->applyIslandEnd($world);
            } else {
                $this->applyIslandOverworld($world);
            }
        }
        return $i;
    });
    return $channel;
}

// Process with Task by PMMP
// Load worlds
if (
    self::$doneLoadWorlds === null &&
    (microtime(true) - self::$lastTimeLoadWorlds) >= 5.0
) {
    self::$lastTimeLoadWorlds = microtime(true);
    self::$doneLoadWorlds = $this->plugin->getWorldManager()->loadWorlds();
} elseif (self::$doneLoadWorlds !== null) {
    CoroutineGen::runNonBlocking(function (): Generator {
        yield from self::$doneLoadWorlds->receiveGen(fn() => null);
        self::$doneLoadWorlds = null;
    });
}
// Completely waits and processes each slow incoming content that Channel sends without over-load the server when too many things are sent and received at once.