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

How to get a plugin to Read whats on a sign Detect when its tapped and Write whats on the sign

Comments in 'Plugin Development' started by Hittmana, Feb 2, 2016.

  1. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    I would like to know how to have my plugin Read whats on a sign when a player places it, How to detect when its tapped, and write what is on the sign. Thanks in advance!
  2. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    PHP:
        public function playerBlockTouch(PlayerInteractEvent $event)
                
    $sign $event->getPlayer()->getLevel()->getTile($event->getBlock());
                if(!(
    $sign instanceof Sign)){
                    return;
                }
                
    $sign $sign->getText();
                
    $sign[0//Line1
                
    $sign[1//Line2
                
    $sign[2//Line3
                
    $sign[3//Line4

        
    }
    Hittmana likes this.
  3. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    There is such thing called PocketMine API Documentation.
    PHP:
    public function onSignChange(SignChangeEvent $event){
    $line_1 $event->getLine(0);
    // ... and so on

    // Write something on sign
    // $sign is instanceof Sign
    // Or you may use $event in this function context
    $sign->setLine(0"Text");
    $event->setLine(0"Text");
    }
    Hittmana likes this.
  4. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    Thx guys!
  5. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    I am guessing i need to import (use) pocketmine\block\Sign right?
  6. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    He asked for tap event
  7. FlamingGenius
    Offline

    FlamingGenius Active Member

    Joined:
    Sep 23, 2015
    Posts:
    173
    Minecraft User:
    FlamingGenius
    why are you telling him code to write to the sign he wants to get the text on the sign what @Tim // robske Büba said was correct
  8. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    No, you don't need it.
    Also, it's not a block, it's a tile.
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    This is off-topic, but as a matter of fact, you can make your event handler function names, as long as not conflicting and not going to conflict, as simple as possible, because nobody would really read them. It may be good to make them represent what event they handle (and usually start with `on` so that callers can notice that they are event handlers and instantly skip them as they are not (generally) useful), but the parameter already explains everything, so you don't really need to make it so descriptive like playerBlockTouch, but is OK to be as simple as onBT ;)
  10. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Grammar.
  11. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    No.
    pocketmine\tile\Sign;

Share This Page

Advertisement