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

I don't understand

Comments in 'Plugin Development' started by KingDeadKnight, Mar 8, 2016.

  1. KingDeadKnight
    Offline

    KingDeadKnight New Member

    Joined:
    Oct 18, 2015
    Posts:
    33
    Minecraft User:
    KingDeadKnight
    I'm trying to create a little plugin for my servers project, but when I try the beginning of the plugin, I get that warning and I don't understand why:

    Warning: file_put_contents(/home/gsp_614/srv5.hmserv.eu-19150/plugins/Royaume/Andorre.yml): failed to open stream: No such file or directory in phar:///home/gsp_614/srv5.hmserv.eu-19150/ImagicalMine.phar/src/pocketmine/utils/Config.php on line 213

    The same warning for the three others yaml files

    Here's my beginning:
    PHP:
    <?php

    namespace KingDeadKnight\Royaume;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\utils\Config;

    class 
    Main extends PluginBase
    {
       
        const 
    PREFIX "[&4Final&6Fire]";
       
       private 
    $plugin;
        
    /** @var AndorreDB $andorredb */
        
    private $andorredb;
        
    /** @var HyrunioDB $hyruniodb */
        
    private $hyruniodb;
        
    /** @var ProlythDB $prolythdb */
        
    private $prolythdb;
        
    /** @var ItoniaDB $itoniadb */
        
    private $itoniadb;
       
        public function 
    onEnable(){
            
    $this->andorredb = new Config($this->getDataFolder() . "Andorre.yml"Config::YAML);
            
    $this->hyruniodb = new Config($this->getDataFolder() . "Hyrunio.yml"Config::YAML);
            
    $this->prolythdb = new Config($this->getDataFolder() . "Prolyth.yml"Config::YAML);
            
    $this->itoniadb = new Config($this->getDataFolder() . "Itonia.yml"Config::YAML);
            }
           
           
        public function 
    onDisable(){
            
    $this->plugin->saveResource("Andorre.yml");
            
    $this->plugin->saveResource("Hyrunio.yml");
            
    $this->plugin->saveResource("Prolyth.yml");
            
    $this->plugin->saveResource("Itonia.yml");
            }
        }
    Thanks to help me!
  2. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    Why use $this->plugin? This is your Main class, right? You can simply do $this->saveResource() on there, put it onEnable()
  3. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    The error means the file doesnt exist.
  4. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Before creating the files, create the DataFolder:
    PHP:
    if(!is_dir($this->getDataFolder())) mkdir($this->getDataFolder());
    PEMapModder likes this.
  5. KingDeadKnight
    Offline

    KingDeadKnight New Member

    Joined:
    Oct 18, 2015
    Posts:
    33
    Minecraft User:
    KingDeadKnight
    Thanks, so is it right now?

    PHP:
    <?php

    namespace KingDeadKnight\Royaume;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\event\Listener;

    class 
    Main extends PluginBase implements Listener
    {
      
        const 
    PREFIX "[&4Final&6Fire]";
      
       private 
    $plugin;
        
    /** @var AndorreDB $andorredb */
        
    private $andorredb;
        
    /** @var HyrunioDB $hyruniodb */
        
    private $hyruniodb;
        
    /** @var ProlythDB $prolythdb */
        
    private $prolythdb;
        
    /** @var ItoniaDB $itoniadb */
        
    private $itoniadb;
      
        public function 
    onEnable(){
            if(!
    is_dir($this->getDataFolder())) mkdir($this->getDataFolder());
            
    $this->andorredb = new Config($this->getDataFolder() . "Andorre.yml"Config::YAML);
            
    $this->saveResource("Andorre.yml");
            
    $this->hyruniodb = new Config($this->getDataFolder() . "Hyrunio.yml"Config::YAML);
            
    $this->saveResource("Hyrunio.yml");
            
    $this->prolythdb = new Config($this->getDataFolder() . "Prolyth.yml"Config::YAML);
            
    $this->saveResource("Prolyth.yml");
            
    $this->itoniadb = new Config($this->getDataFolder() . "Itonia.yml"Config::YAML);
            
    $this->saveResource("Itonia.yml");
            }
          
          
        public function 
    onDisable(){
            
    $this->saveResource("Andorre.yml");
            
    $this->saveResource("Hyrunio.yml");
            
    $this->saveResource("Prolyth.yml");
            
    $this->saveResource("Itonia.yml");
            }
        }
    In the ressource, I have 4 yml with this in:
    PHP:
    Chef: [] 
    Officiers: []
    Membres: [] 
    ... 
    But after loading the plugin, in plugin's folder, I got the 4 yml with nothing in, what can I do too?
    Last edited: Mar 9, 2016
  6. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    Test it yourself, then analyze the error, and if you can't, provide us the error.
  7. KingDeadKnight
    Offline

    KingDeadKnight New Member

    Joined:
    Oct 18, 2015
    Posts:
    33
    Minecraft User:
    KingDeadKnight
    There is no error, just what I tell about the yml file in my latest answer
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Save resource before creating a config instance.
    Creating a config instance means to read that file, or attempt to create it if it didn't already exist.
    Save resource means if file didn't already exist, copy if from your plugin resources (assets)
    CraftYourBukkit likes this.
  9. KingDeadKnight
    Offline

    KingDeadKnight New Member

    Joined:
    Oct 18, 2015
    Posts:
    33
    Minecraft User:
    KingDeadKnight
    OK, thanks a lot everyone, I will come back if I'll have another problems

Share This Page

Advertisement