package org.royaldev.thehumanity.configuration; import com.google.common.collect.Lists; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.json.JSONObject; import xyz.cardstock.cardstock.configuration.Configuration; import java.io.File; import java.util.List; public class TheHumanityConfiguration extends Configuration { private final boolean debug, keepLoaded, webEnabled, onlyRunWeb; @NotNull private final List<String> cardPackFiles = Lists.newArrayList(), defaultPacks = Lists.newArrayList(); // TODO: nickserv to servers in Cardstock @Nullable private final String nickservPassword; @NotNull private final String webHost; private final int webPort; public TheHumanityConfiguration(@NotNull final File file) { super(file.toPath()); final JSONObject theHumanity = this.getJson().getJSONObject("thehumanity"); this.debug = theHumanity.optBoolean("debug"); this.nickservPassword = theHumanity.optString("nickservPassword", null); final JSONObject cardPacks = theHumanity.getJSONObject("cardPacks"); this.keepLoaded = cardPacks.optBoolean("keepLoaded"); for (final Object pack : cardPacks.getJSONArray("files")) { this.cardPackFiles.add(pack.toString()); } for (final Object defaultPack : cardPacks.getJSONArray("defaults")) { this.defaultPacks.add(defaultPack.toString()); } final JSONObject web = theHumanity.getJSONObject("web"); this.webEnabled = web.optBoolean("enabled"); this.onlyRunWeb = web.optBoolean("onlyRunWeb"); this.webHost = web.getString("host"); this.webPort = web.getInt("port"); } @NotNull public List<String> getCardPackFiles() { return this.cardPackFiles; } @NotNull public List<String> getDefaultPacks() { return this.defaultPacks; } public boolean isDebug() { return this.debug; } public boolean isKeepLoaded() { return this.keepLoaded; } public boolean isWebEnabled() { return this.webEnabled; } public boolean isOnlyRunWeb() { return this.onlyRunWeb; } @Nullable public String getNickservPassword() { return this.nickservPassword; } @NotNull public String getWebHost() { return this.webHost; } public int getWebPort() { return this.webPort; } }