Text1)){ $nbt->Text1 = new StringTag("Text1", ""); } if(!isset($nbt->Text2)){ $nbt->Text2 = new StringTag("Text2", ""); } if(!isset($nbt->Text3)){ $nbt->Text3 = new StringTag("Text3", ""); } if(!isset($nbt->Text4)){ $nbt->Text4 = new StringTag("Text4", ""); } parent::__construct($level, $nbt); } public function saveNBT(){ parent::saveNBT(); unset($this->namedtag->Creator); } /** * Changes contents of the specific lines to the string provided. * Leaves contents of the specifc lines as is if null is provided. * * @param null|string $line1 * @param null|string $line2 * @param null|string $line3 * @param null|string $line4 * * @return bool */ public function setText($line1 = "", $line2 = "", $line3 = "", $line4 = ""){ if($line1 !== null){ $this->namedtag->Text1->setValue("Text1", $line1); } if($line2 !== null){ $this->namedtag->Text2->setValue("Text2", $line2); } if($line3 !== null){ $this->namedtag->Text3->setValue("Text3", $line3); } if($line4 !== null){ $this->namedtag->Text4->setValue("Text4", $line4); } $this->onChanged(); } /** * @param int $index 0-3 * @param string $line * @param bool $update */ public function setLine(int $index, string $line, bool $update = true){ if($index < 0 or $index > 3){ throw new \InvalidArgumentException("Index must be in the range 0-3!"); } $this->namedtag->{"Text" . ($index + 1)}->setValue($line); if($update){ $this->onChanged(); } } /** * @param int $index 0-3 * * @return string */ public function getLine(int $index) : string{ if($index < 0 or $index > 3){ throw new \InvalidArgumentException("Index must be in the range 0-3!"); } return $this->namedtag->{"Text" . ($index + 1)}->getValue(); } public function getText(){ return [ $this->namedtag->Text1->getValue(), $this->namedtag->Text2->getValue(), $this->namedtag->Text3->getValue(), $this->namedtag->Text4->getValue() ]; } public function addAdditionalSpawnData(CompoundTag $nbt){ for($i = 1; $i <= 4; $i++){ $textKey = "Text" . $i; $nbt->$textKey = $this->namedtag->$textKey; } return $nbt; } public function updateCompoundTag(CompoundTag $nbt, Player $player) : bool{ if($nbt["id"] !== Tile::SIGN){ return false; } $ev = new SignChangeEvent($this->getBlock(), $player, [ TextFormat::clean($nbt->Text1->getValue(), ($removeFormat = $player->getRemoveFormat())), TextFormat::clean($nbt->Text2->getValue(), $removeFormat), TextFormat::clean($nbt->Text3->getValue(), $removeFormat), TextFormat::clean($nbt->Text4->getValue(), $removeFormat) ]); if(!isset($this->namedtag->Creator) or $this->namedtag->Creator->getValue() !== $player->getRawUniqueId()){ $ev->setCancelled(); } $this->level->getServer()->getPluginManager()->callEvent($ev); if(!$ev->isCancelled()){ $this->setText(...$ev->getLines()); return true; }else{ return false; } } }