public function saveMacro($name, Macro $macro)
{
$tag = new tag\Compound();
$tag["author"] = new tag\String("author", $macro->getAuthor());
$tag["description"] = new tag\String("description", $macro->getDescription());
$tag["ops"] = new tag\Enum("ops");
foreach ($macro->getOperations() as $i => $log) {
$tag["ops"][$i] = $log->toTag();
}
$nbt = new NBT();
$nbt->setData($tag);
$file = $this->getFile($name);
$stream = fopen($file, "wb");
if (!is_resource($stream)) {
throw new \RuntimeException("Unable to open stream. Maybe the macro name is not a valid filename?");
}
$compression = $this->getMain()->getConfig()->getAll()["data providers"]["macro"]["mcr"]["compression"];
if ($compression === 0) {
$data = $nbt->write();
} else {
$data = $nbt->writeCompressed($compression);
}
fwrite($stream, chr($compression) . $data);
fclose($stream);
}