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

Config

Comments in 'Plugin Development' started by Creeperface, Jun 9, 2015.

  1. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    i want to save players names into players.yml so my code:
    PHP:
    public function addPlayer($player){
            
    $cfg = new Config($this->getDataFolder()."players.yml"Config::YAML);
            if(
    $cfg->getAll() !== strtolower($player)) return false;
            else{
                
    $cfg->set(strtolower($player));
                
    $cfg->save();
            }
        }
    but i get error:
    [INFO] An unknown error occurred while attempting to perform this command
    09:38:18 [CRITICAL] Unhandled exception executing command 'rwl add dffdfd' in rwl: yaml_parse(): end of stream reached without finding document 0
    09:38:18 [WARNING] RuntimeException: "yaml_parse(): end of stream reached without finding document 0" (E_WARNING) in "/src/pocketmine/utils/Config" at line 143
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    YAML configs should always save associative arrays. You are expecting to save a string as the whole config.
    If you only want to save a string, don't even use YAML. Use file_put_contents and file_get_contents directly instead.
    Creeperface likes this.
  3. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    so can be this?
    PHP:
    $pl = [$player1$player2]
    $cfg->set("players",  $pl);
    or when i make in players.yml this so should i use $cfg->setNested()?
    players:
    player1:
    home: 341:45:-587
    player2:
    home: 4763:35:333
    player3:
    home: 33:76:9029
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Note that on large servers, this file will become so big that it lags.
  5. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    So is better create file for each player?
  6. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
    not really, if its public u get 5-10k users per day so u have a big folder after 2-3days (my player folder is >50k files) -
    best way - do it with MYSQL! - dont work with a file
    PEMapModder and Creeperface like this.
  7. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    so e.g. i want to add Players to my Residence.
    so how? is it right?
    PHP:
    public function addPlayer($player$residence){
            if(
    is_file($this->getDataFolder()."residences/".$residence.".yml")){
                
    $cfg = new Config($this->getDataFolder()."residences/".$residence.".yml"Config::YAML);
                
    $players $cfg->get('players');
                
    array_push($playersstrtolower($player->getName()));
                
    $cfg->set('players'$players);
                
    $cfg->save();
            }
        }
    YML file:
    Code:
    #residence .......
    name:
    owner:
    flags:
    players:
        Creeperface
        WYXI
        Gradinov
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Actually using
    PHP:
    $array[] = strtolower($player->getName()];
    is better than calling array_push.
    Creeperface likes this.
  9. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    thx and last thing when i set
    Code:
    players:
        Creeperface = "asdad"
        WYXI = "two"
        Gradinov = "one"
    so how can i get single players?
  10. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    can i use array_search?
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    It should be `: ` not ` = `
  12. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    yes sorry :D and i should use $cfg->getNested() right?
    yes getNested() works
    Last edited: Jun 10, 2015
    PEMapModder likes this.
  13. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    my main file.

    PHP:
    $this->msg = new Config($this->getDataFolder()."czech.yml"Config::YAML);

    public function 
    getMessage($key){
            return 
    $this->msg->get($key);
        }

    public function 
    onBlockBreak(BlockBreakEvent $e){
            
    $p $e->getPlayer();
            
    $b $e->getBlock();
                
    $p->sendMessage(TextFormat::GREEN.$this->getMessage("select_point").TextFormat::RED."($b->x$b->y$b->z)".TextFormat::GREEN."!");
                
    $e->setCancelled();
            }
        }

    czech.yml file
    Code:
    #czech
    ---
    select_point: "Zadan vyberovy bod"
    ...
    but when player break a block so message is only (x, y, z)! why??? i tried everything...
    in console is not any error.
  14. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Try doing a var_dump on $this->getMessage("select_point") and see what the result is.
  15. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    so where should i put var_dump if not before $this->getMessage("select_point")?
  16. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Well, I meant, get the value of getMessage and pass it to var_dump. This does not fix the issue. This only allows you to see what is returned by getMessage.

Share This Page

Advertisement