1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved TextFormat::colorize returns nothing

Discussion in 'Development' started by Saxavlax001, May 30, 2019.

  1. Saxavlax001

    Saxavlax001 Witch

    Messages:
    63
    GitHub:
    Saxavlax001
    I was trying to fix signs in sw svile plugin,and I think I fixed them, also, I fixed the "must be utf-8 etc." problem that I had,but when I tried TextFormat::colorize ,the colors from the sw sign disappeared like when I used TextFormat::clean .
    PHP:
        /**
         * "@"param bool $all
         * "@"param string $SWname
         * "@"param int $players
         * "@"param int $slot
         * "@"param string $state
         */
        
    public function refreshSigns($all true$SWname ""$players 0$slot 0$state "&fTap to join")
        {
            if (!
    $all) {
                
    $ex explode(':'array_search($SWname$this->signs));
                if (
    count($ex) == 0b100) {
                    
    $this->getServer()->loadLevel($ex[0b11]);
                    if (
    $this->getServer()->getLevelByName($ex[0b11]) != null) {
                        
    $tile $this->getServer()->getLevelByName($ex[0b11])->getTile(new Vector3($ex[0], (int)$ex[1], $ex[2]));
                        if (
    $tile != null && $tile instanceof Sign) {
                            
    $text $tile->getText();
                            
    $tile->setText(TextFormat::colorize($text[0], $text[1], "&a" $players "&7/&a" $slot$state));
                        } else {
                            
    $this->getLogger()->critical('Can\'t get ' $SWname ' sign.Error finding sign on level: ' $ex[0b11] . ' x:' $ex[0] . ' y:' $ex[1] . ' z:' $ex[2]);
                        }
                    }
                }
            } else {
                foreach (
    $this->signs as $key => $val) {
                    
    $ex explode(':'$key);
                    
    $this->getServer()->loadLevel($ex[0b11]);
                    if (
    $this->getServer()->getLevelByName($ex[0b11]) instanceof \pocketmine\level\Level) {
                        
    $tile $this->getServer()->getLevelByName($ex[0b11])->getTile(new Vector3($ex[0], (int)$ex[1], $ex[2]));
                        if (
    $tile instanceof Sign) {
                            
    $text $tile->getText();
                            
    $tile->setText($text[0], $text[1], $this->arenas[$val]->getSlot(true) . "/" $this->arenas[$val]->getSlot(), $text[3]);
                        } else {
                            
    $this->getLogger()->critical('Can\'t get ' $val ' sign.Error finding sign on level: ' $ex[0b11] . ' x:' $ex[0] . ' y:' $ex[1] . ' z:' $ex[2]);
                        }
                    }
                }
            }
         }
    I just wanted to report that problem,and if you can fix that problem in pmmp so colors will be shown,I would be ok.
     
  2. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Please provide the actual data you passed to colorize(). Try showing us the json_encode() of the data.
     
  3. Saxavlax001

    Saxavlax001 Witch

    Messages:
    63
    GitHub:
    Saxavlax001
    The signs data file is not in json. Its that .db file.
    But the problem is that colors and words are disappearing when I do one of the two TextFormat codes.
     
    Last edited: May 31, 2019
  4. Saxavlax001

    Saxavlax001 Witch

    Messages:
    63
    GitHub:
    Saxavlax001
  5. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    The problem lies here
    PHP:
    $tile->setText(TextFormat::colorize($text[0], $text[1], "&a" $players "&7/&a" $slot$state));
    It should be
    PHP:
    $tile->setText(TextFormat::colorize($text[0]),TextFormat::colorize($text[1]), TextFormat::colorize("&a" $players "&7/&a" $slot),TextFormat::colorize($state));
     
  6. Saxavlax001

    Saxavlax001 Witch

    Messages:
    63
    GitHub:
    Saxavlax001
    Ok thanks,I did TextFormat::colorize with that example and changed some things also in the plugin and now signs are fixed.
     
    Last edited: Jun 1, 2019
  7. Saxavlax001

    Saxavlax001 Witch

    Messages:
    63
    GitHub:
    Saxavlax001
    Someone mark it as solved if you want,because I can't.
     
  8. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    There should a button called "Thread tools" in the top right corner, that should allow you to add the solved tag.
     
  9. Saxavlax001

    Saxavlax001 Witch

    Messages:
    63
    GitHub:
    Saxavlax001
    Yes it exists,but It doesn't have an option to add the Solved tag,I remember that before months it was exist. But ok I don't have problem with that.
     
  10. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Ohhh, it's because this post in in the General Discussion category instead of Development.
     
    SOFe likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.