PHP code example of achedon12 / golem

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

    

achedon12 / golem example snippets


final class WelcomeTest extends TestCase
{
    public function testGreetsPlayersByName(): Generator
    {
        $steve = yield $this->golem('Steve');      // a real Player joins the server

        $this->assertReceivedMessage($steve, 'Welcome, Steve!');
        $this->assertHasItem($steve, VanillaItems::BREAD(), 3);
    }

    public function testMenuTeleportsToSpawn(): Generator
    {
        $steve = yield $this->golem('Steve');
        $steve->teleport($this->spawn()->add(40, 0, 40));

        $steve->chat('/menu');
        $steve->clickButton('Spawn');               // answer the form like a player would

        $this->assertAt($steve, $this->spawn());
    }
}

public function testHealCooldown(): Generator
{
    $steve = yield $this->golem('Steve');
    $steve->op()->player()->setHealth(4);

    $steve->chat('/heal');
    $steve->player()->setHealth(4);
    $steve->chat('/heal');
    $this->assertHealth($steve, 4);                // still on cooldown

    yield $this->wait(5 * 20);                      // five seconds later...
    $steve->chat('/heal');
    $this->assertHealth($steve, 20);
}