Skip to content

Commit

Permalink
Added ability to specify local storage usage individually for each pe…
Browse files Browse the repository at this point in the history
…rsistent data key via a constructor parameter
  • Loading branch information
0ft3n committed Aug 20, 2023
1 parent ed41c10 commit 8052ffa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -42,6 +67,7 @@ public PersistentDataKey(@NotNull final NamespacedKey key,
this.key = key;
this.defaultValue = defaultValue;
this.type = type;
this.local = false;

Eco.get().registerPersistentKey(this);
}
Expand Down Expand Up @@ -82,6 +108,8 @@ public PersistentDataKeyType<T> getType() {
return this.type;
}

public boolean isLocalStorage() { return this.local; }

/**
* Get all persistent data keys.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,4 @@ class EcoServerProfile(

private val PersistentDataKey<*>.isLocal: Boolean
get() = this == localServerIDKey || EcoPlugin.getPlugin(this.key.namespace)?.isUsingLocalStorage == true
|| this.isLocalStorage

0 comments on commit 8052ffa

Please sign in to comment.