Hey, I have a problem When I run My code(bottom this message) Idea: I want to create a lang.yml for Player can change The language of Plugin. PHP: class loader extends command {public function execute(CommandSender $args, $command, array $args){$cfg= new Config($this->getDataFolder() . "lang.yml", Config::YAML);$cfg->set("lang", "en");$cfg->save();#Some codes not important Console return error getDataFolder () Sorry for my bad english
What's the error exactly? I think I knew it Look, there is no getDataFolder method in \pocketmine\command\Command! Hmm, let's see, where it is? it seems to be on \pocketmine\plugin\PluginBase... let me check... YES IT IS! so pass the plugin object reference on the constructor, and replace it on $this->plugin. then use $this->plugin->getDataFolder().
Example: PHP: //inside class...public function __construct(\pocketmine\plugin\PluginBase $plugin, ...$args){ parent::__construct(...$args); $this->plugin = $plugin;} so, you'll have to make the plugin reference as first argument in the Main class.... PHP: $command = new LOLCOMMAND($this/*this is the plugin*/, /*whatever passed here...*/);
PHP: use pocketmine\utils\Config; yes i use it So okay i test it but error PHP: Argument 2 passed to pocketmine\command\SimpleCommandMap::register() must be an instance of pocketmine\command\Command Thanks for all but i want lot of details i don't say it but i'm a little developper so i'm starting. And Thanks for read that But reply just if you can help me and be cool with me not be agressiv sorry for my bad english i'm french
It really depends what you are trying to do. Is the class you showed us your main class? Or is it just a seperate class for commands?
Wait, shouldn't it be like this? PHP: class something extends PluginBase implements Listener{ Correct me if I am wrong...
Depends. PluginBase is, as it says, the base class(you may just call it the main class(I don't mean the class name really, just an identifier)). There you will have the onEnable(), onDisable, onCommand, etc. (If you need them) and this is the class you add to the plugin.yml, since this should get loaded. (it obviously has the startup stuff in onEnable()) You only need to implement the Listener in the class where you use events though. Of course, you can do that in the Main class too, but that can get kinda messy. Meh. This class is made to be a command, so it shouldn't be instanceof PluginBase in this case! Otherwise, he'd need to use onCommand. (Make sure to only have one Main class)
Yeah you're right. I should have been clearer. I wasn't sure if he was trying to do that in his main file, as you usually call your main file Main, or Loader. You gave a way better reply though
Next time please show the exact message. The console shows something more meaningful than just a function name.