Hi, I want to get the text from a sign when I click it. I'm using the PlayerInteractEvent, although it does not work if I have nothing in selected in my inventory. Anyway, my code is this: PHP: public function playerBlockTouch(PlayerInteractEvent $event){ $player = $event->getPlayer(); $block = $event->getBlock(); $player->sendMessage("Block clicked!"); if($block->getID() == 323 || $block->getID() == 63 || $block->getID() == 68){ $player->sendMessage("Sign clicked!"); $text = $block->getText(); //some other code } } But this doesn't work, the console returns an error with the getText() function: I've tried also by using PHP: if($block instanceof Sign){ instead of PHP: if($block->getID() == 323 || $block->getID() == 63 || $block->getID() == 68){ but i don't receive the "Sign clicked!" message, so apparently $block is not a Sign object; probably it's just a Block object, and I can't use getText() on a non-Sign object. I don't really know! Can someone help me?
PHP: if($blockID==63 or $blockID==68 or $blockID==323){ $tile = $event->getBlock()->getLevel()->getTile(new Vector3($event->getBlock()->getX(),$event->getBlock()->getY(),$event->getBlock()->getZ())); if($tile instanceof Sign){ $text = $tile->getText(); $event->getPlayer()->sendMessage("The first line of the sign is ".$text[0]); }} Hope this helped.
SignPost doesn't have a function called getText(). Get the tile from the level using $level->getTile().
$block is not an instance of Sign. It is an instance of SignPost. SignPost is a subclass of block\Block. Sign is a subclass of Tile. They are different, although similar (both as subclasses of Position).
Ah, one last thing: will PlayerInteractEvent event ever be called also if I don't have anything in my hand?