From 8052ffa706fb68eb74a6e947c3f97f4d11ea6541 Mon Sep 17 00:00:00 2001 From: _OfTeN_ Date: Sun, 20 Aug 2023 17:39:22 +0300 Subject: [PATCH] Added ability to specify local storage usage individually for each persistent data key via a constructor parameter --- .../eco/core/data/keys/PersistentDataKey.java | 28 +++++++++++++++++++ .../eco/internal/spigot/data/EcoProfile.kt | 1 + 2 files changed, 29 insertions(+) diff --git a/eco-api/src/main/java/com/willfp/eco/core/data/keys/PersistentDataKey.java b/eco-api/src/main/java/com/willfp/eco/core/data/keys/PersistentDataKey.java index 44ce98c98..00f0aa8b2 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/data/keys/PersistentDataKey.java +++ b/eco-api/src/main/java/com/willfp/eco/core/data/keys/PersistentDataKey.java @@ -29,6 +29,31 @@ public final class PersistentDataKey { */ private final PersistentDataKeyType 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 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 PersistentDataKey(@NotNull final NamespacedKey key, this.key = key; this.defaultValue = defaultValue; this.type = type; + this.local = false; Eco.get().registerPersistentKey(this); } @@ -82,6 +108,8 @@ public PersistentDataKeyType getType() { return this.type; } + public boolean isLocalStorage() { return this.local; } + /** * Get all persistent data keys. * diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoProfile.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoProfile.kt index 7de71c377..72ba1062f 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoProfile.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoProfile.kt @@ -106,3 +106,4 @@ class EcoServerProfile( private val PersistentDataKey<*>.isLocal: Boolean get() = this == localServerIDKey || EcoPlugin.getPlugin(this.key.namespace)?.isUsingLocalStorage == true + || this.isLocalStorage