Players Online On Website, Changed packaging a little & added SettingsLoader (#44)

This commit is contained in:
Daniel Ginovker
2019-10-09 17:30:43 -04:00
committed by GitHub
parent 1f49bff69d
commit b97a843428
12 changed files with 96 additions and 41 deletions
@@ -0,0 +1,40 @@
package redone.integrations;
import org.json.JSONObject;
import redone.integrations.discord.JavaCord;
import java.io.*;
import java.util.stream.Collectors;
public class SettingsLoader {
private static void initialize() {
JSONObject main = new JSONObject();
main
.put("bot-token", "")
.put("powpass", "");
try {
BufferedWriter br = new BufferedWriter(new FileWriter("data/secrets.json"));
br.write(main.toString());
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void loadSettings() throws IOException {
if (!new File("data/secrets.json").exists()) {
initialize();
System.out.println("Please open \"data/secrets.json\" file and enter your discord token bot there!");
System.out.println("Please open \"data/secrets.json\" file and enter your Players Online On Website Password there!");
} else {
BufferedReader br = new BufferedReader(new FileReader("data/secrets.json"));
String out = br.lines().collect(Collectors.joining("\n"));
JSONObject obj = new JSONObject(out);
JavaCord.token = obj.getString("bot-token");
PlayersOnlineWebsite.password = obj.getString("powpass");
}
}
}