This repository has been archived by the owner on Jun 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a discord text config file Added star distance to reddit config Added settings button to open discord config
- Loading branch information
Showing
13 changed files
with
333 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/com/fi0x/edct/logic/filesystem/ConfigHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.fi0x.edct.logic.filesystem; | ||
|
||
import org.json.simple.JSONObject; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
public class ConfigHandler | ||
{ | ||
public static String getValue(JSONObject json, String key, boolean unloading, @Nullable String type) | ||
{ | ||
JSONObject keyArea = null; | ||
if(json.containsKey("Required Variables") && ((JSONObject) json.get("Required Variables")).containsKey(key)) | ||
{ | ||
keyArea = (JSONObject) json.get("Required Variables"); | ||
} else if(json.containsKey("Custom Variables") && ((JSONObject) json.get("Custom Variables")).containsKey(key)) | ||
{ | ||
keyArea = (JSONObject) json.get("Custom Variables"); | ||
} | ||
if(keyArea == null) return ""; | ||
|
||
String value = keyArea.get(key).toString(); | ||
if(value.charAt(0) != '{') return value; | ||
|
||
JSONObject keyJson = (JSONObject) keyArea.get(key); | ||
if(keyJson.containsKey(unloading ? "UNLOADING" : "LOADING")) | ||
{ | ||
if(type == null) return keyJson.get(unloading ? "UNLOADING" : "LOADING").toString(); | ||
else | ||
{ | ||
JSONObject loadingJson = (JSONObject) keyJson.get(unloading ? "UNLOADING" : "LOADING"); | ||
if(loadingJson.containsKey(type)) return loadingJson.get(type).toString(); | ||
} | ||
} else return keyJson.toString(); | ||
|
||
return ""; | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
src/main/java/com/fi0x/edct/logic/filesystem/DiscordHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.fi0x.edct.logic.filesystem; | ||
|
||
import com.fi0x.edct.Main; | ||
import com.fi0x.edct.logging.Logger; | ||
import org.json.simple.JSONObject; | ||
import org.json.simple.parser.JSONParser; | ||
import org.json.simple.parser.ParseException; | ||
|
||
import javax.annotation.Nullable; | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class DiscordHandler | ||
{ | ||
public static void addMissingKeys(JSONObject json) | ||
{ | ||
try | ||
{ | ||
var jsonInput = Main.class.getResourceAsStream("/defaults/discord.json"); | ||
JSONObject originalJson = (JSONObject) new JSONParser().parse(jsonInput.toString()); | ||
for(Object o : originalJson.keySet()) | ||
{ | ||
String key = o.toString(); | ||
if(!json.containsKey(key)) json.put(key, originalJson.get(key)); | ||
} | ||
} catch(ParseException ignored) | ||
{ | ||
} | ||
} | ||
|
||
@Nullable | ||
public static JSONObject getDiscordConfig() | ||
{ | ||
JSONObject json = null; | ||
try | ||
{ | ||
String fileContent = Files.readString(Main.discord.toPath()); | ||
json = (JSONObject) new JSONParser().parse(fileContent); | ||
} catch(IOException | ParseException ignored) | ||
{ | ||
} | ||
|
||
return json; | ||
} | ||
|
||
public static void fillDiscordFileIfEmpty() | ||
{ | ||
try | ||
{ | ||
List<String> fileContent = new ArrayList<>(Files.readAllLines(Main.discord.toPath(), StandardCharsets.UTF_8)); | ||
|
||
if(fileContent.size() <= 0) | ||
{ | ||
var jsonInput = Main.class.getResourceAsStream("/defaults/discord.json"); | ||
fileContent = new BufferedReader(new InputStreamReader(jsonInput, StandardCharsets.UTF_8)).lines().collect(Collectors.toList()); | ||
} | ||
|
||
Files.write(Main.discord.toPath(), fileContent, StandardCharsets.UTF_8); | ||
} catch(IOException e) | ||
{ | ||
Logger.WARNING(996, "Could not write default entry to discord config", e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.