java.lang.Object
dev.scsupercraft.mc.libraries.corelib.api.data.SaveData<T>
Type Parameters:
T - The type of the data being saved.
All Implemented Interfaces:
Data<T>
Direct Known Subclasses:
AutoSaveData, WorldSaveData

@AvailableSince("1.0.0") public sealed class SaveData<T> extends Object implements Data<T> permits AutoSaveData<T>, WorldSaveData<T>
A helper class for save data.
  • Constructor Details

    • SaveData

      @AvailableSince("1.0.0") public SaveData(Supplier<@NotNull T> defaultValue, CodecHolder<T> codecHolder, Supplier<File> fileGetter, SaveData.Type type)
      Creates new save data.
      Parameters:
      defaultValue - A supplier that returns the default value for this savable. Used if there isn't any existing data during loading.
      codecHolder - A codec holder for serializing the save data.
      fileGetter - A supplier that returns the file that the data will be saved to.
      type - What should the data be saved as.
  • Method Details

    • load

      @AvailableSince("1.0.0") public void load()
      Loads the data from the disk.
    • save

      @AvailableSince("1.0.0") public void save()
      Saves the data to the disk. Only saves if marked with markDirty() or if the file doesn't already exist.
    • getCodecHolder

      @AvailableSince("1.0.0") public CodecHolder<T> getCodecHolder()
      Gets the codec holder used for serialization.
      Returns:
      The codec holder
    • getData

      @AvailableSince("1.0.0") @NotNull public T getData()
      Get the saved value.
      Specified by:
      getData in interface Data<T>
      Returns:
      The current value.
    • setData

      @AvailableSince("1.0.0") public void setData(@NotNull T value)
      Set the saved value. This calls markDirty() for you.
      Specified by:
      setData in interface Data<T>
      Parameters:
      value - The new value.
    • markDirty

      @AvailableSince("1.0.0") public void markDirty()
      Tell the savable that it was updated. Failing to call this method after an update will result in the data not getting saved.