Added ability to specify local storage usage individually for each persistent data key via a constructor parameter

This commit is contained in:
_OfTeN_
2023-08-20 17:39:22 +03:00
parent ed41c1091c
commit 8052ffa706
2 changed files with 29 additions and 0 deletions

View File

@@ -29,6 +29,31 @@ public final class PersistentDataKey<T> {
*/
private final PersistentDataKeyType<T> type;
/**
* If the key uses local storage.
*/
private final boolean local;
/**
* Create a new Persistent Data Key.
*
* @param key The key.
* @param type The data type.
* @param defaultValue The default value.
* @param local If the key uses local storage.
*/
public PersistentDataKey(@NotNull final NamespacedKey key,
@NotNull final PersistentDataKeyType<T> type,
@NotNull final T defaultValue,
final boolean local) {
this.key = key;
this.defaultValue = defaultValue;
this.type = type;
this.local = local;
Eco.get().registerPersistentKey(this);
}
/**
* Create a new Persistent Data Key.
*
@@ -42,6 +67,7 @@ public final class PersistentDataKey<T> {
this.key = key;
this.defaultValue = defaultValue;
this.type = type;
this.local = false;
Eco.get().registerPersistentKey(this);
}
@@ -82,6 +108,8 @@ public final class PersistentDataKey<T> {
return this.type;
}
public boolean isLocalStorage() { return this.local; }
/**
* Get all persistent data keys.
*