Package net.citizensnpcs.api.persistence
Class PersistenceLoader
java.lang.Object
net.citizensnpcs.api.persistence.PersistenceLoader
Performs reflective persistence of objects into
DataKey
s. Persist
annotations are used to mark fields
for annotation.- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> PersisterRegistry
<T> createRegistry
(Class<?> base) static <T> T
Creates an instance of the given class using the default constructor and loads it usingload(Object, DataKey)
.static <T> T
static void
registerPersistDelegate
(Class<?> clazz, Class<? extends Persister<?>> delegateClass) Registers aPersister
redirect.static void
-
Constructor Details
-
PersistenceLoader
public PersistenceLoader()
-
-
Method Details
-
createRegistry
-
load
Creates an instance of the given class using the default constructor and loads it usingload(Object, DataKey)
. Will return null if an exception occurs.- Parameters:
clazz
- The class to create an instance fromroot
- The root key to load from- Returns:
- The loaded instance
- See Also:
-
load
Analyses the class forField
s with thePersist
annotation and loads data into them using the givenDataKey
. If aDelegatePersistence
annotation is provided the referencedPersister
will be used to create the instance. This annotation can be omitted if the Persister has been registered usingregisterPersistDelegate(Class, Class)
- Parameters:
instance
- The instance to load data intoroot
- The key to load data from- Returns:
- The instance, with persisted fields loaded
-
registerPersistDelegate
public static void registerPersistDelegate(Class<?> clazz, Class<? extends Persister<?>> delegateClass) Registers aPersister
redirect. Fields or constructors with thePersist
annotation with a type that has been registered using this method will use the suppliedPersister
for (de)serialisation. TheDelegatePersistence
annotation will be preferred if present.- Parameters:
clazz
- The class to redirectdelegateClass
- The Persister class to use when loading and saving
-
save
- Parameters:
instance
- The instance to saveroot
- The key to save into
-