GreenAppleLogin/gal-velocity/src/main/java/net/limework/gal/ConfigLoader.java

81 lines
2.6 KiB
Java

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.ArrayList;
import java.util.concurrent.TimeUnit;
public class ConfigLoader implements Configuration {
private final char crackedChar;
private final char bedrockChar;
private final boolean replaceSpacesWithUnderscore;
private final boolean useTheContainMethod;
private final AntiBot antiBot;
private final String onlineModeDomain;
private final String[] disclaimerMessage;
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.bedrockChar = (jsonObject.get("bedrock-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();
ArrayList<String> message = new ArrayList<>();
jsonObject.getAsJsonArray("disclaimer-message").forEach((element) -> {
message.add(element.getAsString());
});
disclaimerMessage = message.toArray(new String[0]);
}
@Override
public char getCrackedChar() {
return this.crackedChar;
}
@Override
public String getCrackedCharString() {
return String.valueOf(this.crackedChar);
}
@Override
public char getBedrockChar() {
return this.bedrockChar;
}
@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;
}
@Override
public String[] getDisclaimerMessage() {
return this.disclaimerMessage;
}
}