Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

plugin does not save in config.yml

Comments in 'Plugin Development' started by Praxthisnovcht, Dec 16, 2014.

  1. Praxthisnovcht
    Offline

    Praxthisnovcht Notable Member Plugin Developer

    Joined:
    Mar 10, 2014
    Posts:
    702
    Plugins:
    4
    Minecraft User:
    PraxHellTag
  2. xFlare
    Offline

    xFlare Active Member Plugin Developer

    Joined:
    Sep 28, 2014
    Posts:
    199
    Plugins:
    1
    Minecraft User:
    xFlare
    In onEnable add:

    PHP:
    $this->saveDefaultConfig();
    EvolSoft likes this.
  3. Praxthisnovcht
    Offline

    Praxthisnovcht Notable Member Plugin Developer

    Joined:
    Mar 10, 2014
    Posts:
    702
    Plugins:
    4
    Minecraft User:
    PraxHellTag
    the problem persists,
  4. Praxthisnovcht
    Offline

    Praxthisnovcht Notable Member Plugin Developer

    Joined:
    Mar 10, 2014
    Posts:
    702
    Plugins:
    4
    Minecraft User:
    PraxHellTag
    Its correct ?

    PHP:
            // sets prefix for player
            
    if ((strtolower $command->getName () ) == "setprefix") && isset ( $args [0] ) && isset ( $args [1] )) {
                
    $playerName $args [0];
                
    $p $sender->getServer ()->getPlayerExact $playerName );
                if (
    $p == null) {
                    
    $sender->sendMessage "player " $playerName " is not online!" );
                    exit ();
                }
                
    $prefix $args [1];
                
    $this->pgin->getConfig ()->set $p->getName ().".prefix"$prefix );
                
    $this->pgin->getConfig ()->save ();
  5. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    It's logic that it doesn't work!
    You must get the config file first.
    Try to add it at the start of onCommand() function
    PHP:
    $this->config $this->plugin->getConfig()->getAll();
    xFlare likes this.
  6. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    However you made a lot of errors in your code.
    First of all, don't use the construct variable ($this->pgin) to get the config. Simply declare a new variable.
    xFlare likes this.
  7. xpyctum
    Offline

    xpyctum Active Member Plugin Developer

    Joined:
    Jan 13, 2014
    Posts:
    292
    Plugins:
    4
    Minecraft User:
    tylerdisney
    For start, init this
    PHP:
    $this->pgin = new Config($this->getDataFolder()."config.yml"Config::YAML);
  8. xFlare
    Offline

    xFlare Active Member Plugin Developer

    Joined:
    Sep 28, 2014
    Posts:
    199
    Plugins:
    1
    Minecraft User:
    xFlare
    Why do that? Just make it use the default config.
    EvolSoft likes this.
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    This isn't needed; his config is in $this->pgin->getConfig() and PocketMine PluginBase class will do everything for him! How many times do I need to tell you? If you can't understand my language, fine, go to https://github.com/PocketMine/PocketMine-MP/blob/master/src/pocketmine/plugin/PluginBase.php and read the code yourself
    $this->pgin is his PluginBase object not a config file apparently.
  10. Praxthisnovcht
    Offline

    Praxthisnovcht Notable Member Plugin Developer

    Joined:
    Mar 10, 2014
    Posts:
    702
    Plugins:
    4
    Minecraft User:
    PraxHellTag
  11. Sergey_D
    Offline

    Sergey_D Active Member

    Joined:
    Jan 19, 2014
    Posts:
    75
    Minecraft User:
    CLILLZ
    You will create plugin folder,and after this create a config file.
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    saveDefaultConfig() does all these work.
    Praxthisnovcht and EvolSoft like this.
  13. Sergey_D
    Offline

    Sergey_D Active Member

    Joined:
    Jan 19, 2014
    Posts:
    75
    Minecraft User:
    CLILLZ
    PHP:
    @mkdir($this->getDataFolder()); //Create plugin folder
    $this->config = new Config($this->getDataFolder() . "Config.yml"Config::YAML, array());
  14. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    Or simply do:
    PHP:
    $this->configuration $this->getConfig();
  15. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Just do $this->saveDefaultConfig() and PocketMine will do all these for you. And <? echo strtolower("DO NOT DEFINE \$this->config YOURSELF") ?>.
    Last edited: Dec 21, 2014
    EvolSoft likes this.
  16. Praxthisnovcht
    Offline

    Praxthisnovcht Notable Member Plugin Developer

    Joined:
    Mar 10, 2014
    Posts:
    702
    Plugins:
    4
    Minecraft User:
    PraxHellTag
    why not stay as simple as possible.
    PEMapModder likes this.
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Then why save it as a field... Just keep using $this->getConfig()!

    Maybe this is better in some ways though because getConfig() checks if the config exists every time, but there isn't really much lagginess.
  18. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    Exact :)
    It's useless to get the config every time. Saved in a field is better ;)
  19. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    But that's very minimum time use. Any other useless line you write spends more time than the difference here.

    The only difference is an extra isset() call (or !== null check; I forgot).
  20. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,132
    Plugins:
    4
    Minecraft User:
    iksaku
    Do not call "exit()" on plugins, you will only break the plugin
    Praxthisnovcht likes this.

Share This Page

Advertisement