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

How to get a "list" from config?

Discussion in 'Development' started by DrakerZR, May 27, 2018.

  1. DrakerZR

    DrakerZR Silverfish

    Messages:
    21
    GitHub:
    drakerzr
    Hi. How may I will get a list from config?
    Example, this is my config:
    Code:
    worlds:
    - "Survival"
    - "FFA" 
    This is my main:
    PHP:
    public function playerChange(EntityLevelChangeEvent $event){
            
    $player $event->getEntity();
            
    $worlds $this->worlds->get("worlds"){//$this->worlds is config.yml
    But it doesn't works. Help plz
     
  2. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    PHP:
    public function playerChange(EntityLevelChangeEvent $event){
            
    $player $event->getEntity();
            
    $worlds $this->worlds->getNested("worlds");
    }
     
  3. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    If I understand correctly you want to take the array of your world from your config and use them only on this world if I'm wrong on your question.
    Try:
    PHP:
     public function onLevelChange(EntityLevelChangeEvent $event){
            
    $entity $event->getEntity();
            
    $worlds = (array) $this->worlds->getAll()['worlds'];
            if(
    in_array($entity->getLevel()->getFolderName(), $worlds)){
                
    //continue your code ...
            
    }
        }
     
    Last edited: May 29, 2018
  4. ClembDeveloper

    ClembDeveloper Creeper

    Messages:
    2
    Code:
    worlds:
    - Lobby
    - Totem
    PHP:
    $level $config->get("worlds");
    foreach(
    $level as $worlds){

    }
     
  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.