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

{new api} how to get the text on the sign, on the first line.

Comments in 'Plugin Development' started by Killman2, Jul 6, 2014.

  1. Killman2
    Offline

    Killman2 Active Member Plugin Developer

    Joined:
    May 5, 2014
    Posts:
    81
    Plugins:
    1
    Minecraft User:
    Killman2
    Hi, I am updating my K2SignStats plugin, and I was wondering how do you get the text on the first line of the sign. Like :

    PHP:
     if($data->data["Text1"] == "bla"){
    //code
    How do you make that for the new api?
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Did you know that not every plugin developer likes to call their variables $data?
    We don't even know what your event is.
  3. Killman2
    Offline

    Killman2 Active Member Plugin Developer

    Joined:
    May 5, 2014
    Posts:
    81
    Plugins:
    1
    Minecraft User:
    Killman2
    PHP:
    //there is the hole function
        
    public function eventHandler($data$event)
        {
            switch(
    $event)
            {
                case 
    "tile.update":
                if(!(
    $data instanceof Tile)){return;}
                if(
    $data->class != TILE_SIGN){return;}
                if (
    $data->data["Text1"] == 'stats'){
                
    $world $this->api->level->getDefault();
                    if (
    $world)
                    {
                    
    $players count($world->players);
                    
    $data->data["Text1"]="[SignStats]";
                    
    $data->data["Text2"]= "Players Online:";
                    
    $data->data["Text3"]= $players;
                    
    $data->data["Text4"]= "============================";
                    
    $this->api->tile->spawnToAll($data);
                    }
                    else
                    {
                    
    $data->data["Text1"]="ERROR";
                    
    $data->data["Text2"]="ERROR";
                    
    $this->api->tile->spawnToAll($data);
                    }
                }
                break;
            }
        }
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    BTW, use == instead of === as a good practice.

    I don't think there is presently an event for it.
  5. Killman2
    Offline

    Killman2 Active Member Plugin Developer

    Joined:
    May 5, 2014
    Posts:
    81
    Plugins:
    1
    Minecraft User:
    Killman2
    Ok, thanks for answering :)
  6. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    435
    Plugins:
    4
    Minecraft User:
    Lambo
    Get the tile and make sure it is a sign, use $tile->getText() which will return a array and use $array[0] for the first text
    Killman2 likes this.
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    And tile.update? The problem is how you get the sign you want.
  8. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,132
    Plugins:
    4
    Minecraft User:
    iksaku
    There's a function yo request the update if the sign... Maybe on "Tile" class :p
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Yes, but the event?
  10. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,132
    Plugins:
    4
    Minecraft User:
    iksaku
    Yes, it's possible, try this:
    PHP:
    use pocketmine\tile\Sign;

    ============
    =
    Other code=
    ============

    public function 
    onBlockPlace(BlockPlaceEvent $event){
            
    $players count($event->getPlayer()->getLevel()->getPlayers());
            
    $block $event->getBlock();
            if(
    $block instanceof Sign){
                
    $text $block->getText();
                if(
    strtolower($text[0]) == "stats"){
                    
    $text[0] = "[SignStats]";
                    
    $text[1] = "Players Online:";
                    
    $text[2] = $players;
                    
    $text[3] = "============================";
                }
                
    $block->scheduleUpdate();
            }
    }
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Sign place ≠ sign text inputed (posted at 2:21 a.m. at my time zone)
  12. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,132
    Plugins:
    4
    Minecraft User:
    iksaku
    :p you need to put the text when placing the sign because you can't edit a previously placed sign xD so it can work ;)
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    No. When you tap a ground, your client shows up the sign input window. However, a message that places the sign is sent to the server. When you finish the sign, the server will not receive a packet about a block touched/placed, so such event won't be triggered. The block place event is triggered before the player finishes the sign.
  14. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,132
    Plugins:
    4
    Minecraft User:
    iksaku
    true :/ well... there may be another event available, let me search :p
  15. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I think not yet :p
  16. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,132
    Plugins:
    4
    Minecraft User:
    iksaku
    A temporary solution can be to register (change or modify) the sign tapping it, I believe that is easy ;)
    P.S: This will help me with EssentialsPE Warp & Teleport Signs :D
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    The words are not set when the event is called...

    P.S. I found it (maybe) possible by monitoring the receiving of EntityDataPacket.

    P.P.S. Posted at 2:46 a.m. Reason: E_CANNOT_SLEEP.
    Last edited: Jul 6, 2014
    Tuff likes this.
  18. Killman2
    Offline

    Killman2 Active Member Plugin Developer

    Joined:
    May 5, 2014
    Posts:
    81
    Plugins:
    1
    Minecraft User:
    Killman2
    LOL : D
  19. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    use Scheduling
  20. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Schedule how long? What if the player never typed in a value or took a whole hour to write it (like AFK)?

Share This Page

Advertisement