What am I doing wrong? I want to get the text from the txt file of another plugin, when I want to execute something on it, it says it is null, but why? PHP: @mkdir("/storage/emulated/0/PocketMine/plugins/VIP/", 0777, true); $this->vips = new Config("/storage/emulated/PocketMine/plugins/VIP/" ."VIPS.txt", Config::ENUM, array());
To write text files, you do not use Config(). Instead, use PHP: $handle = fopen("the/directory/to/file.txt", "a"); and then, to write, PHP: fwrite($handle, $data); // $data is the text information.fclose($handle); If you want to get data from a text file, do file_get_contents(). Also, what is that useless '.' doing there? Combine the two strings..
BTW, Opening it in w+ mode will overwrite all exisiting data with the new data being added, Use fopen("the/directory/to/file.txt", 'a'); to append new data to the file, just a heads up. And if you use the file_put_contents("the/directory/to/file.txt", $data); it will overwrite the existing data. So use the FILE_APPEND flag like so: file_put_contents("the/directory/to/file.txt", $data, FILE_APPEND);
Thanks to everyone, but I already found it out by myself, for these, who are interested: PHP: $file = fopen("/storage/emulated/0/PocketMine/plugins/VIP/VIPS.txt" , "r"); $i = 0; while (!feof($file)) { $vips[] = fgets($file); } fclose($file);foreach($vips as $vip){ if($vip == $sender->getName()){ $sender->sendMessage("§aYou got the §6VIP §bkit§a.");$sender->getInventory()->addItem(new Item(265, 0, 4)); $sender->getInventory()->addItem(new Item(269, 0, 1)); $sender->getInventory()->addItem(new Item(265, 0, 4)); $sender->getInventory()->addItem(new Item(354, 0, 1)); $sender->getInventory()->addItem(new Item(322, 0, 1)); }} My last question, how am I able to add text there on without deleting the current one?