PHP code example of sofe / infoapi

1. Go to this page and download the library: Download sofe/infoapi 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/ */

    

sofe / infoapi example snippets


use SOFe\InfoAPI;

// $this is the plugin main
$player->sendMessage(InfoAPI::render($this, $this->getConfig()->get("format"), [
    "arg" => $arg,
], $player));

use SOFe\AwaitGenerator\Await;
use SOFe\InfoAPI;

Await::f2c(function() use($player) {
    $traverser = InfoAPI::renderContinuous($this, $this->getConfig()->get("format"), [
        "arg" => $arg,
    ], $player);

    while(yield from $traverser->next($message)) {
        $player->sendPopup($message);
    }
});

InfoAPI::addMapping(
    $this, "myplugin.money",
    fn(Player $player) : ?int => $this->getMoney($player),
);

InfoAPI::addMapping(
    $this, "myplugin.money",
    fn(Player $player) : ?int => $this->getMoney($player),
    watchChanges: fn(Player $player) => Events::watch(
        $this, MoneyChangeEvent::class, $player->getName(),
        fn(MoneyChangeEvent $event) => $event->getPlayer()->getName(),
    )->asGenerator(),
);