package net.limework.gal; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import net.limework.gal.utils.config.AntiBot; import net.limework.gal.utils.config.Configuration; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.util.concurrent.TimeUnit; public class ConfigLoader implements Configuration { private final char crackedChar; private final boolean replaceSpacesWithUnderscore; private final boolean useTheContainMethod; private final AntiBot antiBot; private final String onlineModeDomain; public ConfigLoader(File file) throws FileNotFoundException { JsonObject jsonObject = JsonParser.parseReader(new FileReader(file)).getAsJsonObject(); this.crackedChar = (jsonObject.get("default-cracked-char").getAsString().charAt(0)); this.replaceSpacesWithUnderscore = jsonObject.get("replace-spaces-with-underscore").getAsBoolean(); this.useTheContainMethod = jsonObject.get("use-the-contain-method").getAsBoolean(); JsonObject antiBotJson = jsonObject.getAsJsonObject("simple-anti-bot"); this.antiBot = new AntiBot(antiBotJson.get("max-connections").getAsInt(), antiBotJson.get("reset").getAsLong(), TimeUnit.MINUTES); this.onlineModeDomain = jsonObject.get("online-mode-domain").getAsString(); } @Override public char getCrackedChar() { return this.crackedChar; } @Override public String getCrackedCharString() { return String.valueOf(this.crackedChar); } @Override public boolean doReplaceSpacesWithUnderscore() { return this.replaceSpacesWithUnderscore; } @Override public boolean useTheContainMethod() { return this.useTheContainMethod; } @Override public AntiBot getAntiBot() { return this.antiBot; } @Override public String getOnlineModeDomain() { return this.onlineModeDomain; } }