@@ -5,66 +5,180 @@ import dev.slne.surf.surfapi.core.api.config.manager.SpongeConfigManager
55import dev.slne.surf.surfapi.core.api.util.requiredService
66import java.nio.file.Path
77
8+ /* *
9+ * API for managing configuration files in the Surf API, supporting both Sponge and DazzlConf configurations.
10+ * Provides methods to create, retrieve, and reload configuration files in various formats (YAML, JSON).
11+ */
812interface SurfConfigApi {
913
14+ /* *
15+ * Creates a DazzlConf configuration file.
16+ *
17+ * @param C The type of the configuration class.
18+ * @param configClass The class of the configuration.
19+ * @param configFolder The folder where the configuration file is stored.
20+ * @param configFileName The name of the configuration file. Must follow the YAML file name pattern.
21+ * @return An instance of the configuration class [C].
22+ */
1023 @PreferUsingSpongeConfigOverDazzlConf
1124 fun <C > createDazzlConfig (
1225 configClass : Class <C >,
1326 configFolder : Path ,
14- configFileName : @YamlConfigFileNamePattern String
27+ configFileName : @YamlConfigFileNamePattern String ,
1528 ): C
1629
30+ /* *
31+ * Retrieves a DazzlConf configuration.
32+ *
33+ * @param C The type of the configuration class.
34+ * @param configClass The class of the configuration.
35+ * @return An instance of the configuration class [C].
36+ */
1737 @PreferUsingSpongeConfigOverDazzlConf
1838 fun <C > getDazzlConfig (configClass : Class <C >): C
1939
40+ /* *
41+ * Reloads a DazzlConf configuration from the file.
42+ *
43+ * @param C The type of the configuration class.
44+ * @param configClass The class of the configuration.
45+ * @return The reloaded instance of the configuration class [C].
46+ */
2047 @PreferUsingSpongeConfigOverDazzlConf
2148 fun <C > reloadDazzlConfig (configClass : Class <C >): C
2249
50+ /* *
51+ * Creates a Sponge YAML configuration file.
52+ *
53+ * @param C The type of the configuration class.
54+ * @param configClass The class of the configuration.
55+ * @param configFolder The folder where the configuration file is stored.
56+ * @param configFileName The name of the configuration file. Must follow the YAML file name pattern.
57+ * @return An instance of the configuration class [C].
58+ */
2359 fun <C > createSpongeYmlConfig (
2460 configClass : Class <C >,
2561 configFolder : Path ,
26- configFileName : @YamlConfigFileNamePattern String
62+ configFileName : @YamlConfigFileNamePattern String ,
2763 ): C
2864
65+ /* *
66+ * Creates a Sponge JSON configuration file.
67+ *
68+ * @param C The type of the configuration class.
69+ * @param configClass The class of the configuration.
70+ * @param configFolder The folder where the configuration file is stored.
71+ * @param configFileName The name of the configuration file. Must follow the JSON file name pattern.
72+ * @return An instance of the configuration class [C].
73+ */
2974 fun <C > createSpongeJsonConfig (
3075 configClass : Class <C >,
3176 configFolder : Path ,
32- configFileName : @JsonConfigFileNamePattern String
77+ configFileName : @JsonConfigFileNamePattern String ,
3378 ): C
3479
80+ /* *
81+ * Retrieves a Sponge configuration.
82+ *
83+ * @param C The type of the configuration class.
84+ * @param configClass The class of the configuration.
85+ * @return An instance of the configuration class [C].
86+ */
3587 fun <C > getSpongeConfig (configClass : Class <C >): C
3688
89+ /* *
90+ * Reloads a Sponge configuration from the file.
91+ *
92+ * @param C The type of the configuration class.
93+ * @param configClass The class of the configuration.
94+ * @return The reloaded instance of the configuration class [C].
95+ */
3796 fun <C > reloadSpongeConfig (configClass : Class <C >): C
3897
98+ /* *
99+ * Retrieves the [SpongeConfigManager] for a specific configuration class.
100+ *
101+ * @param C The type of the configuration class.
102+ * @param configClass The class of the configuration.
103+ * @return An instance of [SpongeConfigManager] for the configuration class [C].
104+ */
39105 fun <C > getSpongeConfigManagerForConfig (configClass : Class <C >): SpongeConfigManager <C >
40106
41107 companion object {
108+ /* *
109+ * Retrieves the singleton instance of [SurfConfigApi].
110+ */
42111 val instance = requiredService<SurfConfigApi >()
43112 }
44113}
45114
115+ /* *
116+ * Retrieves the singleton instance of [SurfConfigApi].
117+ */
46118val surfConfigApi get() = SurfConfigApi .instance
47119
120+ /* *
121+ * Creates a DazzlConf configuration using a reified type.
122+ *
123+ * @param C The type of the configuration class.
124+ * @param configFolder The folder where the configuration file is stored.
125+ * @param configFileName The name of the configuration file. Must follow the YAML file name pattern.
126+ * @return An instance of the configuration class [C].
127+ */
48128@PreferUsingSpongeConfigOverDazzlConf
49129inline fun <reified C > SurfConfigApi.createDazzlConfig (
50130 configFolder : Path ,
51- configFileName : @YamlConfigFileNamePattern String
131+ configFileName : @YamlConfigFileNamePattern String ,
52132) = createDazzlConfig(C ::class .java, configFolder, configFileName)
53133
134+ /* *
135+ * Retrieves a DazzlConf configuration using a reified type.
136+ *
137+ * @param C The type of the configuration class.
138+ * @return An instance of the configuration class [C].
139+ */
54140@PreferUsingSpongeConfigOverDazzlConf
55141inline fun <reified C > SurfConfigApi.getDazzlConfig () = getDazzlConfig(C ::class .java)
56142
143+ /* *
144+ * Reloads a DazzlConf configuration using a reified type.
145+ *
146+ * @param C The type of the configuration class.
147+ * @return The reloaded instance of the configuration class [C].
148+ */
57149@PreferUsingSpongeConfigOverDazzlConf
58150inline fun <reified C > SurfConfigApi.reloadDazzlConfig () = reloadDazzlConfig(C ::class .java)
59151
152+ /* *
153+ * Creates a Sponge YAML configuration using a reified type.
154+ *
155+ * @param C The type of the configuration class.
156+ * @param configFolder The folder where the configuration file is stored.
157+ * @param configFileName The name of the configuration file. Must follow the YAML file name pattern.
158+ * @return An instance of the configuration class [C].
159+ */
60160inline fun <reified C > SurfConfigApi.createSpongeYmlConfig (
61161 configFolder : Path ,
62- configFileName : @YamlConfigFileNamePattern String
162+ configFileName : @YamlConfigFileNamePattern String ,
63163) = createSpongeYmlConfig(C ::class .java, configFolder, configFileName)
64164
165+ /* *
166+ * Creates a Sponge JSON configuration using a reified type.
167+ *
168+ * @param C The type of the configuration class.
169+ * @param configFolder The folder where the configuration file is stored.
170+ * @param configFileName The name of the configuration file. Must follow the JSON file name pattern.
171+ * @return An instance of the configuration class [C].
172+ */
65173inline fun <reified C > SurfConfigApi.createSpongeJsonConfig (
66174 configFolder : Path ,
67- configFileName : @JsonConfigFileNamePattern String
175+ configFileName : @JsonConfigFileNamePattern String ,
68176) = createSpongeJsonConfig(C ::class .java, configFolder, configFileName)
69177
178+ /* *
179+ * Retrieves a Sponge configuration using a reified type.
180+ *
181+ * @param C The type of the configuration class.
182+ * @return An instance of the configuration class [C].
183+ */
70184inline fun <reified C > SurfConfigApi.getSpongeConfig () = getSpongeConfig(C ::class .java)
0 commit comments