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

Solved [New API] Save resources automatically

Comments in 'Plugin Development' started by EvolSoft, Jul 14, 2015.

  1. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    Hi,
    I'm updating a plugin and I would like to know how can I save every file in resources folder of a phar plugin in the plugin folder.
    Thanks in advance :)
  2. luca28pet
    Offline

    luca28pet Active Member

    Joined:
    Feb 20, 2014
    Posts:
    251
    Minecraft User:
    luca28pet
    Try this:
    PHP:
    $c $this->getResource($filename); //eg resource.yml
    $o stream_get_contents($c);
    fclose($c);
    file_put_contents($this->getDataFolder().$filename$o));
    EvolSoft likes this.
  3. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    Is there a recursive way?
  4. onebone
    Offline

    onebone Notable Member Plugin Developer

    Joined:
    Aug 31, 2013
    Posts:
    330
    Plugins:
    7
    Minecraft User:
    onebone
    I have tried it before but if the file is '.phar', it doesn't work. (Error exactly)
    Maybe you could try using \Phar class. (Maybe very slow)
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Try using RecursiveDirectoryIterator
    EvolSoft likes this.
  6. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    Thank you :)
  7. luca28pet
    Offline

    luca28pet Active Member

    Joined:
    Feb 20, 2014
    Posts:
    251
    Minecraft User:
    luca28pet
    I don't really know if this works:
    PHP:
    foreach($this->getResources() as $resource){
      
    $c $this->getResource($resource);
      
    $o stream_get_contents($c);
      
    fclose($c);
      
    file_put_contents($this->getDataFolder().$resource$o));
    }
    PEMapModder likes this.
  8. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    luca28pet likes this.

Share This Page

Advertisement