package draylar.omegaconfig.api; import draylar.omegaconfig.OmegaConfig; import net.minecraft.nbt.NbtCompound; import org.jetbrains.annotations.Nullable; import java.util.Arrays; public interface Config { /** * Writes this configuration file instance to disk. * Useful for saving modified values during runtime. */ default void save() { OmegaConfig.writeConfig((Class) getClass(), this); } default NbtCompound writeSyncingTag() { NbtCompound tag = new NbtCompound(); tag.putString("ConfigName", getName()); // all config vs. individual fields if (Arrays.stream(getClass().getAnnotations()).anyMatch(annotation -> annotation instanceof Syncing)) { // write ALL fields to tag String json = OmegaConfig.GSON.toJson(this); tag.putString("Serialized", json); tag.putBoolean("AllSync", true); } else { // write all syncable fields to tag String json = OmegaConfig.SYNC_ONLY_GSON.toJson(this); tag.putString("Serialized", json); tag.putBoolean("AllSync", false); } return tag; } /** * @return true if this {@link Config} has any values that should be synced to the client */ default boolean hasAnySyncable() { boolean hasSyncingField = Arrays.stream(getClass().getDeclaredFields()).anyMatch(field -> Arrays.stream(field.getDeclaredAnnotations()).anyMatch(annotation -> annotation instanceof Syncing)); boolean classSyncs = Arrays.stream(getClass().getDeclaredAnnotations()).anyMatch(annotation -> annotation instanceof Syncing); return hasSyncingField | classSyncs; } /** * Returns the name of this config, which is used for the name of the config file saved to disk, and syncing. * *

* The name returned by this method should generally follow Identifier conventions, but this is not enforced: *