Hello i have a simple question How can i give a player sign with text I already know this: give sho sign 16 {display:{Name:"§6§lPLACE ME!"},BlockEntityTag:{Text1:"CUSTOM TEXT",Text2:"----------------",Text3:"I can have",Text4:"default text!"}} But i want to do that with a plugin. sorry for bad england
PHP: $nbt = new CompoundTag("BlockEntityTag", [ new ListTag("Text", "Msg") ]); $sign = ItemFactory::get(Item::SIGN, 0, 1); $sign->setNamedTagEntry($nbt); $sender->getInventory()->addItem($sign); //Dont know if it work but try
For the custom name ("PLACE ME"), there's a direct API method: PHP: $item->setCustomName("PLACE ME!"); For the Block Entity data, since the API methods involved may return null, you'll need to have a check for that. PHP: $tiledata = $item->getCustomBlockData() ?? new CompoundTag();$display_tag = $tiledata->getCompoundTag("display") ?? new CompoundTag("display"); The rest is pretty straight-forward: PHP: $display_tag->setString("Text1", "Line 1");$display_tag->setString("Text2", "Line 2");$display_tag->setString("Text3", "Line 3");$display_tag->setString("Text4", "Line 4");$item->setCustomBlockData($tiledata);
to edit the sign using gettile (set text when placeevent) PHP: $pos = new Vector3(X, Y, Z); //coords$sign = $level->getTile($pos); if($sign instanceof Sign){// check whether sign$sign->setText("Text1", "Text2", "Text3", "Text4"); //set text$sign->saveNBT(); //save the changes}