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

Error GetDataFolder ()

Discussion in 'Development' started by Palente, Nov 15, 2016.

  1. Palente

    Palente Slime

    Messages:
    75
    GitHub:
    palente
    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
     
  2. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Are u sure you are using this at the top of your code?

    PHP:
    use pocketmine\utils\Config;
     
  3. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    Your loader class shouldn't extend command, but PluginBase.
     
    HimbeersaftLP likes this.
  4. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Lol, didn't even notice it...
     
  5. PocketKiller

    PocketKiller Slime

    Messages:
    83
    GitHub:
    iPocket
    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().
     
    HimbeersaftLP likes this.
  6. PocketKiller

    PocketKiller Slime

    Messages:
    83
    GitHub:
    iPocket
    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...*/);
     
    Last edited: Nov 15, 2016
    HimbeersaftLP likes this.
  7. Palente

    Palente Slime

    Messages:
    75
    GitHub:
    palente
    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
     
  8. PocketKiller

    PocketKiller Slime

    Messages:
    83
    GitHub:
    iPocket
    no
    @Palente don't do that.
     
  9. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    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?
     
  10. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Wait, shouldn't it be like this?

    PHP:
    class something extends PluginBase implements Listener{
    Correct me if I am wrong...
     
  11. CraftYourBukkit

    CraftYourBukkit Creeper

    Messages:
    3
    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)
     
    Last edited: Nov 16, 2016
    HimbeersaftLP likes this.
  12. Palente

    Palente Slime

    Messages:
    75
    GitHub:
    palente
    Thanks for review all.
    This thread is now solved
    Yes is it that they work thanks
     
    HimbeersaftLP likes this.
  13. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    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 :)
     
    HimbeersaftLP likes this.
  14. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Next time please show the exact message. The console shows something more meaningful than just a function name.
     
    HimbeersaftLP likes this.
  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.