mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-02-02 21:51:24 +01:00
Check Default node exists, if not write it. Saves erroring etc.
I'm sure theres an easier/better way to do this but this will do for now.
This commit is contained in:
parent
a288015bf0
commit
3c054e4a95
@ -1,8 +1,14 @@
|
|||||||
package com.onarandombox.MultiVerseCore.configuration;
|
package com.onarandombox.MultiVerseCore.configuration;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.DataInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.FileWriter;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
|
||||||
import com.onarandombox.MultiVerseCore.MultiVerseCore;
|
import com.onarandombox.MultiVerseCore.MultiVerseCore;
|
||||||
|
|
||||||
@ -13,8 +19,12 @@ import com.onarandombox.MultiVerseCore.MultiVerseCore;
|
|||||||
public class DefaultConfiguration {
|
public class DefaultConfiguration {
|
||||||
|
|
||||||
public DefaultConfiguration(File folder, String name){
|
public DefaultConfiguration(File folder, String name){
|
||||||
|
new DefaultConfiguration(folder,name,null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DefaultConfiguration(File folder, String name, String contains){
|
||||||
File actual = new File(folder, name);
|
File actual = new File(folder, name);
|
||||||
|
|
||||||
if (!actual.exists()) {
|
if (!actual.exists()) {
|
||||||
InputStream input = this.getClass().getResourceAsStream("/defaults/" + name);
|
InputStream input = this.getClass().getResourceAsStream("/defaults/" + name);
|
||||||
if (input != null) {
|
if (input != null) {
|
||||||
@ -29,7 +39,7 @@ public class DefaultConfiguration {
|
|||||||
output.write(buf, 0, length);
|
output.write(buf, 0, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiVerseCore.log.info(MultiVerseCore.logPrefix + "Default setup file written: " + name);
|
MultiVerseCore.log.info(MultiVerseCore.logPrefix + "Default config file written: " + name);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
@ -46,6 +56,52 @@ public class DefaultConfiguration {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if(contains==null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean found = false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Open the file that is the first
|
||||||
|
// command line parameter
|
||||||
|
FileInputStream fstream = new FileInputStream(actual);
|
||||||
|
// Get the object of DataInputStream
|
||||||
|
DataInputStream in = new DataInputStream(fstream);
|
||||||
|
BufferedReader br = new BufferedReader(new InputStreamReader(in));
|
||||||
|
String strLine;
|
||||||
|
//Read File Line By Line
|
||||||
|
|
||||||
|
while ((strLine = br.readLine()) != null) {
|
||||||
|
if(strLine.equals(contains)){
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Close the input stream
|
||||||
|
in.close();
|
||||||
|
} catch (Exception e) {//Catch exception if any
|
||||||
|
System.err.println("Error: Could not verify the contents of " + actual.toString());
|
||||||
|
System.err.println("Error: " + e.getMessage());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!found){
|
||||||
|
try {
|
||||||
|
BufferedWriter out = new BufferedWriter(new FileWriter(actual, true));
|
||||||
|
out.newLine();
|
||||||
|
out.write(contains);
|
||||||
|
out.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println("Error: Could not write default node to " + actual.toString());
|
||||||
|
System.err.println("Error: " + e.getMessage());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user