Selaa lähdekoodia

Finished javadoc + minor optimizations

Lortseam 4 vuotta sitten
vanhempi
sitoutus
a21dc60acd

+ 5 - 2
src/main/java/me/lortseam/completeconfig/CompleteConfig.java

@@ -7,13 +7,16 @@ import java.util.HashMap;
 import java.util.Objects;
 import java.util.Optional;
 
+/**
+ * Starting class for using the CompleteConfig API.
+ */
 @NoArgsConstructor(access = AccessLevel.PRIVATE)
 public final class CompleteConfig {
 
     private static final HashMap<String, ConfigManager> MANAGERS = new HashMap<>();
 
     /**
-     * Registers a mod
+     * Registers a mod.
      * @param modID The ID of the mod
      * @return The {@link ConfigManager} for the newly registered mod
      */
@@ -28,7 +31,7 @@ public final class CompleteConfig {
     }
 
     /**
-     * Gets the {@link ConfigManager} for the specified mod if that mod was registered before
+     * Gets the {@link ConfigManager} for the specified mod if that mod was registered before.
      * @param modID The ID of the mod
      * @return The {@link ConfigManager} if one was found or else an empty result
      */

+ 6 - 0
src/main/java/me/lortseam/completeconfig/ConfigManager.java

@@ -18,6 +18,9 @@ import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.function.Supplier;
 
+/**
+ * Main interaction class for using the CompleteConfig API. References a single mod.
+ */
 public final class ConfigManager {
 
     private static final Gson GSON = new GsonBuilder()
@@ -95,6 +98,9 @@ public final class ConfigManager {
         return buildScreen(parentScreen);
     }
 
+    /**
+     * Saves the config to a save file.
+     */
     public void save() {
         if (!Files.exists(jsonPath)) {
             try {

+ 13 - 0
src/main/java/me/lortseam/completeconfig/api/ConfigEntryContainer.java

@@ -14,6 +14,13 @@ import java.util.List;
  */
 public interface ConfigEntryContainer {
 
+    /**
+     * Used to register other containers. They will be located on the same level.
+     *
+     * @return an array of other containers
+     *
+     * @see Transitive
+     */
     default ConfigEntryContainer[] getTransitiveConfigEntryContainers() {
         return new ConfigEntryContainer[0];
     }
@@ -22,6 +29,12 @@ public interface ConfigEntryContainer {
         return false;
     }
 
+    /**
+     * Applied to declare that a field of type {@link ConfigEntryContainer} is transitive. The container will be
+     * registered on the same level.
+     *
+     * @see #getTransitiveConfigEntryContainers()
+     */
     @Target(ElementType.FIELD)
     @Retention(RetentionPolicy.RUNTIME)
     @interface Transitive {

+ 1 - 0
src/main/java/me/lortseam/completeconfig/gui/GuiProvider.java

@@ -11,6 +11,7 @@ import java.util.function.Consumer;
 @FunctionalInterface
 public interface GuiProvider<T> {
 
+    //TODO: Optional should not be used for an argument
     AbstractConfigListEntry<T> build(Text text, Field field, T value, T defaultValue, Optional<Text[]> tooltip, Extras<T> extras, Consumer<T> saveConsumer, boolean requiresRestart);
 
 }

+ 2 - 1
src/main/java/me/lortseam/completeconfig/gui/Registration.java → src/main/java/me/lortseam/completeconfig/gui/GuiProviderRegistration.java

@@ -8,7 +8,8 @@ import me.lortseam.completeconfig.entry.Entry;
 import java.util.function.Predicate;
 
 @RequiredArgsConstructor(access = AccessLevel.PACKAGE)
-class Registration<T> implements Predicate<Entry<?>> {
+//TODO: Functional interfaces should not get extended
+class GuiProviderRegistration<T> implements Predicate<Entry<?>> {
 
     private final GuiProviderPredicate<T> predicate;
     @Getter(AccessLevel.PACKAGE)

+ 4 - 3
src/main/java/me/lortseam/completeconfig/gui/GuiRegistry.java

@@ -21,20 +21,21 @@ import java.util.function.Function;
 
 public class GuiRegistry {
 
+    //TODO: Only used for setting requireRestart cause that method returns void, should be done differently
     public static <T, A extends AbstractConfigListEntry> A build(Consumer<FieldBuilder<T, A>> fieldBuilderModifier, Function<ConfigEntryBuilder, FieldBuilder<T, A>> builder) {
         FieldBuilder<T, A> fieldBuilder = builder.apply(ConfigEntryBuilder.create());
         fieldBuilderModifier.accept(fieldBuilder);
         return fieldBuilder.build();
     }
 
-    private final List<Registration> registrations = new ArrayList<>();
+    private final List<GuiProviderRegistration> registrations = new ArrayList<>();
 
     GuiRegistry() {
         registerDefaultProviders();
     }
 
     public <T> void registerProvider(GuiProvider<T> provider, GuiProviderPredicate<T> predicate, Class... types) {
-        registrations.add(new Registration<>(predicate.and((field, extras) -> {
+        registrations.add(new GuiProviderRegistration<>(predicate.and((field, extras) -> {
             if (types.length == 0) {
                 return true;
             }
@@ -240,7 +241,7 @@ public class GuiRegistry {
     }
 
     <T> Optional<GuiProvider<T>> getProvider(Entry<T> entry) {
-        for (Registration<?> registration : Lists.reverse(registrations)) {
+        for (GuiProviderRegistration<?> registration : Lists.reverse(registrations)) {
             if (registration.test(entry)) {
                 return Optional.of((GuiProvider<T>) registration.getProvider());
             }