2021-12-14 14:47:17 +00:00
|
|
|
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;
|
2023-03-25 10:22:01 +00:00
|
|
|
import java.util.ArrayList;
|
2021-12-14 14:47:17 +00:00
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
public class ConfigLoader implements Configuration {
|
|
|
|
|
2021-12-14 16:55:57 +00:00
|
|
|
private final char crackedChar;
|
2023-03-18 16:10:43 +00:00
|
|
|
private final char bedrockChar;
|
2021-12-14 16:55:57 +00:00
|
|
|
private final boolean replaceSpacesWithUnderscore;
|
|
|
|
private final boolean useTheContainMethod;
|
2021-12-14 14:47:17 +00:00
|
|
|
private final AntiBot antiBot;
|
2023-03-18 16:10:43 +00:00
|
|
|
private final String onlineModeDomain;
|
2021-12-14 14:47:17 +00:00
|
|
|
|
2023-03-25 10:22:01 +00:00
|
|
|
private final String[] disclaimerMessage;
|
|
|
|
|
2021-12-14 14:47:17 +00:00
|
|
|
public ConfigLoader(File file) throws FileNotFoundException {
|
|
|
|
JsonObject jsonObject = JsonParser.parseReader(new FileReader(file)).getAsJsonObject();
|
2021-12-14 16:55:57 +00:00
|
|
|
this.crackedChar = (jsonObject.get("default-cracked-char").getAsString().charAt(0));
|
2023-03-18 16:10:43 +00:00
|
|
|
this.bedrockChar = (jsonObject.get("bedrock-char").getAsString().charAt(0));
|
2021-12-14 16:55:57 +00:00
|
|
|
this.replaceSpacesWithUnderscore = jsonObject.get("replace-spaces-with-underscore").getAsBoolean();
|
|
|
|
this.useTheContainMethod = jsonObject.get("use-the-contain-method").getAsBoolean();
|
2021-12-14 14:47:17 +00:00
|
|
|
JsonObject antiBotJson = jsonObject.getAsJsonObject("simple-anti-bot");
|
|
|
|
this.antiBot = new AntiBot(antiBotJson.get("max-connections").getAsInt(), antiBotJson.get("reset").getAsLong(), TimeUnit.MINUTES);
|
2023-03-18 16:10:43 +00:00
|
|
|
this.onlineModeDomain = jsonObject.get("online-mode-domain").getAsString();
|
2023-03-25 10:22:01 +00:00
|
|
|
ArrayList<String> message = new ArrayList<>();
|
|
|
|
jsonObject.getAsJsonArray("disclaimer-message").forEach((element) -> {
|
|
|
|
message.add(element.getAsString());
|
|
|
|
});
|
|
|
|
disclaimerMessage = message.toArray(new String[0]);
|
2021-12-14 14:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-12-14 16:55:57 +00:00
|
|
|
public char getCrackedChar() {
|
2021-12-14 14:47:17 +00:00
|
|
|
return this.crackedChar;
|
|
|
|
}
|
|
|
|
|
2021-12-14 16:55:57 +00:00
|
|
|
@Override
|
|
|
|
public String getCrackedCharString() {
|
|
|
|
return String.valueOf(this.crackedChar);
|
|
|
|
}
|
|
|
|
|
2023-03-18 16:10:43 +00:00
|
|
|
@Override
|
|
|
|
public char getBedrockChar() {
|
|
|
|
return this.bedrockChar;
|
|
|
|
}
|
|
|
|
|
2021-12-14 16:55:57 +00:00
|
|
|
@Override
|
|
|
|
public boolean doReplaceSpacesWithUnderscore() {
|
|
|
|
return this.replaceSpacesWithUnderscore;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean useTheContainMethod() {
|
|
|
|
return this.useTheContainMethod;
|
|
|
|
}
|
|
|
|
|
2021-12-14 14:47:17 +00:00
|
|
|
@Override
|
|
|
|
public AntiBot getAntiBot() {
|
|
|
|
return this.antiBot;
|
|
|
|
}
|
2021-12-14 19:03:58 +00:00
|
|
|
|
|
|
|
@Override
|
2023-03-18 16:10:43 +00:00
|
|
|
public String getOnlineModeDomain() {
|
|
|
|
return this.onlineModeDomain;
|
2021-12-14 19:03:58 +00:00
|
|
|
}
|
2023-03-18 16:10:43 +00:00
|
|
|
|
2023-03-25 10:22:01 +00:00
|
|
|
@Override
|
|
|
|
public String[] getDisclaimerMessage() {
|
|
|
|
return this.disclaimerMessage;
|
|
|
|
}
|
2021-12-14 14:47:17 +00:00
|
|
|
}
|