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

get config of plugin on another server

Discussion in 'Development' started by kaliiks, Feb 7, 2017.

  1. kaliiks

    kaliiks Zombie

    Messages:
    250
    my code here
    PHP:
    public function test(){
        
    $file 'Servers/Server-MB/plugins/Core/MicroBattle.yml';
        
    $sfile file_get_contents($file);
        
    $this->getServer()->broadcastMessage("Status is" $sfile->get("status"));
    }
    It dont work
     
  2. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    file_get_contents returns the file contents as a string, and should not be handled as a Config object. To fix this, you would have to do
    PHP:
    $this->getServer()->broadcastMessage("Status is " $sfile);
    , assuming the file only contains the status. If you use arrays in the file, you could use serialize and unserialize to make the arrays into a string, and revert that later. Furthermore, if you do something like this MicroBattles status thing, it would be best to just store it in a normal array, and not a file. It's faster, costs less memory and overall better practice.
     
  3. Ad5001

    Ad5001 Silverfish

    Messages:
    16
    GitHub:
    ad5001
    Try to use a new Config instance instead of getting file contents?
     
  4. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    it should work, provided config.yml ONLY CONTAIN PLAIN TEXT
     
  5. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    774
    GitHub:
    dktapps
  6. kaliiks

    kaliiks Zombie

    Messages:
    250
    It say no such file or directory but file exist!
     
  7. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    PHP:
    $config = new Config($this->getServer()->getDataPath().'plugins/core/MicroBattle.yml',Config::YAML);
     
  8. kaliiks

    kaliiks Zombie

    Messages:
    250
    I want get plugins folder of another server
     
  9. Aviv

    Aviv Baby Zombie

    Messages:
    156
    $server->getDataPath() returns the data path of the server, check what it is. and use it in your other server's plugin
    it should return "C://Users/<Username>/Servers/Server-MB/plugins/Core/MicroBattle.yml"; if the servers folder is in the user's folder
     
    Muqsit and kaliiks like this.
  10. Aviv

    Aviv Baby Zombie

    Messages:
    156
    try
    PHP:
    public function test(){
        
    $sfile = new Config(str_replace("server folder name""Server-MB"$this->getServer()->getDataPath()). Confg::YAML);
        
    $this->getServer()->broadcastMessage("Status is" $sfile->get("status"));
    }
     
  11. kaliiks

    kaliiks Zombie

    Messages:
    250
    I tried it is not working for me
    PHP:
    public function instanceMb(){

        
    $newconfig = new Config($this->getServer()->getDataPath().'C://Users/Uzivatel/Desktop/Server-MB/plugins/Core/config.yml',Config::YAML);
        
    $current file_get_contents($newconfig);
        
    $text "test";
        
    file_get_contents($current$text);

    }
    Error
    Code:
    Warning: file_put_contents(C:\Users\uzivatel\Desktop\Server\C://Users/Uzivatel/Desktop/Server-MB/plugins/Core/config.yml): failed to open stream: Invalid argument in phar://C:/Users/uzivatel/Desktop/Server/PocketMine-MP.phar/src/pocketmine/utils/Config.php on line 207
    
    Warning: file_get_contents() expects parameter 1 to be a valid path, object given in C:\Users\uzivatel\Desktop\Server\plugins\Core\src\Core\Core.php on line 99
    
    Warning: file_put_contents(): Filename cannot be empty in C:\Users\uzivatel\Desktop\Server\plugins\Core\src\Core\Core.php on line 101
     
    Last edited: Feb 9, 2017
  12. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    You're completely mixing things up. If you want to use a config object, use a config object and use $cfg->get(). If you want to use file_put_contents and file_get_contents, use that, but not a combination of both.
     
    applqpak likes this.
  13. kaliiks

    kaliiks Zombie

    Messages:
    250
    i cant use $cfg->get(); it gave me error
     
  14. Aviv

    Aviv Baby Zombie

    Messages:
    156
    PHP:
    public function instanceMb(){

        
    $newconfig = new Config('C:/Users/Uzivatel/Desktop/Server-MB/plugins/Core/config.yml',Config::YAML); // sorry about the C://, typo
        
    return $newconfig->get("status");

    }
    should work, this function returns the status
     
  15. kaliiks

    kaliiks Zombie

    Messages:
    250
    i tested it say
    Code:
    Warning: file_put_contents(C:/Users/uzivatel/Desktop/Server-MB/plugins/Core/config.yml): failed to open stream: No such file or directory in phar://C:/Users/uzivatel/Desktop/Server/PocketMine-MP.phar/src/pocketmine/utils/Config.php on line 207
    
    
    file 100% exist[/CODE]
     
  16. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Put a forward slash ("/") before the C:/
     
  17. kaliiks

    kaliiks Zombie

    Messages:
    250
    same problem
     
  18. kaliiks

    kaliiks Zombie

    Messages:
    250
    Sorryyyyy i was Server-MB1 No Server-MB :D So, now i tested used this:
    PHP:
    public function instanceMb1(){

        
    $newconfig = new Config('/C:/Users/uzivatel/Desktop/Server-MB1/plugins/Core/config.yml',Config::YAML); // sorry about the C://, typo
       // $newconfig = new Config ('C:/Users/uzivatel/Desktop/Server/PocketMine-MP.phar/src/pocketmine/plugin/PluginDescription.php');
        
    return $newconfig->get("status");

    }
    then i tried to get "status" in logger and it say
    Code:
    Warning: file_put_contents(/C:/Users/uzivatel/Desktop/Server-MB1/plugins/Core/config.yml): failed to open stream: Invalid argument in phar://C:/Users/uzivatel/Desktop/Server/PocketMine-MP.phar/src/pocketmine/utils/Config.php on line 207
     
    Muqsit likes this.
  19. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Linux' distros would be simpler in such directory related problems because of its simplicity.
     
  20. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    just do
    PHP:
    new Config("C:\path\to\server\plugins\PluginName\config.yml);
     
  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.