package nl.dykam.dev.reutil.data;

import nl.dykam.dev.reutil.data.annotations.*;

import java.lang.reflect.Array;

class ComponentInfo {

    public static final ObjectType[] ALL_OBJECT_TYPES = ObjectType.values();
    @SuppressWarnings("unchecked")
    public static final Class<? extends Component>[] NO_CLASSES = (Class<? extends Component>[]) Array.newInstance(Class.class, 0);
    private static final SaveMoment[] DEFAULT_SAVE_MOMENTS = {SaveMoment.PluginUnload};

    public static <T extends Component> Defaults getDefaults(Class<T> type) {
        return type.getAnnotation(Defaults.class);
    }

    private static <T extends Component>  ComponentBuilder<T> getBuilder(Class<T> type) {
        return ComponentBuilder.getBuilder(type);
    }

    public static <T extends Component> ObjectType[] getApplicables(Class<T> type) {
        ApplicableTo annotation = type.getAnnotation(ApplicableTo.class);
        return annotation == null ? ALL_OBJECT_TYPES : annotation.value();
    }

    @SuppressWarnings("unchecked")
    public static <T extends Component> Class<? extends Component>[] getRequired(Class<T> type) {
        Require annotation = type.getAnnotation(Require.class);
        return annotation == null ? NO_CLASSES : annotation.value();
    }

    public static SaveMoment[] getSaveMoments(Component component) {
        Persistent annotation = component.getClass().getAnnotation(Persistent.class);
        return annotation == null ? DEFAULT_SAVE_MOMENTS : annotation.value();
    }

    public static Defaults getDefaults(Component component) {
        return getDefaults(component.getClass());
    }
}

@@ -59,26 +59,166 @@
 til.
-data.annotations.*
+ReUtilPlugin;%0Aimport nl.dykam.dev.reutil.data.annotations.*;%0Aimport org.bukkit.Bukkit;%0Aimport org.bukkit.configuration.serialization.ConfigurationSerializable
 ;%0A%0Ai
@@ -582,31 +582,8 @@
  = %7B
-SaveMoment.PluginUnload
 %7D;%0A%0A
@@ -758,17 +758,16 @@
 mponent%3E
- 
  Compone
@@ -1439,32 +1439,106 @@
 nt component) %7B%0A
+        Class%3C? extends Component%3E componentClass = component.getClass();%0A
         Persiste
@@ -1562,27 +1562,21 @@
 omponent
-.get
 Class
-()
 .getAnno
@@ -1613,58 +1613,396 @@
     
-return annotation == null ? DEFAULT_SAVE_MOMENTS :
+SaveMoment%5B%5D result = DEFAULT_SAVE_MOMENTS;%0A        if(annotation == null) %7B%0A            return DEFAULT_SAVE_MOMENTS;%0A        %7D else if(!ConfigurationSerializable.class.isAssignableFrom(componentClass)) %7B%0A            ReUtilPlugin.getMessage().warn(Bukkit.getConsoleSender(), %22ConfigurationSerializable not implemented by @Persistent %22 + componentClass.getName());%0A        %7D%0A        return
  ann

Fix ComponentInfo.getSaveMoments to return nothing when @Persistent is missing