瀏覽代碼

No reason to handle this ourselves, Bukkit does it for us.

GJ 11 年之前
父節點
當前提交
8632baed27
共有 1 個文件被更改,包括 2 次插入54 次删除
  1. 2 54
      src/main/java/com/gmail/nossr50/config/ConfigLoader.java

+ 2 - 54
src/main/java/com/gmail/nossr50/config/ConfigLoader.java

@@ -1,11 +1,6 @@
 package com.gmail.nossr50.config;
 
 import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
 import java.util.List;
 
 import org.bukkit.configuration.file.FileConfiguration;
@@ -16,7 +11,7 @@ import com.gmail.nossr50.mcMMO;
 public abstract class ConfigLoader {
     protected static final mcMMO plugin = mcMMO.p;
     protected String fileName;
-    protected File configFile;
+    private File configFile;
     protected FileConfiguration config;
 
     public ConfigLoader(String relativePath, String fileName) {
@@ -34,7 +29,7 @@ public abstract class ConfigLoader {
     protected void loadFile() {
         if (!configFile.exists()) {
             plugin.debug("Creating mcMMO " + fileName + " File...");
-            createFile();
+            plugin.saveResource(fileName, false);
         }
         else {
             plugin.debug("Loading mcMMO " + fileName + " File...");
@@ -45,53 +40,6 @@ public abstract class ConfigLoader {
 
     protected abstract void loadKeys();
 
-    protected void createFile() {
-        configFile.getParentFile().mkdirs();
-
-        InputStream inputStream = plugin.getResource(fileName);
-
-        if (inputStream == null) {
-            plugin.getLogger().severe("Missing resource file: '" + fileName + "' please notify the plugin authors");
-            return;
-        }
-
-        OutputStream outputStream = null;
-
-        try {
-            outputStream = new FileOutputStream(configFile);
-
-            int read;
-            byte[] bytes = new byte[1024];
-
-            while ((read = inputStream.read(bytes)) != -1) {
-                outputStream.write(bytes, 0, read);
-            }
-        }
-        catch (FileNotFoundException e) {
-            e.printStackTrace();
-        }
-        catch (IOException e) {
-            e.printStackTrace();
-        }
-        finally {
-            if (outputStream != null) {
-                try {
-                    outputStream.close();
-                }
-                catch (IOException e) {
-                    e.printStackTrace();
-                }
-            }
-
-            try {
-                inputStream.close();
-            }
-            catch (IOException e) {
-                e.printStackTrace();
-            }
-        }
-    }
-
     protected boolean validateKeys() {
         return true;
     }