PHP code example of ninjaknights / drawerapi

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

    

ninjaknights / drawerapi example snippets


use ninjaknights\drawerAPI\DrawerAPI;
class MyPlugin extends PluginBase {
	public function onLoad(): void {
		if(!DrawerAPI::isRegistered()){
			DrawerAPI::register($this);
		}
	}
}

use ninjaknights\drawerAPI\shape\Text;
// Create a text shape
Text::create(
	$world, // Player/World Players to show the text to
	"Hello, World!", // The text to display
	new Vector3(0, 100, 0), // Position in the world or set to null to use player's position
	ShapeColor::WHITE->value, // Color name "red" or #f0f0f0, f0f0f0 or ShapeColor enum works too
);

use ninjaknights\drawerAPI\shape\Circle;
// Create a text shape
Circle::create(
	$world, // Player/World Players to show the text to
	new Vector3(0, 100, 0), // Position in the world or set to null to use player's position
	1.0, // Scale of the shape
	"#ff0000", // Color name or #f0f0f0, f0f0f0 or ShapeColor enum works too
	3 // 3 means it will have 3 sides so a triangle, default is 20 (not sure)
);

use ninjaknights\drawerAPI\shape\Cube;
// Create a cube shape
Cube::create(
	$world, // Player/World Players to show the text to
	new Vector3(0, 100, 0), // Position in the world or set to null to use player's position
	"Hi there", // text of the shape
	"#ff0000", // Color name or #f0f0f0, f0f0f0 or ShapeColor enum works too
	10 // lifespan meaning it will stay in the world for 10 seconds after spawning
);

use ninjaknights\drawerAPI\DrawerAPI;
DrawerAPI::clearAll(ShapeType::TEXT, $world); // Clears all text shapes for the specified world
DrawerAPI::clearAll(ShapeType::ARROW, $player); // Clears all arrow shapes for the specified player

use ninjaknights\drawerAPI\shape\Text;
Text::removeById($world, 1); // Removes the text shape with ID 1 for the player/world players

use ninjaknights\drawerAPI\shape\Cube;
Text::clear($world); // Removes the cube shape for the player/world players

use ninjaknights\drawerAPI\DrawerAPI;
use ninjaknights\drawerAPI\ShapeType;

$activeIds = DrawerAPI::getIdList(ShapeType::LINE);
foreach ($activeIds as $id) {
	echo "Line shape active with ID: $id\n";
}

DrawerAPI::isActiveId(ShapeType::CIRCLE, 5); // Returns true/false

$lastId = DrawerAPI::getId(ShapeType::BOX);

$pmColor = ShapeColor::WHITE->toColor(); // pocketmine\color\Color
// or
$color = ShapeColor::fromString("cyan");
if ($color !== null) {
	$pmColor = $color->toColor(); // pocketmine\color\Color
}