Class SaveData<T>
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.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionSaveData(Supplier<@NotNull T> defaultValue, CodecHolder<T> codecHolder, Supplier<File> fileGetter, SaveData.Type type) Creates new save data. -
Method Summary
-
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 withmarkDirty()or if the file doesn't already exist. -
getCodecHolder
Gets the codec holder used for serialization.- Returns:
- The codec holder
-
getData
Get the saved value. -
setData
Set the saved value. This callsmarkDirty()for you. -
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.
-