mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-26 15:16:45 +01:00
No reason to handle this ourselves, Bukkit does it for us.
This commit is contained in:
parent
9aaea7e44f
commit
8632baed27
@ -1,11 +1,6 @@
|
|||||||
package com.gmail.nossr50.config;
|
package com.gmail.nossr50.config;
|
||||||
|
|
||||||
import java.io.File;
|
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 java.util.List;
|
||||||
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
@ -16,7 +11,7 @@ import com.gmail.nossr50.mcMMO;
|
|||||||
public abstract class ConfigLoader {
|
public abstract class ConfigLoader {
|
||||||
protected static final mcMMO plugin = mcMMO.p;
|
protected static final mcMMO plugin = mcMMO.p;
|
||||||
protected String fileName;
|
protected String fileName;
|
||||||
protected File configFile;
|
private File configFile;
|
||||||
protected FileConfiguration config;
|
protected FileConfiguration config;
|
||||||
|
|
||||||
public ConfigLoader(String relativePath, String fileName) {
|
public ConfigLoader(String relativePath, String fileName) {
|
||||||
@ -34,7 +29,7 @@ public abstract class ConfigLoader {
|
|||||||
protected void loadFile() {
|
protected void loadFile() {
|
||||||
if (!configFile.exists()) {
|
if (!configFile.exists()) {
|
||||||
plugin.debug("Creating mcMMO " + fileName + " File...");
|
plugin.debug("Creating mcMMO " + fileName + " File...");
|
||||||
createFile();
|
plugin.saveResource(fileName, false);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
plugin.debug("Loading mcMMO " + fileName + " File...");
|
plugin.debug("Loading mcMMO " + fileName + " File...");
|
||||||
@ -45,53 +40,6 @@ public abstract class ConfigLoader {
|
|||||||
|
|
||||||
protected abstract void loadKeys();
|
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() {
|
protected boolean validateKeys() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user