package hmggirlfront.world;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import hmggirlfront.mod_GirlFront;
import hmggirlfront.event.level.WorldDifficultyLevel_new;
import hmggirlfront.network.GFClientMessageKeyPressed;
import hmggirlfront.network.GFPacketHandler;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

public class GFEventWorld {
	
	/*現在は未使用21/6/7
	@SubscribeEvent
	public void OnEvent(WorldEvent.Load event) {
		mod_GirlFront mod = mod_GirlFront.INSTANCE;
		if(!event.getWorld().isRemote){
			String name = event.getWorld().getWorldInfo().getWorldName();
			File newfile = new File(".",
					"mods" + File.separatorChar + "hmggirlfront" + File.separatorChar + "level" + File.separatorChar
							+ name);
			if (newfile.isFile()) {
				try {
					if (checkBeforeReadfile(newfile)) {
						BufferedReader br = new BufferedReader(new FileReader(newfile)); // ファイルを開く
						String str;
						while ((str = br.readLine()) != null) { // 1行ずつ読み込む
							String[] type = str.split(",");
							if (type.length != 0) {// 1
								//if (!mod.proxy.getClient())
								{
									//System.out.println(String.format("1"));
									if (type[0].equals("level")) {
										mod.difficult_level = Integer.parseInt(type[1]);
										String dd = String.format("%1$3d", (int)mod.difficult_level);
										System.out.println(String.format(dd));
									}
								}
							}
						}
						br.close(); // ファイルを閉じる
					}
				} catch (FileNotFoundException ex) {
					ex.printStackTrace();
				} catch (IOException ex) {
					ex.printStackTrace();
				}
			} else{
				File dire = new File(".",
						"mods" + File.separatorChar + "hmggirlfront" + File.separatorChar + "level");
				dire.mkdirs();
				try {
					newfile.createNewFile();
					BufferedWriter bw = new BufferedWriter(new FileWriter(newfile));
					bw.write("#");
					bw.newLine();
					bw.write("level," + "0");
					bw.close();
				} catch (FileNotFoundException ex) {
					ex.printStackTrace();
				} catch (IOException ex) {
					ex.printStackTrace();
				}
				mod.difficult_level = 0;
				System.out.println(String.format("createLevel"));
				String dd = String.format("%1$3d", (int)mod.difficult_level);
				System.out.println(String.format(dd));
			}
			if(FMLCommonHandler.instance().getMinecraftServerInstance() != null) {
				for (EntityPlayerMP player : FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayers())
	            {
					GFPacketHandler.INSTANCE2.sendTo(new GFClientMessageKeyPressed(1, mod.difficult_level), player);
	            }
            }
		}else {
			mod.difficult_level = WorldDifficultyLevel_new.getLevelClient();
		}
	}
	
	 private static boolean checkBeforeReadfile(File file){
		    if (file.exists()){
		      if (file.isFile() && file.canRead()){
		        return true;
		      }
		    }

		    return false;
		  }
	 */
}
