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

Save all signs with a specific line

Comments in 'Plugin Development' started by AndrewBit, Apr 11, 2016.

  1. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    Hi, I'm trying to save OnEnable all signs with '[Ex-1]' as first line.
    PHP:
    public function setSigns()
        {
            foreach(
    $this->getServer()->getDefaultLevel()->getTiles() as $tile){
                if(
    $tile instanceof Sign){
                    if(
    in_array(substr(TextFormat::clean($tile->getText()[0]), 1, -1),$this->games)){
                        
    array_push($this->sign_object,$tile);
                    }
                }
            }
        }
    I'm using substr because $this->games is array that content other similar strings (Ex-2, Ex-3..) without brackets.
    What I'm doing as bad? I'm trying to update all signs inside $sign_object in another function, but they didn't get updated.

    NOTE: This function is being executed on enable.
  2. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Remeber that you actually have to load the chunks in the level, otherwise technically no tiles are existent
  3. xBeastMode
    Offline

    xBeastMode Active Member

    Joined:
    Nov 27, 2015
    Posts:
    292
    On enable the server hasn't completely loaded and can't access signs. Schedule a task on enable and on that task update all signs. Then cancel it after updating.
    ImagicalGamer and AndrewBit like this.
  4. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    $tile is instanceof Tile not array.
  5. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    Last edited: Apr 12, 2016
    Ritch likes this.
  6. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    Check the tile by converting it to a block and then its ID, because if($tile instanceof Sign){ doesnt work
  7. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
  8. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    And how I can execute method getText without checking if it's a Sign...?
  9. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    As I said, convert the Tile to a Block by doing getBlock() and then check its ID
  10. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    Maybe this is not what is wrong, still not working.
    How I set signs:
    PHP:
    public function setSignsTitle()
        {
            foreach(
    $this->sign_object as $sign)
            {
                
    $game $this->getGame(substr(TextFormat::clean($sign->getText()[0]), 1, -1));
                
    $sign->setText(
                    
    TextFormat::GRAY '[' TextFormat::DARK_BLUE $game->getGame() . TextFormat::GRAY ']',
                    
    TextFormat::YELLOW $game->getStatus(),
                    
    $game->getMapName(),
                    
    TextFormat::BOLD TextFormat::GREEN $game->getNumberOfPlayers() . TextFormat::GRAY '/' TextFormat::RED .'16'
                
    );
            }
        }
    How I SaveSignsTask (on enable) works:
    PHP:
    <?php

    namespace EvolveTSW\task;

    use 
    EvolveTSW\Base;
    use 
    pocketmine\scheduler\PluginTask;

    class 
    SaveSignsTask extends PluginTask
    {
        
    /**@var Base $owner*/
        
    protected $owner;

        
    /**@param Base $owner*/
        
    public function __construct(Base $owner)
        {
            
    parent::__construct($owner);
            
    $this->owner $owner;
        }

        public function 
    OnRun($tick){
            
    $scheduler $this->owner->getServer()->getScheduler();
            
    $scheduler->scheduleRepeatingTask(new SingUpdaterTask($this->owner), 20 5);
            
    $scheduler->cancelTask($this->getTaskId());
        }
    }
    And how SignUpdaterTask works:
    PHP:
    <?php

    namespace EvolveTSW\task;

    use 
    EvolveTSW\Base;
    use 
    pocketmine\scheduler\PluginTask;

    class 
    SingUpdaterTask extends PluginTask
    {
        
    /**@var Base $owner*/
        
    protected $owner;

        
    /**@param Base $owner*/
        
    public function __construct(Base $owner)
        {
            
    $this->owner $owner;
            
    parent::__construct($owner);
        }

        public function 
    OnRun($tick)
        {
            
    $this->owner->setSignsTitle();
        }
    }
    This seems too strange for me, Idk what I'm doing wrong...
    Last edited: Apr 12, 2016
  11. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    Try checking how many tiles are in your level and debug each ID, text...
  12. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    Then it's definetly the string checking, var_dump both strings

Share This Page

Advertisement