1. Go to this page and download the library: Download cosmicpe/blockdata 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/ */
cosmicpe / blockdata example snippets
final class MyPlugin extends PluginBase{
/** @var BlockDataWorldManager */
private $manager;
protected function onEnable() : void{
$this->manager = BlockDataWorldManager::create($this);
}
}
class BlockHistoryData extends BlockData{ // stores when block was placed and by whom.
public static function nbtDeserialize(CompoundTag $nbt) : BlockData{
return new BlockHistoryData($nbt->getString("placer"), $nbt->getLong("timestamp"));
}
/** @var string */
private $placer;
/** @var int */
private $timestamp;
public function __construct(string $placer, ?int $timestamp = null){
$this->placer = $placer;
$this->timestamp = $timestamp ?? time();
}
public function getPlacer() : string{
return $this->placer;
}
public function getTimestamp() : int{
return $this->timestamp;
}
public function nbtSerialize() : CompoundTag{
return CompoundTag::create()
->setString("placer", $this->placer)
->setLong("timestamp", $this->timestamp);
}
}