Package net.citizensnpcs.api.persistence
Class PersistenceLoader
java.lang.Object
net.citizensnpcs.api.persistence.PersistenceLoader
Performs reflective persistence of objects into
DataKeys. Persist annotations are used to mark fields
for annotation.- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> PersisterRegistry<T> createRegistry(Class<?> base) static <T> TCreates an instance of the given class using the default constructor and loads it usingload(Object, DataKey).static <T> Tstatic voidregisterPersistDelegate(Class<?> clazz, Class<? extends Persister<?>> delegateClass) Registers aPersisterredirect.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 forFields with thePersistannotation and loads data into them using the givenDataKey. If aDelegatePersistenceannotation is provided the referencedPersisterwill 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 aPersisterredirect. Fields or constructors with thePersistannotation with a type that has been registered using this method will use the suppliedPersisterfor (de)serialisation. TheDelegatePersistenceannotation 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
-