Skip to content

Commit d04faf6

Browse files
authored
Refactor/refactor (#220)
2 parents 89958bc + 824ad36 commit d04faf6

File tree

60 files changed

+3741
-880
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+3741
-880
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled
77
javaVersion=25
88
mcVersion=1.21.11
99
group=dev.slne.surf
10-
version=1.21.11-2.58.0
10+
version=1.21.11-2.59.0
1111
relocationPrefix=dev.slne.surf.surfapi.libs
1212
snapshot=false

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ gson = "2.13.2"
4545
commons-lang3 = "3.20.0"
4646
commons-text = "1.15.0"
4747
commons-math4-core = "4.0-beta1"
48+
commons-math3 = "3.6.1"
4849
plugin-yml-paper = "0.8.0"
4950
spongepowered-math = "2.0.1"
5051
fastutil = "8.5.18"
@@ -139,6 +140,7 @@ gson = { module = "com.google.code.gson:gson", version.ref = "gson" }
139140
commons-lang3 = { module = "org.apache.commons:commons-lang3", version.ref = "commons-lang3" }
140141
commons-text = { module = "org.apache.commons:commons-text", version.ref = "commons-text" }
141142
commons-math4-core = { module = "org.apache.commons:commons-math4-core", version.ref = "commons-math4-core" }
143+
commons-math3 = { module = "org.apache.commons:commons-math3", version.ref = "commons-math3" }
142144
spongepowered-math = { module = "org.spongepowered:math", version.ref = "spongepowered-math" }
143145
fastutil = { module = "it.unimi.dsi:fastutil", version.ref = "fastutil" }
144146
okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" }

surf-api-bukkit/surf-api-bukkit-server/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ dependencies {
4444
paperLibrary(libs.flogger)
4545
paperLibrary(libs.flogger.slf4j.backend)
4646
paperLibrary(libs.commons.math4.core)
47+
paperLibrary(libs.commons.math3)
4748
paperLibrary(libs.aide.reflection)
4849
api(libs.mccoroutine.folia.api)
4950
api(libs.mccoroutine.folia.core)

surf-api-core/surf-api-core-api/api/surf-api-core-api.api

Lines changed: 320 additions & 32 deletions
Large diffs are not rendered by default.

surf-api-core/surf-api-core-api/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ dependencies {
1919
api(libs.configurate.kotlin)
2020
compileOnlyApi(libs.flogger)
2121
compileOnlyApi(libs.commons.math4.core)
22+
compileOnlyApi(libs.commons.math3)
2223
compileOnlyApi(libs.aide.reflection)
2324
api(libs.glm)
2425

surf-api-core/surf-api-core-api/src/main/kotlin/dev/slne/surf/surfapi/core/api/SurfCoreApi.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ interface SurfCoreApi {
2121
*/
2222
fun getPlayer(playerUuid: UUID): Any?
2323

24-
companion object {
24+
companion object : SurfCoreApi by surfCoreApi {
2525

2626
/**
2727
* The instance of the SurfCoreApi.
2828
*/
2929
@JvmStatic
30-
val instance = requiredService<SurfCoreApi>()
30+
val instance = surfCoreApi
3131
}
3232
}
3333

3434
/**
3535
* The instance of the SurfCoreApi.
3636
*/
37-
val surfCoreApi get() = SurfCoreApi.instance
37+
val surfCoreApi = requiredService<SurfCoreApi>()

surf-api-core/surf-api-core-api/src/main/kotlin/dev/slne/surf/surfapi/core/api/config/SurfConfigApi.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package dev.slne.surf.surfapi.core.api.config
22

3+
import dev.slne.surf.surfapi.core.api.config.manager.DazzlConfDeprecationMessageHolder
34
import dev.slne.surf.surfapi.core.api.config.manager.PreferUsingSpongeConfigOverDazzlConf
45
import dev.slne.surf.surfapi.core.api.config.manager.SpongeConfigManager
56
import dev.slne.surf.surfapi.core.api.util.requiredService
@@ -21,6 +22,7 @@ interface SurfConfigApi {
2122
* @return An instance of the configuration class [C].
2223
*/
2324
@PreferUsingSpongeConfigOverDazzlConf
25+
@Deprecated(message = DazzlConfDeprecationMessageHolder.MESSAGE, level = DeprecationLevel.ERROR)
2426
fun <C> createDazzlConfig(
2527
configClass: Class<C>,
2628
configFolder: Path,
@@ -35,6 +37,7 @@ interface SurfConfigApi {
3537
* @return An instance of the configuration class [C].
3638
*/
3739
@PreferUsingSpongeConfigOverDazzlConf
40+
@Deprecated(message = DazzlConfDeprecationMessageHolder.MESSAGE, level = DeprecationLevel.ERROR)
3841
fun <C> getDazzlConfig(configClass: Class<C>): C
3942

4043
/**
@@ -45,6 +48,7 @@ interface SurfConfigApi {
4548
* @return The reloaded instance of the configuration class [C].
4649
*/
4750
@PreferUsingSpongeConfigOverDazzlConf
51+
@Deprecated(message = DazzlConfDeprecationMessageHolder.MESSAGE, level = DeprecationLevel.ERROR)
4852
fun <C> reloadDazzlConfig(configClass: Class<C>): C
4953

5054
/**
@@ -134,18 +138,18 @@ interface SurfConfigApi {
134138
*/
135139
fun <C> getSpongeConfigManagerForConfig(configClass: Class<C>): SpongeConfigManager<C>
136140

137-
companion object {
141+
companion object: SurfConfigApi by surfConfigApi {
138142
/**
139143
* Retrieves the singleton instance of [SurfConfigApi].
140144
*/
141-
val instance = requiredService<SurfConfigApi>()
145+
val instance = surfConfigApi
142146
}
143147
}
144148

145149
/**
146150
* Retrieves the singleton instance of [SurfConfigApi].
147151
*/
148-
val surfConfigApi get() = SurfConfigApi.instance
152+
val surfConfigApi = requiredService<SurfConfigApi>()
149153

150154
/**
151155
* Creates a DazzlConf configuration using a reified type.
@@ -156,6 +160,8 @@ val surfConfigApi get() = SurfConfigApi.instance
156160
* @return An instance of the configuration class [C].
157161
*/
158162
@PreferUsingSpongeConfigOverDazzlConf
163+
@Deprecated(message = DazzlConfDeprecationMessageHolder.MESSAGE, level = DeprecationLevel.ERROR)
164+
@Suppress("DEPRECATION_ERROR")
159165
inline fun <reified C> SurfConfigApi.createDazzlConfig(
160166
configFolder: Path,
161167
configFileName: @YamlConfigFileNamePattern String,
@@ -168,6 +174,8 @@ inline fun <reified C> SurfConfigApi.createDazzlConfig(
168174
* @return An instance of the configuration class [C].
169175
*/
170176
@PreferUsingSpongeConfigOverDazzlConf
177+
@Deprecated(message = DazzlConfDeprecationMessageHolder.MESSAGE, level = DeprecationLevel.ERROR)
178+
@Suppress("DEPRECATION_ERROR")
171179
inline fun <reified C> SurfConfigApi.getDazzlConfig() = getDazzlConfig(C::class.java)
172180

173181
/**
@@ -177,6 +185,8 @@ inline fun <reified C> SurfConfigApi.getDazzlConfig() = getDazzlConfig(C::class.
177185
* @return The reloaded instance of the configuration class [C].
178186
*/
179187
@PreferUsingSpongeConfigOverDazzlConf
188+
@Deprecated(message = DazzlConfDeprecationMessageHolder.MESSAGE, level = DeprecationLevel.ERROR)
189+
@Suppress("DEPRECATION_ERROR")
180190
inline fun <reified C> SurfConfigApi.reloadDazzlConfig() = reloadDazzlConfig(C::class.java)
181191

182192
/**

surf-api-core/surf-api-core-api/src/main/kotlin/dev/slne/surf/surfapi/core/api/config/manager/DazzlConfConfigManager.kt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package dev.slne.surf.surfapi.core.api.config.manager
33
import dev.slne.surf.surfapi.core.api.config.YamlConfigFileNamePattern
44
import dev.slne.surf.surfapi.core.api.config.serializer.DefaultDazzlConfSerializers
55
import dev.slne.surf.surfapi.core.api.util.logger
6+
import dev.slne.surf.surfapi.shared.api.util.InternalSurfApi
67
import space.arim.dazzleconf.ConfigurationOptions
78
import space.arim.dazzleconf.error.ConfigFormatSyntaxException
89
import space.arim.dazzleconf.error.InvalidConfigException
@@ -16,12 +17,19 @@ import java.nio.file.Path
1617
import java.util.concurrent.TimeUnit
1718

1819
@RequiresOptIn(
19-
level = RequiresOptIn.Level.WARNING,
20-
message = "Prefer using Sponge's Configurate library over DazzlConf"
20+
level = RequiresOptIn.Level.ERROR,
21+
message = DazzlConfDeprecationMessageHolder.MESSAGE
2122
)
2223
@Retention(AnnotationRetention.BINARY)
2324
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
24-
annotation class PreferUsingSpongeConfigOverDazzlConf
25+
annotation class PreferUsingSpongeConfigOverDazzlConf {
26+
}
27+
28+
@InternalSurfApi
29+
object DazzlConfDeprecationMessageHolder {
30+
const val MESSAGE =
31+
"Prefer using Sponge's Configurate library over DazzlConf. DazzlConf will be removed in a future release. If you need to use DazzlConf, please contact the developers to discuss your use case."
32+
}
2533

2634
/**
2735
* Manages configurations using the DazzlConf library, including loading, saving, and reloading configurations.
@@ -31,6 +39,7 @@ annotation class PreferUsingSpongeConfigOverDazzlConf
3139
* @property config The current configuration instance, or `null` if not yet loaded.
3240
*/
3341
@PreferUsingSpongeConfigOverDazzlConf
42+
@Deprecated(message = DazzlConfDeprecationMessageHolder.MESSAGE, level = DeprecationLevel.ERROR)
3443
class DazzlConfConfigManager<C> private constructor(private val helper: ConfigurationHelper<C>) {
3544
@Volatile
3645
var config: C? = null
@@ -102,6 +111,9 @@ class DazzlConfConfigManager<C> private constructor(private val helper: Configur
102111
* @return A new instance of [DazzlConfConfigManager].
103112
*/
104113
@JvmStatic
114+
@Deprecated(message = DazzlConfDeprecationMessageHolder.MESSAGE, level = DeprecationLevel.ERROR)
115+
@PreferUsingSpongeConfigOverDazzlConf
116+
@Suppress("DEPRECATION_ERROR")
105117
fun <C> create(
106118
configClass: Class<C>,
107119
configFolder: Path,

surf-api-core/surf-api-core-api/src/main/kotlin/dev/slne/surf/surfapi/core/api/config/manager/SpongeConfigManager.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import dev.slne.surf.surfapi.core.api.config.JsonConfigFileNamePattern
44
import dev.slne.surf.surfapi.core.api.config.YamlConfigFileNamePattern
55
import dev.slne.surf.surfapi.core.api.config.serializer.SpongeConfigSerializers
66
import dev.slne.surf.surfapi.core.api.util.logger
7-
import org.jetbrains.annotations.Contract
87
import org.spongepowered.configurate.ConfigurateException
98
import org.spongepowered.configurate.ConfigurationNode
109
import org.spongepowered.configurate.ScopedConfigurationNode
@@ -15,6 +14,7 @@ import org.spongepowered.configurate.serialize.SerializationException
1514
import org.spongepowered.configurate.yaml.NodeStyle
1615
import org.spongepowered.configurate.yaml.YamlConfigurationLoader
1716
import java.io.Serial
17+
import java.io.UncheckedIOException
1818
import java.nio.file.Path
1919

2020
/**
@@ -24,7 +24,7 @@ import java.nio.file.Path
2424
* @param C The type of the configuration class.
2525
* @property config The current configuration instance.
2626
*/
27-
class SpongeConfigManager<C> @Contract(pure = true) private constructor(
27+
class SpongeConfigManager<C> private constructor(
2828
private val configClass: Class<C>,
2929
@JvmField @field:Volatile var config: C,
3030
private val loader: ConfigurationLoader<out ConfigurationNode>,
@@ -34,8 +34,9 @@ class SpongeConfigManager<C> @Contract(pure = true) private constructor(
3434
/**
3535
* Saves the current configuration to the file.
3636
*
37-
* @throws RuntimeException if an I/O error or serialization error occurs.
37+
* @throws UncheckedIOException if an I/O error or serialization error occurs.
3838
*/
39+
@Throws(UncheckedIOException::class)
3940
fun save() {
4041
try {
4142
node.set(configClass, config)
@@ -44,15 +45,15 @@ class SpongeConfigManager<C> @Contract(pure = true) private constructor(
4445
log.atSevere()
4546
.withCause(e)
4647
.log("Failed to save config")
47-
throw RuntimeException(e)
48+
throw UncheckedIOException(e)
4849
}
4950
}
5051

5152
/**
5253
* Reloads the configuration from the file. If loading fails, the current configuration remains unchanged.
5354
*
5455
* @return The reloaded configuration instance.
55-
* @throws RuntimeException if a critical error occurs during reload.
56+
* @throws UncheckedIOException if an I/O error occurs during reload.
5657
*/
5758
fun reloadFromFile(): C {
5859
try {
@@ -74,7 +75,7 @@ class SpongeConfigManager<C> @Contract(pure = true) private constructor(
7475
log.atSevere()
7576
.withCause(e)
7677
.log("Failed to reload config")
77-
throw RuntimeException(e)
78+
throw UncheckedIOException(e)
7879
}
7980
}
8081

surf-api-core/surf-api-core-api/src/main/kotlin/dev/slne/surf/surfapi/core/api/config/serializer/DefaultDazzlConfSerializers.kt

Lines changed: 21 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
package dev.slne.surf.surfapi.core.api.config.serializer
22

33
import dev.slne.surf.surfapi.core.api.config.manager.PreferUsingSpongeConfigOverDazzlConf
4-
import dev.slne.surf.surfapi.core.api.messages.Colors
4+
import dev.slne.surf.surfapi.core.api.minimessage.SurfMiniMessageHolder
55
import net.kyori.adventure.text.Component
6-
import net.kyori.adventure.text.format.TextColor
76
import net.kyori.adventure.text.minimessage.MiniMessage
87
import net.kyori.adventure.text.minimessage.ParsingException
9-
import net.kyori.adventure.text.minimessage.tag.Tag
108
import space.arim.dazzleconf.serialiser.Decomposer
119
import space.arim.dazzleconf.serialiser.FlexibleType
1210
import space.arim.dazzleconf.serialiser.ValueSerialiser
11+
import java.util.concurrent.CopyOnWriteArrayList
1312

1413
/**
1514
* Default serializers for DazzlConf configuration files. Provides support for custom types such as Adventure [Component].
@@ -20,7 +19,11 @@ object DefaultDazzlConfSerializers {
2019
/**
2120
* The default list of serializers used in DazzlConf configurations.
2221
*/
23-
val DEFAULTS = mutableListOf<ValueSerialiser<*>>(ComponentSerializer())
22+
val DEFAULTS = CopyOnWriteArrayList<ValueSerialiser<*>>()
23+
24+
init {
25+
DEFAULTS.add(ComponentSerializer())
26+
}
2427

2528
/**
2629
* Serializer for [Component] objects in DazzlConf configurations.
@@ -29,7 +32,7 @@ object DefaultDazzlConfSerializers {
2932
override fun getTargetClass() = Component::class.java
3033
override fun deserialise(flexibleType: FlexibleType): Component {
3134
try {
32-
return miniMessage.deserialize(flexibleType.string)
35+
return SurfMiniMessageHolder.miniMessage().deserialize(flexibleType.string)
3336
} catch (e: ParsingException) {
3437
throw flexibleType.badValueExceptionBuilder()
3538
.message(
@@ -45,48 +48,24 @@ object DefaultDazzlConfSerializers {
4548
}
4649

4750
override fun serialise(value: Component, decomposer: Decomposer?) =
48-
miniMessage.serialize(value)
51+
SurfMiniMessageHolder.miniMessage().serialize(value)
4952

5053
companion object {
51-
private val builder = MiniMessage.builder()
52-
.editTags {
53-
val tags = mapOf(
54-
"primary" to Colors.PRIMARY,
55-
"secondary" to Colors.SECONDARY,
56-
"info" to Colors.INFO,
57-
"success" to Colors.SUCCESS,
58-
"warning" to Colors.WARNING,
59-
"error" to Colors.ERROR,
60-
"variable_key" to Colors.VARIABLE_KEY,
61-
"variable_value" to Colors.VARIABLE_VALUE,
62-
"spacer" to Colors.SPACER,
63-
"dark_spacer" to Colors.DARK_SPACER,
64-
"prefix_color" to Colors.PREFIX_COLOR
65-
)
66-
67-
tags.forEach { (tag, color) ->
68-
it.tag(tag) { _, _ -> colorTag(color) }
69-
}
70-
}
71-
7254
@JvmStatic
73-
var miniMessage: MiniMessage = builder.build()
74-
get() {
75-
if (modified) {
76-
field = builder.build()
77-
modified = false
78-
}
79-
80-
return field
81-
}
82-
private set
83-
private var modified = false
84-
85-
private fun colorTag(color: TextColor) = Tag.styling { it.color(color) }
55+
@Deprecated(
56+
message = "Configs now use the MiniMessage instance supplied by the SurfMiniMessageHolder",
57+
replaceWith = ReplaceWith(
58+
"SurfMiniMessageHolder.miniMessage()",
59+
"dev.slne.surf.surfapi.core.api.minimessage.SurfMiniMessageHolder"
60+
)
61+
)
62+
val miniMessage: MiniMessage = SurfMiniMessageHolder.miniMessage()
8663

64+
@Deprecated(
65+
message = "Cannot customize MiniMessage anymore. If you need custom tags, use your own MiniMessage instance instead and use a String in the config, then parse it manually (Consider caching the parsed value in a lazy value though).",
66+
level = DeprecationLevel.ERROR
67+
)
8768
fun customizeMiniMessage(modifier: (MiniMessage.Builder) -> Unit) {
88-
modifier(builder)
89-
modified = true
9069
}
9170
}
9271
}

0 commit comments

Comments
 (0)