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
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.
Use a Config instead of file_get_contents(). Reference: https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/utils/Config.php#L72-L77
PHP: $config = new Config($this->getServer()->getDataPath().'plugins/core/MicroBattle.yml',Config::YAML);
$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
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"));}
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
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.
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
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]
Sorryyyyy i was Server-MB1 No Server-MB 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