Greetings, I added a config file to my plugin and when I changed the message from "You are healed" to $this->myConfig->get("XY") I get this error when I execute the command in game. (Internal Server Error) [Server thread/CRITICAL]: TypeError: "Argument 1 passed to pocketmine\lang\BaseLang::translateString() must be of the type string, bool given, called in phar://C:/Users/Varga Domonkos Péter/Documents/Minecraft PE Szerverek/Szerver 1/PocketMine-MP.phar/src/pocketmine/Player.php on line 3510" (EXCEPTION) in "src/pocketmine/lang/BaseLang" at line 129 And here is the code of the command: case "heal": if($sender instanceof Player){ if($sender->hasPermission("servercore.heal")){ $sender->setHealth($sender->getMaxHealth()); $sender->sendMessage($this->myConfig->get("heal_success")); } } else { } break; Thanks for any help in advance, have a great day!
I can't show you, because the forum doesn't let me send comment or message which is contain more than 1000 characters. How could I show you then? Is there any other option to do this?
so, you should set $this->myconfig = $this->getConfig(); onEnable. do you used this? (Still im waiting for your full code
When getting a value from config, it will return a false if the key was not found. Make sure the config in "../plugin_data/YourPlugin/servercore.yml " has the key "heal_success". You can bypass empty key problem, by providing the default return value in second argument for Config::get(). See, you're making an empty config file by giving an array() PHP: $this->myConfig = new Config($this->getDataFolder() . "servercore.yml", Config:: YAML, array()); If you have prepared config, in your plugin resources folder use Plugin::saveDefaultConfig()
Maybe this is the problem, I just checked the plugin's data folder and for some reason the servercore.yml is an empty file, but in the src folder of the plugin i put the servercore.yml file with the config values to the resources folder but when I start my server the plugin generate an empty servercore.yml file...
You nowhere in the code specify to use the one in resource folder. Check out PluginBase::saveDefaultConfig(). But Note: the config must be named by default conventions 'config.yml' instead of your servercore.yml file. This will mean that you'll no longer will have to initialize your own ''myConfig" object, but instead use PluginBase::getConfig().