CompleteConfig.java 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package me.lortseam.completeconfig;
  2. import lombok.AccessLevel;
  3. import lombok.NoArgsConstructor;
  4. import java.util.HashMap;
  5. import java.util.Objects;
  6. import java.util.Optional;
  7. /**
  8. * Starting class for using the CompleteConfig API.
  9. */
  10. @NoArgsConstructor(access = AccessLevel.PRIVATE)
  11. public final class CompleteConfig {
  12. private static final HashMap<String, ConfigManager> MANAGERS = new HashMap<>();
  13. /**
  14. * Registers a mod.
  15. * @param modID The ID of the mod
  16. * @return The {@link ConfigManager} for the newly registered mod
  17. */
  18. public static ConfigManager register(String modID) {
  19. Objects.requireNonNull(modID);
  20. if (MANAGERS.containsKey(modID)) {
  21. throw new IllegalArgumentException("A manager with this mod ID is already registered");
  22. }
  23. ConfigManager manager = new ConfigManager(modID);
  24. MANAGERS.put(modID, manager);
  25. return manager;
  26. }
  27. /**
  28. * Gets the {@link ConfigManager} for the specified mod if that mod was registered before.
  29. * @param modID The ID of the mod
  30. * @return The {@link ConfigManager} if one was found or else an empty result
  31. */
  32. public static Optional<ConfigManager> getManager(String modID) {
  33. return Optional.ofNullable(MANAGERS.get(modID));
  34. }
  35. }