public static function emit(StringWriter $writer, Clip $clip) { $writer->appendBString($clip->getName()); $writer->appendLong(count($clip->getBlocks())); foreach ($clip->getBlocks() as $key => $block) { $v = Clip::unkey($key); $writer->appendInt($v->x); $writer->appendShort($v->y); $writer->appendInt($v->z); $writer->appendByte($block->getID()); $writer->appendByte($block->getDamage()); } }
public function setClip($name, Clip $clip) { if (strlen($name) >= 64) { throw new \InvalidArgumentException("Clip names must not exceed 64 characters!"); // This exception will be caught at SubcommandMap.php } $blocks = $clip->getBlocks(); $this->deleteClip($name); foreach ($blocks as $keyed => $block) { $unkeyed = Clip::unkey($keyed); $this->db->query("INSERT INTO clipboard_blocks VALUES (\n\t\t\t\t\t'{$this->db->escape_string($clip->getName())}',\n\t\t\t\t\t{$unkeyed->x},\n\t\t\t\t\t{$unkeyed->y},\n\t\t\t\t\t{$unkeyed->z},\n\t\t\t\t\t{$block->getID()},\n\t\t\t\t\t{$block->getDamage()}\n\t\t\t\t\t);"); } }
public function onRun(array $args, Space $space, Player $player) { $anchor = $player->getPosition(); if (isset($args[0]) and ($args[0] === "-a" or $args[0] === "-anchor")) { $anchor = $this->getMain()->getAnchor($player); } if (!isset($args[0])) { array_unshift($args, "default"); } $clip = new Clip($space, $anchor, array_shift($args)); if (isset($args[0]) and ($args[0] === "g" or $args[0] === "global")) { $clipboard = $this->getMain()->getClipboardProvider(); $clipboard[$clip->getName()] = $clip; } else { $this->getMain()->setClip($player, $clip, $clip->getName()); } return "Clip " . $clip->getName() . " copied."; }
/** * @param Player $player * @param Clip $clip * @param string|bool $name */ public function setClip(Player $player, Clip $clip, $name = false) { if ($name === false) { $name = $clip->getName(); } if (!isset($this->clips[$player->getID()])) { $this->clips[$player->getID()] = []; } $this->clips[$player->getID()][$name] = $clip; }