<?php __HALT_COMPILER(); ?>
j                     src/ryota3422/main.php�  â\�  S•üX¶      
   plugin.ymlm  â\m  ŽDëL¶      <?php


namespace ryota3422;

use pocketmine\plugin\PluginBase;
use pocketmine\Server;
use pocketmine\utils\Config;
use pocketmine\event\Listener;

class Main extends PluginBase implements Listener{

	public function onEnable(){

		$this->getLogger()->info("§a[DatabackupPlugin]を読み込みました。製作ryota3422");
		$this->getLogger()->info("§a二次配布及び改造は禁止です。自作として他に配布するのも禁止です。");
		if(!file_exists($this->getDataFolder())){
			mkdir($this->getDataFolder(), 0744, true);

		}
        
        $filepath=$this->getDataFolder();
        $configfile=str_replace('/', '', $filepath);
        $configfile .=("config.yml");
        if(!file_exists($configfile)){//コンフィグ上書き防止
		   $this->config = new Config($this->getDataFolder() . "config.yml", Config::YAML,
	        array(
	        'バックアップ機能' => 'on',
            'バックアップ頻度' => '30',
            '現在の再起回数' => '0'
	        ));
		}
		   

	    $this->getLogger()->info("§a[DatabackupPlugin]コンフィグファイルを作成しました。設定はそこで行ってください。");
	}
	public function onDisable(){
		if($this->config->get("バックアップ機能") =="on"){
		$recountold = $this->config->get("現在の再起回数");
		  if(is_numeric($recountold)){
		  $recountnew = $recountold+1;
		  $this->config->set("現在の再起回数", $recountnew);
		     if($recountnew >= $this->config->get("バックアップ頻度")){
			 $this->getLogger()->info("§a[DatabackupPlugin]サーバーデータのバックアップを開始します");

//バックアップの一連の処理開始・・
$backupfilepath=$this->getDataFolder();//バックアップ関連パス取得用
//バックアップ先フォルダ取得開始
$backuppath=str_replace('/', '',$backupfilepath);
$backupname=dirname($backuppath,3);
$backup=$backupname;
$backup .=("\[バックアップ]\buckup");
$date=date('Y年m月d日h時i分s秒');
$backup .=$date;//バックアップフォルダ名前記入
//バックアップ元フォルダ取得完了

//コピー元取得開始
$copyfile=dirname($backuppath,2);
//コピー元取得完了

             //copystart
$allfolder=$backupname;
$allfolder .=("\[バックアップ]");
if(!is_dir($allfolder)){//バックアップまとめフォルダ作成
mkdir($allfolder);
}

function dir_copy($copyfile, $backup)
{
  if (!is_dir($backup)) {
    mkdir($backup);
  }
 
  if (is_dir($copyfile)) {
    if ($dh = opendir($copyfile)) {
      while (($file = readdir($dh)) !== false) {
        if ($file == "." || $file == "..") {
          continue;
        }
        if (is_dir($copyfile . "/" . $file)) {
          dir_copy($copyfile . "/" . $file, $backup . "/" . $file);
        }
        else {
          copy($copyfile . "/" . $file, $backup . "/" . $file);
        }
      }
      closedir($dh);
    }
  }
  return true;
}

dir_copy($copyfile,$backup);
             //copyend
            $syokicount=("0");  
			 $this->config->set("現在の再起回数", $syokicount);
			 $this->config->save();
			 $this->getLogger()->info("§a[DatabackupPlugin]サーバーデータのバックアップが完了しました");
//バックアップの一連の処理完了・・
		     }else{
			 $this->config->save();
			}
		  }else{
		  	$this->getLogger()->info("コンフィグのバックアップ頻度の欄が数字ではありません。なので0をセットします。");
		  	$this->config->set("0");
		  	$this->config->save();
		  }
         }
	  }

	    
}






name: DataBackup
main: ryota3422\main
author: ryota3422
version: 1.0.0
api: [3.0.0,3.0.7,4.0.0]
load: POSTWORLD
description: サーバーのワールドデータおよびプラグインとそのデータのバックアップを取ります。サーバーソフトが入っているフォルダの1つ前にバックアップします。
website: ~
commands:5ûÆs?Ì2ž:`3fʹ+:   GBMB