diff --git a/src/main/java/ru/bclib/api/dataexchange/handler/autosync/AutoSync.java b/src/main/java/ru/bclib/api/dataexchange/handler/autosync/AutoSync.java index ec554502..3d96ea25 100644 --- a/src/main/java/ru/bclib/api/dataexchange/handler/autosync/AutoSync.java +++ b/src/main/java/ru/bclib/api/dataexchange/handler/autosync/AutoSync.java @@ -32,15 +32,15 @@ public class AutoSync { @Environment(EnvType.CLIENT) public static class ClientConfig extends NamedPathConfig{ - public static final ConfigToken ENABLED = new ConfigToken(true, "enabled", SYNC_CATEGORY); + public static final ConfigToken ENABLED = ConfigToken.Boolean(true, "enabled", SYNC_CATEGORY); @ConfigUI(leftPadding =8) - public static final ConfigToken ACCEPT_CONFIGS = new DependendConfigToken(true,"acceptConfigs", SYNC_CATEGORY, (config)->config.get(ENABLED)); + public static final DependendConfigToken ACCEPT_CONFIGS = DependendConfigToken.Boolean(true,"acceptConfigs", SYNC_CATEGORY, (config)->config.get(ENABLED)); @ConfigUI(leftPadding =8) - public static final ConfigToken ACCEPT_FILES = new DependendConfigToken(true,"acceptFiles", SYNC_CATEGORY, (config)->config.get(ENABLED)); + public static final DependendConfigToken ACCEPT_FILES = DependendConfigToken.Boolean(true,"acceptFiles", SYNC_CATEGORY, (config)->config.get(ENABLED)); @ConfigUI(leftPadding =8) - public static final ConfigToken ACCEPT_MODS = new DependendConfigToken(true,"acceptMods", SYNC_CATEGORY, (config)->config.get(ENABLED)); + public static final DependendConfigToken ACCEPT_MODS = DependendConfigToken.Boolean(true,"acceptMods", SYNC_CATEGORY, (config)->config.get(ENABLED)); @ConfigUI(topPadding = 12) - public static final ConfigToken DEBUG_HASHES = new ConfigToken(true, "debugHashes", SYNC_CATEGORY); + public static final ConfigToken DEBUG_HASHES = ConfigToken.Boolean(true, "debugHashes", SYNC_CATEGORY); public ClientConfig(){ @@ -56,23 +56,25 @@ public class AutoSync { } public boolean isAcceptingMods() { - return get(ACCEPT_MODS) && isAllowingAutoSync(); + return get(ACCEPT_MODS) /*&& isAllowingAutoSync()*/; } public boolean isAcceptingConfigs() { - return get(ACCEPT_CONFIGS) && isAllowingAutoSync(); + return get(ACCEPT_CONFIGS) /*&& isAllowingAutoSync()*/; } public boolean isAcceptingFiles() { - return get(ACCEPT_FILES) && isAllowingAutoSync(); + return get(ACCEPT_FILES) /*&& isAllowingAutoSync()*/; } } public static class ServerConfig extends NamedPathConfig { - public static final ConfigToken ENABLED = new ConfigToken(true, "enabled", SYNC_CATEGORY); - public static final ConfigToken OFFER_CONFIGS = new ConfigToken(true,"offerConfigs", SYNC_CATEGORY); - public static final ConfigToken OFFER_FILES = new ConfigToken(true,"offerFiles", SYNC_CATEGORY); - public static final ConfigToken OFFER_MODS = new ConfigToken(true,"offerMods", SYNC_CATEGORY); + public static final ConfigToken ENABLED = ConfigToken.Boolean(true, "enabled", SYNC_CATEGORY); + public static final DependendConfigToken OFFER_CONFIGS = DependendConfigToken.Boolean(true,"offerConfigs", SYNC_CATEGORY, (config)->config.get(ENABLED)); + public static final DependendConfigToken OFFER_FILES = DependendConfigToken.Boolean(true,"offerFiles", SYNC_CATEGORY, (config)->config.get(ENABLED)); + public static final DependendConfigToken OFFER_MODS = DependendConfigToken.Boolean(true,"offerMods", SYNC_CATEGORY, (config)->config.get(ENABLED)); + + public static final ConfigToken> ADDITIONAL_MODS = ConfigToken.StringArray(new ArrayList<>(0),"additionalMods", SYNC_CATEGORY); public ServerConfig(){ @@ -84,15 +86,19 @@ public class AutoSync { } public boolean isOfferingConfigs() { - return get(OFFER_CONFIGS) && isAllowingAutoSync(); + return get(OFFER_CONFIGS) /*&& isAllowingAutoSync()*/; } public boolean isOfferingFiles() { - return get(OFFER_FILES) && isAllowingAutoSync(); + return get(OFFER_FILES) /*&& isAllowingAutoSync()*/; } public boolean isOfferingMods() { - return get(OFFER_MODS) && isAllowingAutoSync(); + return get(OFFER_MODS) /*&& isAllowingAutoSync()*/; + } + + public String[] additionalModsForSync() { + return new String[0]; } } diff --git a/src/main/java/ru/bclib/config/NamedPathConfig.java b/src/main/java/ru/bclib/config/NamedPathConfig.java index 71ee456b..1bf295c7 100644 --- a/src/main/java/ru/bclib/config/NamedPathConfig.java +++ b/src/main/java/ru/bclib/config/NamedPathConfig.java @@ -2,6 +2,11 @@ package ru.bclib.config; import net.minecraft.resources.ResourceLocation; import ru.bclib.BCLib; +import ru.bclib.config.ConfigKeeper.BooleanEntry; +import ru.bclib.config.ConfigKeeper.FloatEntry; +import ru.bclib.config.ConfigKeeper.IntegerEntry; +import ru.bclib.config.ConfigKeeper.StringArrayEntry; +import ru.bclib.config.ConfigKeeper.StringEntry; import java.lang.reflect.Field; import java.lang.reflect.Modifier; @@ -49,47 +54,68 @@ public class NamedPathConfig extends PathConfig{ public static class DependendConfigToken extends ConfigToken{ protected final Predicate dependenciesTrue; - public DependendConfigToken(T defaultValue, String entry, ResourceLocation path, Predicate dependenciesTrue) { - this(defaultValue, entry, new String[]{path.getNamespace(), path.getPath()}, dependenciesTrue); + protected DependendConfigToken(Class type, T defaultValue, String entry, ResourceLocation path, Predicate dependenciesTrue) { + this(type, defaultValue, entry, new String[]{path.getNamespace(), path.getPath()}, dependenciesTrue); } - public DependendConfigToken(T defaultValue, String entry, String path, Predicate dependenciesTrue) { - super(defaultValue, entry, path); + protected DependendConfigToken(Class type, T defaultValue, String entry, String path, Predicate dependenciesTrue) { + super(type, defaultValue, entry, path); this.dependenciesTrue = dependenciesTrue; } - public DependendConfigToken(T defaultValue, String entry, String[] path, Predicate dependenciesTrue) { - super(defaultValue, entry, path); + protected DependendConfigToken(Class type, T defaultValue, String entry, String[] path, Predicate dependenciesTrue) { + super(type, defaultValue, entry, path); this.dependenciesTrue = dependenciesTrue; } public boolean dependenciesTrue(NamedPathConfig config){ return dependenciesTrue.test(config); } + + public static DependendConfigToken Boolean(boolean defaultValue, String entry, String path, Predicate dependenciesTrue) { + return new DependendConfigToken(BooleanEntry.class, defaultValue, entry, path, dependenciesTrue); + } } public static class ConfigToken extends ConfigKey{ public final T defaultValue; - public final Class type; + public final Class type; - public ConfigToken(T defaultValue, String entry, ResourceLocation path) { - this(defaultValue, entry, path.getNamespace(), path.getPath()); + protected ConfigToken(Class type, T defaultValue, String entry, ResourceLocation path) { + this(type, defaultValue, entry, path.getNamespace(), path.getPath()); } @SuppressWarnings("unchecked") - public ConfigToken(T defaultValue, String entry, String... path) { + protected ConfigToken(Class type, T defaultValue, String entry, String... path) { super(entry, path); this.defaultValue = defaultValue; - if (defaultValue == null){ - BCLib.LOGGER.error("[Internal Error] defaultValue should not be null (" +this.getEntry() +")"); - } - this.type = defaultValue!=null?(Class)defaultValue.getClass():(Class)Object.class; + this.type = type; } public boolean dependenciesTrue(NamedPathConfig config){ return true; } + + public static ConfigToken Boolean(boolean defaultValue, String entry, String path) { + return new ConfigToken(BooleanEntry.class, defaultValue, entry, path); + } + + public static ConfigToken Int(int defaultValue, String entry, String path) { + return new ConfigToken(IntegerEntry.class, defaultValue, entry, path); + } + + public static ConfigToken Float(float defaultValue, String entry, String path) { + return new ConfigToken(FloatEntry.class, defaultValue, entry, path); + } + + public static ConfigToken String(String defaultValue, String entry, String path) { + return new ConfigToken(StringEntry.class, defaultValue, entry, path); + } + + public static ConfigToken> StringArray(List defaultValue, String entry, String path) { + return new ConfigToken>(StringArrayEntry.class, defaultValue, entry, path); + } } public NamedPathConfig(String modID, String group, boolean autoSync, boolean diffContent) { @@ -157,18 +183,21 @@ public class NamedPathConfig extends PathConfig{ @SuppressWarnings("unchecked") private T _get(ConfigToken what, boolean raw){ //TODO: Check if we can make config fully Generic to avoid runtime type checks... - if (Boolean.class.isAssignableFrom(what.type)){ + if (BooleanEntry.class.isAssignableFrom(what.type)){ return (T)_getBoolean((ConfigToken)what, raw); } - if (Integer.class.isAssignableFrom(what.type)){ + if (IntegerEntry.class.isAssignableFrom(what.type)){ return (T)_getInt((ConfigToken)what); } - if (Float.class.isAssignableFrom(what.type)){ + if (FloatEntry.class.isAssignableFrom(what.type)){ return (T)_getFloat((ConfigToken)what); } - if (String.class.isAssignableFrom(what.type)){ + if (StringEntry.class.isAssignableFrom(what.type)){ return (T)_getString((ConfigToken)what); } + if (StringArrayEntry.class.isAssignableFrom(what.type)){ + return (T)_getStringArray((ConfigToken>)what); + } return this._get(what); } @@ -209,5 +238,12 @@ public class NamedPathConfig extends PathConfig{ return this.getString(what, what.defaultValue); } + public void set(ConfigToken> what, List value) { + this.setStringArray(what, value); + } + private List _getStringArray(ConfigToken> what){ + return this.getStringArray(what, what.defaultValue); + } + }