Skip to content

Commit

Permalink
Improved local keys
Browse files Browse the repository at this point in the history
  • Loading branch information
WillFP committed Dec 3, 2023
1 parent 77de51b commit 1a75dd8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,24 @@ public final class PersistentDataKey<T> {
/**
* If the key uses local storage.
*/
private final boolean local;
private final boolean isLocal;

/**
* 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.
* @param isLocal If the key uses local storage.
*/
public PersistentDataKey(@NotNull final NamespacedKey key,
@NotNull final PersistentDataKeyType<T> type,
@NotNull final T defaultValue,
final boolean local) {
final boolean isLocal) {
this.key = key;
this.defaultValue = defaultValue;
this.type = type;
this.local = local;
this.isLocal = isLocal;

Eco.get().registerPersistentKey(this);
}
Expand All @@ -67,7 +67,7 @@ public PersistentDataKey(@NotNull final NamespacedKey key,
this.key = key;
this.defaultValue = defaultValue;
this.type = type;
this.local = false;
this.isLocal = false;

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

public boolean isLocalStorage() { return this.local; }
/**
* Get if the key uses local storage.
*
* @return If the key uses local storage.
*/
public boolean isLocal() {
return this.isLocal;
}

/**
* Get all persistent data keys.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ abstract class EcoProfile(
return this.data[key] as T
}

this.data[key] = if (key.isLocal) {
this.data[key] = if (key.isSavedLocally) {
localHandler.read(uuid, key)
} else {
handler.read(uuid, key)
Expand Down Expand Up @@ -104,6 +104,7 @@ class EcoServerProfile(
}
}

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

0 comments on commit 1a75dd8

Please sign in to comment.