MySQL Data Changes: Keys are now registered on first read/write

This commit is contained in:
Auxilor
2022-02-16 16:32:38 +00:00
parent 9a51fb8358
commit 5aeeafc041
6 changed files with 51 additions and 73 deletions

View File

@@ -1,6 +1,8 @@
package com.willfp.eco.core.data.keys;
import org.bukkit.NamespacedKey;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Set;
@@ -21,4 +23,13 @@ public interface KeyRegistry {
* @return The keys.
*/
Set<PersistentDataKey<?>> getRegisteredKeys();
/**
* Get persistent data key from namespaced key.
*
* @param namespacedKey The key.
* @return The key, or null if not found.
*/
@Nullable
PersistentDataKey<?> getKeyFrom(@NotNull NamespacedKey namespacedKey);
}

View File

@@ -29,11 +29,6 @@ public class PersistentDataKey<T> {
*/
private final PersistentDataKeyType<T> type;
/**
* If the key is for server data.
*/
private final boolean isServerKey;
/**
* Create a new Persistent Data Key.
*
@@ -44,25 +39,9 @@ public class PersistentDataKey<T> {
public PersistentDataKey(@NotNull final NamespacedKey key,
@NotNull final PersistentDataKeyType<T> type,
@NotNull final T defaultValue) {
this(key, type, defaultValue, false);
}
/**
* Create a new Persistent Data Key.
*
* @param key The key.
* @param type The data type.
* @param defaultValue The default value.
* @param isServerKey If the key is for server data.
*/
public PersistentDataKey(@NotNull final NamespacedKey key,
@NotNull final PersistentDataKeyType<T> type,
@NotNull final T defaultValue,
final boolean isServerKey) {
this.key = key;
this.defaultValue = defaultValue;
this.type = type;
this.isServerKey = isServerKey;
Eco.getHandler().getKeyRegistry().registerKey(this);
}
@@ -103,15 +82,6 @@ public class PersistentDataKey<T> {
return this.type;
}
/**
* Get if the key is for server data.
*
* @return If server key.
*/
public boolean isServerKey() {
return isServerKey;
}
/**
* Get all persistent data keys.
*