Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[NEW-API] Get sign text in PlayerInteractEvent

Comments in 'Plugin Development' started by YoDevil, Jul 15, 2014.

  1. YoDevil
    Offline

    YoDevil New Member

    Joined:
    May 12, 2014
    Posts:
    10
    Minecraft User:
    YoDevil
    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? :)
  2. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    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.
    Taha_The_Hacker and PEMapModder like this.
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    SignPost doesn't have a function called getText(). Get the tile from the level using $level->getTile().
    thebigsmileXD likes this.
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    $block is already an instance of Vector3. You can put $block instead of new Vector3(...).
  5. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    Oh lol
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    $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).
  7. YoDevil
    Offline

    YoDevil New Member

    Joined:
    May 12, 2014
    Posts:
    10
    Minecraft User:
    YoDevil
    Yeah this worked, thank you both ;)
    PEMapModder likes this.
  8. YoDevil
    Offline

    YoDevil New Member

    Joined:
    May 12, 2014
    Posts:
    10
    Minecraft User:
    YoDevil
    Ah, one last thing: will PlayerInteractEvent event ever be called also if I don't have anything in my hand?
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I think yes. The item will become air. (Instance of Air)
  10. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    I don't know. I hope so.
    PEMapModder likes this.

Share This Page

Advertisement