Class ConfigurationSerialization
java.lang.Object
org.bukkit.configuration.serialization.ConfigurationSerialization
public class ConfigurationSerialization
extends java.lang.Object
Utility class for storing and retrieving classes for
Configuration.-
Field Summary
Fields Modifier and Type Field Description private static java.util.Map<java.lang.String,java.lang.Class<? extends ConfigurationSerializable>>aliasesprivate java.lang.Class<? extends ConfigurationSerializable>clazzstatic java.lang.StringSERIALIZED_TYPE_KEY -
Constructor Summary
Constructors Modifier Constructor Description protectedConfigurationSerialization(@NotNull java.lang.Class<? extends ConfigurationSerializable> clazz) -
Method Summary
Modifier and Type Method Description @Nullable ConfigurationSerializabledeserialize(@NotNull java.util.Map<java.lang.String,?> args)static @Nullable ConfigurationSerializabledeserializeObject(@NotNull java.util.Map<java.lang.String,?> args)Attempts to deserialize the given arguments into a new instance of the given class.static @Nullable ConfigurationSerializabledeserializeObject(@NotNull java.util.Map<java.lang.String,?> args, @NotNull java.lang.Class<? extends ConfigurationSerializable> clazz)Attempts to deserialize the given arguments into a new instance of the given class.protected @Nullable ConfigurationSerializabledeserializeViaCtor(@NotNull java.lang.reflect.Constructor<? extends ConfigurationSerializable> ctor, @NotNull java.util.Map<java.lang.String,?> args)protected @Nullable ConfigurationSerializabledeserializeViaMethod(@NotNull java.lang.reflect.Method method, @NotNull java.util.Map<java.lang.String,?> args)static @NotNull java.lang.StringgetAlias(@NotNull java.lang.Class<? extends ConfigurationSerializable> clazz)Gets the correct alias for the givenConfigurationSerializableclassstatic @Nullable java.lang.Class<? extends ConfigurationSerializable>getClassByAlias(@NotNull java.lang.String alias)Attempts to get a registeredConfigurationSerializableclass by its aliasprotected @Nullable java.lang.reflect.Constructor<? extends ConfigurationSerializable>getConstructor()protected @Nullable java.lang.reflect.MethodgetMethod(@NotNull java.lang.String name, boolean isStatic)static voidregisterClass(@NotNull java.lang.Class<? extends ConfigurationSerializable> clazz)Registers the givenConfigurationSerializableclass by its aliasstatic voidregisterClass(@NotNull java.lang.Class<? extends ConfigurationSerializable> clazz, @NotNull java.lang.String alias)Registers the given alias to the specifiedConfigurationSerializableclassstatic voidunregisterClass(@NotNull java.lang.Class<? extends ConfigurationSerializable> clazz)Unregisters any aliases for the specifiedConfigurationSerializableclassstatic voidunregisterClass(@NotNull java.lang.String alias)Unregisters the specified alias to aConfigurationSerializableMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
SERIALIZED_TYPE_KEY
public static final java.lang.String SERIALIZED_TYPE_KEY- See Also:
- Constant Field Values
-
clazz
-
aliases
private static java.util.Map<java.lang.String,java.lang.Class<? extends ConfigurationSerializable>> aliases
-
-
Constructor Details
-
ConfigurationSerialization
protected ConfigurationSerialization(@NotNull @NotNull java.lang.Class<? extends ConfigurationSerializable> clazz)
-
-
Method Details
-
getMethod
@Nullable protected @Nullable java.lang.reflect.Method getMethod(@NotNull @NotNull java.lang.String name, boolean isStatic) -
getConstructor
@Nullable protected @Nullable java.lang.reflect.Constructor<? extends ConfigurationSerializable> getConstructor() -
deserializeViaMethod
@Nullable protected @Nullable ConfigurationSerializable deserializeViaMethod(@NotNull @NotNull java.lang.reflect.Method method, @NotNull @NotNull java.util.Map<java.lang.String,?> args) -
deserializeViaCtor
@Nullable protected @Nullable ConfigurationSerializable deserializeViaCtor(@NotNull @NotNull java.lang.reflect.Constructor<? extends ConfigurationSerializable> ctor, @NotNull @NotNull java.util.Map<java.lang.String,?> args) -
deserialize
@Nullable public @Nullable ConfigurationSerializable deserialize(@NotNull @NotNull java.util.Map<java.lang.String,?> args) -
deserializeObject
@Nullable public static @Nullable ConfigurationSerializable deserializeObject(@NotNull @NotNull java.util.Map<java.lang.String,?> args, @NotNull @NotNull java.lang.Class<? extends ConfigurationSerializable> clazz)Attempts to deserialize the given arguments into a new instance of the given class.The class must implement
ConfigurationSerializable, including the extra methods as specified in the javadoc of ConfigurationSerializable.If a new instance could not be made, an example being the class not fully implementing the interface, null will be returned.
- Parameters:
args- Arguments for deserializationclazz- Class to deserialize into- Returns:
- New instance of the specified class
-
deserializeObject
@Nullable public static @Nullable ConfigurationSerializable deserializeObject(@NotNull @NotNull java.util.Map<java.lang.String,?> args)Attempts to deserialize the given arguments into a new instance of the given class.The class must implement
ConfigurationSerializable, including the extra methods as specified in the javadoc of ConfigurationSerializable.If a new instance could not be made, an example being the class not fully implementing the interface, null will be returned.
- Parameters:
args- Arguments for deserialization- Returns:
- New instance of the specified class
-
registerClass
public static void registerClass(@NotNull @NotNull java.lang.Class<? extends ConfigurationSerializable> clazz)Registers the givenConfigurationSerializableclass by its alias- Parameters:
clazz- Class to register
-
registerClass
public static void registerClass(@NotNull @NotNull java.lang.Class<? extends ConfigurationSerializable> clazz, @NotNull @NotNull java.lang.String alias)Registers the given alias to the specifiedConfigurationSerializableclass- Parameters:
clazz- Class to registeralias- Alias to register as- See Also:
SerializableAs
-
unregisterClass
public static void unregisterClass(@NotNull @NotNull java.lang.String alias)Unregisters the specified alias to aConfigurationSerializable- Parameters:
alias- Alias to unregister
-
unregisterClass
public static void unregisterClass(@NotNull @NotNull java.lang.Class<? extends ConfigurationSerializable> clazz)Unregisters any aliases for the specifiedConfigurationSerializableclass- Parameters:
clazz- Class to unregister
-
getClassByAlias
@Nullable public static @Nullable java.lang.Class<? extends ConfigurationSerializable> getClassByAlias(@NotNull @NotNull java.lang.String alias)Attempts to get a registeredConfigurationSerializableclass by its alias- Parameters:
alias- Alias of the serializable- Returns:
- Registered class, or null if not found
-
getAlias
@NotNull public static @NotNull java.lang.String getAlias(@NotNull @NotNull java.lang.Class<? extends ConfigurationSerializable> clazz)Gets the correct alias for the givenConfigurationSerializableclass- Parameters:
clazz- Class to get alias for- Returns:
- Alias to use for the class
-