forked from chipmunkmc/chipmunkbot
Default config & Java 17 because yes
This commit is contained in:
parent
5831725629
commit
2f6dac6ae5
3 changed files with 36 additions and 3 deletions
4
pom.xml
4
pom.xml
|
@ -8,8 +8,8 @@
|
||||||
<name>chipmunkbot</name>
|
<name>chipmunkbot</name>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
|
|
|
@ -10,7 +10,9 @@ import java.io.InputStream;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
|
@ -19,9 +21,31 @@ import com.google.gson.JsonParser;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
private static File CONFIG_FILE = new File("config.json");
|
private static final File CONFIG_FILE = new File("config.json");
|
||||||
|
|
||||||
private static JsonObject getConfig () throws Exception {
|
private static JsonObject getConfig () throws Exception {
|
||||||
|
if (!CONFIG_FILE.exists()) {
|
||||||
|
// Read the default config
|
||||||
|
InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream("default_config.json");
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
while (reader.ready()) {
|
||||||
|
char character = (char) reader.read();
|
||||||
|
stringBuilder.append(character);
|
||||||
|
}
|
||||||
|
String defaultConfig = stringBuilder.toString();
|
||||||
|
|
||||||
|
// Write the default config
|
||||||
|
BufferedWriter configWriter = new BufferedWriter(new FileWriter(CONFIG_FILE));
|
||||||
|
configWriter.write(defaultConfig);
|
||||||
|
configWriter.close();
|
||||||
|
|
||||||
|
System.out.println("The config.json file was not found, so a default one was created.");
|
||||||
|
|
||||||
|
// Return the default config (instead of reading again, for efficiency)
|
||||||
|
return JsonParser.parseString(defaultConfig).getAsJsonObject();
|
||||||
|
}
|
||||||
|
|
||||||
InputStream opt = new FileInputStream(CONFIG_FILE);
|
InputStream opt = new FileInputStream(CONFIG_FILE);
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(opt));
|
BufferedReader reader = new BufferedReader(new InputStreamReader(opt));
|
||||||
|
|
||||||
|
|
9
src/main/resources/default_config.json
Normal file
9
src/main/resources/default_config.json
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"bots": [
|
||||||
|
{
|
||||||
|
"host": "localhost",
|
||||||
|
"port": 25565,
|
||||||
|
"username": "ChipmunkBot"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
Loading…
Reference in a new issue