|
@@ -5,6 +5,7 @@ import me.lortseam.completeconfig.ConfigMap;
|
|
import me.lortseam.completeconfig.api.ConfigEntry;
|
|
import me.lortseam.completeconfig.api.ConfigEntry;
|
|
import me.lortseam.completeconfig.api.ConfigEntryContainer;
|
|
import me.lortseam.completeconfig.api.ConfigEntryContainer;
|
|
import me.lortseam.completeconfig.api.ConfigEntryListener;
|
|
import me.lortseam.completeconfig.api.ConfigEntryListener;
|
|
|
|
+import me.lortseam.completeconfig.entry.Bounds;
|
|
import me.lortseam.completeconfig.entry.Entry;
|
|
import me.lortseam.completeconfig.entry.Entry;
|
|
import me.lortseam.completeconfig.exception.IllegalAnnotationParameterException;
|
|
import me.lortseam.completeconfig.exception.IllegalAnnotationParameterException;
|
|
import me.lortseam.completeconfig.exception.IllegalAnnotationTargetException;
|
|
import me.lortseam.completeconfig.exception.IllegalAnnotationTargetException;
|
|
@@ -20,7 +21,7 @@ public class EntryMap extends ConfigMap<Entry> {
|
|
void fill(ConfigEntryContainer container) {
|
|
void fill(ConfigEntryContainer container) {
|
|
LinkedHashMap<String, Entry> containerEntries = new LinkedHashMap<>();
|
|
LinkedHashMap<String, Entry> containerEntries = new LinkedHashMap<>();
|
|
for (Class<? extends ConfigEntryContainer> clazz : container.getClasses()) {
|
|
for (Class<? extends ConfigEntryContainer> clazz : container.getClasses()) {
|
|
- List<Listener> listeners = new ArrayList<>();
|
|
|
|
|
|
+ /*List<Listener> listeners = new ArrayList<>();
|
|
Iterator<Listener> iter = pendingListeners.iterator();
|
|
Iterator<Listener> iter = pendingListeners.iterator();
|
|
while (iter.hasNext()) {
|
|
while (iter.hasNext()) {
|
|
Listener listener = iter.next();
|
|
Listener listener = iter.next();
|
|
@@ -28,7 +29,7 @@ public class EntryMap extends ConfigMap<Entry> {
|
|
listeners.add(listener);
|
|
listeners.add(listener);
|
|
iter.remove();
|
|
iter.remove();
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ }*/
|
|
Arrays.stream(clazz.getDeclaredMethods()).filter(method -> !Modifier.isStatic(method.getModifiers()) && method.isAnnotationPresent(ConfigEntryListener.class)).forEach(method -> {
|
|
Arrays.stream(clazz.getDeclaredMethods()).filter(method -> !Modifier.isStatic(method.getModifiers()) && method.isAnnotationPresent(ConfigEntryListener.class)).forEach(method -> {
|
|
ConfigEntryListener listener = method.getDeclaredAnnotation(ConfigEntryListener.class);
|
|
ConfigEntryListener listener = method.getDeclaredAnnotation(ConfigEntryListener.class);
|
|
String fieldName = listener.value();
|
|
String fieldName = listener.value();
|
|
@@ -40,6 +41,18 @@ public class EntryMap extends ConfigMap<Entry> {
|
|
}
|
|
}
|
|
Class<? extends ConfigEntryContainer> fieldClass = listener.container();
|
|
Class<? extends ConfigEntryContainer> fieldClass = listener.container();
|
|
if (fieldClass == ConfigEntryContainer.class) {
|
|
if (fieldClass == ConfigEntryContainer.class) {
|
|
|
|
+ fieldClass = container.getClass();
|
|
|
|
+ }
|
|
|
|
+ //TODO: Check for void return type
|
|
|
|
+ //TODO: Check for valid parameter type
|
|
|
|
+ if (method.getParameterCount() != 1) {
|
|
|
|
+ throw new IllegalArgumentException("Listener method " + method + " has wrong number of parameters");
|
|
|
|
+ }
|
|
|
|
+ if (!method.isAccessible()) {
|
|
|
|
+ method.setAccessible(true);
|
|
|
|
+ }
|
|
|
|
+ Entry.of(fieldName, fieldClass).addListener(method, container);
|
|
|
|
+ /*if (fieldClass == ConfigEntryContainer.class) {
|
|
listeners.add(new Listener(method, container, fieldName));
|
|
listeners.add(new Listener(method, container, fieldName));
|
|
} else {
|
|
} else {
|
|
Map<String, Entry> fieldClassEntries = findEntries(config, fieldClass);
|
|
Map<String, Entry> fieldClassEntries = findEntries(config, fieldClass);
|
|
@@ -52,7 +65,7 @@ public class EntryMap extends ConfigMap<Entry> {
|
|
}
|
|
}
|
|
addListenerToEntry(entry, method, container);
|
|
addListenerToEntry(entry, method, container);
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ }*/
|
|
});
|
|
});
|
|
LinkedHashMap<String, Entry> clazzEntries = new LinkedHashMap<>();
|
|
LinkedHashMap<String, Entry> clazzEntries = new LinkedHashMap<>();
|
|
Arrays.stream(clazz.getDeclaredFields()).filter(field -> {
|
|
Arrays.stream(clazz.getDeclaredFields()).filter(field -> {
|
|
@@ -70,12 +83,12 @@ public class EntryMap extends ConfigMap<Entry> {
|
|
if (!field.isAccessible()) {
|
|
if (!field.isAccessible()) {
|
|
field.setAccessible(true);
|
|
field.setAccessible(true);
|
|
}
|
|
}
|
|
- Entry.Builder builder = new Entry.Builder(field, container);
|
|
|
|
|
|
+ Entry<?> entry = Entry.of(field, container);
|
|
if (field.isAnnotationPresent(ConfigEntry.class)) {
|
|
if (field.isAnnotationPresent(ConfigEntry.class)) {
|
|
ConfigEntry entryAnnotation = field.getDeclaredAnnotation(ConfigEntry.class);
|
|
ConfigEntry entryAnnotation = field.getDeclaredAnnotation(ConfigEntry.class);
|
|
String customTranslationKey = entryAnnotation.customTranslationKey();
|
|
String customTranslationKey = entryAnnotation.customTranslationKey();
|
|
if (!StringUtils.isBlank(customTranslationKey)) {
|
|
if (!StringUtils.isBlank(customTranslationKey)) {
|
|
- builder.setCustomTranslationKey(customTranslationKey);
|
|
|
|
|
|
+ entry.setCustomTranslationKey(customTranslationKey);
|
|
}
|
|
}
|
|
String[] customTooltipKeys = entryAnnotation.customTooltipKeys();
|
|
String[] customTooltipKeys = entryAnnotation.customTooltipKeys();
|
|
if (customTooltipKeys.length > 0) {
|
|
if (customTooltipKeys.length > 0) {
|
|
@@ -84,53 +97,45 @@ public class EntryMap extends ConfigMap<Entry> {
|
|
throw new IllegalAnnotationParameterException("Tooltip key(s) of entry field " + field + " must not be blank");
|
|
throw new IllegalAnnotationParameterException("Tooltip key(s) of entry field " + field + " must not be blank");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- builder.setCustomTooltipKeys(customTooltipKeys);
|
|
|
|
|
|
+ entry.setCustomTooltipKeys(customTooltipKeys);
|
|
}
|
|
}
|
|
- builder.setForceUpdate(entryAnnotation.forceUpdate());
|
|
|
|
|
|
+ entry.setForceUpdate(entryAnnotation.forceUpdate());
|
|
}
|
|
}
|
|
if (field.isAnnotationPresent(ConfigEntry.Bounded.Integer.class)) {
|
|
if (field.isAnnotationPresent(ConfigEntry.Bounded.Integer.class)) {
|
|
if (field.getType() != int.class && field.getType() != Integer.class) {
|
|
if (field.getType() != int.class && field.getType() != Integer.class) {
|
|
throw new IllegalAnnotationTargetException("Cannot apply Integer bound to non Integer field " + field);
|
|
throw new IllegalAnnotationTargetException("Cannot apply Integer bound to non Integer field " + field);
|
|
}
|
|
}
|
|
ConfigEntry.Bounded.Integer bounds = field.getDeclaredAnnotation(ConfigEntry.Bounded.Integer.class);
|
|
ConfigEntry.Bounded.Integer bounds = field.getDeclaredAnnotation(ConfigEntry.Bounded.Integer.class);
|
|
- builder.setBounds(bounds.min(), bounds.max());
|
|
|
|
|
|
+ entry.getExtras().setBounds(bounds.min(), bounds.max());
|
|
} else if (field.isAnnotationPresent(ConfigEntry.Bounded.Long.class)) {
|
|
} else if (field.isAnnotationPresent(ConfigEntry.Bounded.Long.class)) {
|
|
if (field.getType() != long.class && field.getType() != Long.class) {
|
|
if (field.getType() != long.class && field.getType() != Long.class) {
|
|
throw new IllegalAnnotationTargetException("Cannot apply Long bound to non Long field " + field);
|
|
throw new IllegalAnnotationTargetException("Cannot apply Long bound to non Long field " + field);
|
|
}
|
|
}
|
|
ConfigEntry.Bounded.Long bounds = field.getDeclaredAnnotation(ConfigEntry.Bounded.Long.class);
|
|
ConfigEntry.Bounded.Long bounds = field.getDeclaredAnnotation(ConfigEntry.Bounded.Long.class);
|
|
- builder.setBounds(bounds.min(), bounds.max());
|
|
|
|
|
|
+ entry.getExtras().setBounds(bounds.min(), bounds.max());
|
|
} else if (field.isAnnotationPresent(ConfigEntry.Bounded.Float.class)) {
|
|
} else if (field.isAnnotationPresent(ConfigEntry.Bounded.Float.class)) {
|
|
if (field.getType() != float.class && field.getType() != Float.class) {
|
|
if (field.getType() != float.class && field.getType() != Float.class) {
|
|
throw new IllegalAnnotationTargetException("Cannot apply Float bound to non Float field " + field);
|
|
throw new IllegalAnnotationTargetException("Cannot apply Float bound to non Float field " + field);
|
|
}
|
|
}
|
|
ConfigEntry.Bounded.Float bounds = field.getDeclaredAnnotation(ConfigEntry.Bounded.Float.class);
|
|
ConfigEntry.Bounded.Float bounds = field.getDeclaredAnnotation(ConfigEntry.Bounded.Float.class);
|
|
- builder.setBounds(bounds.min(), bounds.max());
|
|
|
|
|
|
+ entry.getExtras().setBounds(bounds.min(), bounds.max());
|
|
} else if (field.isAnnotationPresent(ConfigEntry.Bounded.Double.class)) {
|
|
} else if (field.isAnnotationPresent(ConfigEntry.Bounded.Double.class)) {
|
|
if (field.getType() != double.class && field.getType() != Double.class) {
|
|
if (field.getType() != double.class && field.getType() != Double.class) {
|
|
throw new IllegalAnnotationTargetException("Cannot apply Double bound to non Double field " + field);
|
|
throw new IllegalAnnotationTargetException("Cannot apply Double bound to non Double field " + field);
|
|
}
|
|
}
|
|
ConfigEntry.Bounded.Double bounds = field.getDeclaredAnnotation(ConfigEntry.Bounded.Double.class);
|
|
ConfigEntry.Bounded.Double bounds = field.getDeclaredAnnotation(ConfigEntry.Bounded.Double.class);
|
|
- builder.setBounds(bounds.min(), bounds.max());
|
|
|
|
|
|
+ entry.getExtras().setBounds(bounds.min(), bounds.max());
|
|
}
|
|
}
|
|
- Entry<?> entry = builder.build();
|
|
|
|
- if (guiRegistry.getProvider(entry) == null) {
|
|
|
|
|
|
+ //TODO
|
|
|
|
+ /*if (guiRegistry.getProvider(entry) == null) {
|
|
throw new UnsupportedOperationException("Could not find gui provider for field type " + entry.getType());
|
|
throw new UnsupportedOperationException("Could not find gui provider for field type " + entry.getType());
|
|
- }
|
|
|
|
- String fieldName = field.getName();
|
|
|
|
- listeners.removeIf(listener -> {
|
|
|
|
- if (!listener.getFieldName().equals(fieldName)) {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- addListenerToEntry(entry, listener.getMethod(), listener.getParentObject());
|
|
|
|
- return true;
|
|
|
|
- });
|
|
|
|
- clazzEntries.put(fieldName, entry);
|
|
|
|
|
|
+ }*/
|
|
|
|
+ clazzEntries.put(field.getName(), entry);
|
|
});
|
|
});
|
|
- if (!listeners.isEmpty()) {
|
|
|
|
|
|
+ /*if (!listeners.isEmpty()) {
|
|
Listener listener = listeners.iterator().next();
|
|
Listener listener = listeners.iterator().next();
|
|
throw new IllegalAnnotationParameterException("Could not find field " + listener.getFieldName() + " in " + clazz + " requested by listener method " + listener.getMethod());
|
|
throw new IllegalAnnotationParameterException("Could not find field " + listener.getFieldName() + " in " + clazz + " requested by listener method " + listener.getMethod());
|
|
- }
|
|
|
|
|
|
+ }*/
|
|
//TODO: Quite hacky solution to sort the entries (superclasses first)
|
|
//TODO: Quite hacky solution to sort the entries (superclasses first)
|
|
clazzEntries.putAll(containerEntries);
|
|
clazzEntries.putAll(containerEntries);
|
|
containerEntries = clazzEntries;
|
|
containerEntries = clazzEntries;
|