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); }
public function saveMacro($name, Macro $macro) { $this->db->query("INSERT INTO macros (name, author, description) VALUES (\n\t\t\t\t'{$this->db->escape_string($name)}',\n\t\t\t\t'{$this->db->escape_string($macro->getAuthor())}',\n\t\t\t\t'{$this->db->escape_string($macro->getDescription())}'\n\t\t\t\t);"); foreach ($macro->getOperations() as $offset => $op) { if ($op->getType() === MacroOperation::TYPE_WAIT) { $this->db->query("INSERT INTO macros_deltas (owner, offset, delta) VALUES (\n\t\t\t\t\t\t'{$this->db->escape_string($name)}',\n\t\t\t\t\t\t{$offset},\n\t\t\t\t\t\t{$op->getLength()}\n\t\t\t\t\t\t);"); } else { $delta = $op->getDelta(); $block = $op->getBlock(); $this->db->query("INSERT INTO macros_ops (owner, offset, x, y, z, id, damage) VALUES (\n\t\t\t\t\t\t'{$this->db->escape_string($name)}',\n\t\t\t\t\t\t{$offset},\n\t\t\t\t\t\t{$delta->x},\n\t\t\t\t\t\t{$delta->y},\n\t\t\t\t\t\t{$delta->z},\n\t\t\t\t\t\t{$block->getID()},\n\t\t\t\t\t\t{$block->getDamage()}\n\t\t\t\t\t\t);"); } } }