Skip to content

Commit a4bff92

Browse files
authored
feat: comply with simplecoreapi 0.8.0 (#52)
1 parent ab03643 commit a4bff92

File tree

6 files changed

+65
-59
lines changed

6 files changed

+65
-59
lines changed

build.gradle.kts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ plugins {
1212
}
1313

1414
val env = project.rootProject.file(".env").let { file ->
15-
if(file.exists()) file.readLines().filter { it.isNotBlank() && !it.startsWith("#") && it.split("=").size == 2 }.associate { it.split("=")[0] to it.split("=")[1] } else emptyMap()
15+
if (file.exists()) file.readLines().filter { it.isNotBlank() && !it.startsWith("#") && it.split("=").size == 2 }.associate { it.split("=")[0] to it.split("=")[1] } else emptyMap()
1616
}.toMutableMap().apply { putAll(System.getenv()) }
1717

18-
val projectVersion = env["VERSION"] ?: "0.3.0-SNAPSHOT"
18+
val projectVersion = env["VERSION"] ?: "0.4.0-SNAPSHOT"
1919

2020
group = "xyz.theprogramsrc"
2121
version = projectVersion
@@ -26,18 +26,18 @@ repositories {
2626
mavenCentral()
2727

2828
maven("https://s01.oss.sonatype.org/content/groups/public/")
29+
maven("https://oss.sonatype.org/content/repositories/snapshots/")
30+
maven("https://oss.sonatype.org/content/repositories/releases/")
2931
maven("https://oss.sonatype.org/content/groups/public/")
3032
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
33+
maven("https://repo.papermc.io/repository/maven-public/")
3134
maven("https://repo.codemc.org/repository/maven-public/")
3235
maven("https://jitpack.io/")
3336
}
3437

3538
dependencies {
36-
compileOnly("xyz.theprogramsrc:simplecoreapi:0.6.2-SNAPSHOT")
37-
compileOnly("xyz.theprogramsrc:filesmodule:0.2.0-SNAPSHOT")
38-
39-
compileOnly("org.spigotmc:spigot-api:1.19.3-R0.1-SNAPSHOT")
40-
compileOnly("net.md-5:bungeecord-api:1.20-R0.1")
39+
compileOnly("xyz.theprogramsrc:simplecoreapi:0.8.0-SNAPSHOT")
40+
compileOnly("xyz.theprogramsrc:filesmodule:0.4.0-SNAPSHOT")
4141

4242
testImplementation("org.junit.jupiter:junit-jupiter:5.10.0")
4343
}
@@ -89,9 +89,7 @@ tasks {
8989
}
9090

9191
dokkaHtml {
92-
val dokkaFolder = file(project.buildDir.absolutePath + "/dokka")
93-
outputDirectory.set(dokkaFolder)
94-
92+
outputDirectory.set(layout.buildDirectory.dir("dokka/"))
9593
}
9694
}
9795

src/main/kotlin/xyz/theprogramsrc/translationsmodule/Main.kt

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/main/kotlin/xyz/theprogramsrc/translationsmodule/Translation.kt

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package xyz.theprogramsrc.translationsmodule
22

33
import xyz.theprogramsrc.filesmodule.config.YmlConfig
4-
import xyz.theprogramsrc.filesmodule.utils.folder
4+
import xyz.theprogramsrc.simplecoreapi.global.utils.extensions.folder
55
import java.io.File
66

77
/**
@@ -15,20 +15,20 @@ import java.io.File
1515
* @param autoRegister If the translation should be automatically registered. (Defaults to true) It is recommended to disable if you're going to initialize the same translation multiple times (for example inside a loop)
1616
*/
1717
data class Translation(
18-
val id: String,
19-
val defaultValue: String,
20-
val group: String = "common",
21-
val language: String = "en",
22-
val mainColor: String? = null,
23-
val colors: Array<String> = emptyArray(),
24-
val autoRegister: Boolean = true
18+
val id: String,
19+
val defaultValue: String,
20+
val group: String = "common",
21+
val language: String = "en",
22+
val mainColor: String? = null,
23+
val colors: Array<String> = emptyArray(),
24+
val autoRegister: Boolean = true
2525
) {
2626

27-
init {
28-
if(autoRegister) {
29-
TranslationManager.instance.registerTranslations(group, this)
30-
}
31-
}
27+
init {
28+
if (autoRegister) {
29+
TranslationManager.instance.registerTranslations(group, this)
30+
}
31+
}
3232

3333
/**
3434
* Translates this [Translation] to the current language.
@@ -38,28 +38,30 @@ data class Translation(
3838
* @return The translated string.
3939
*/
4040
fun translate(language: String? = null, placeholders: Map<String, String> = emptyMap(), colorize: Boolean = true): String {
41-
val file = YmlConfig(File(File("translations/${if(group.endsWith("/")) group else "$group/"}").folder(), (language ?: TranslationManager.getCurrentLanguage()) + ".lang")) // Get the file of the translation
41+
val file = YmlConfig(File(File("translations/${if (group.endsWith("/")) group else "$group/"}").folder(), (language
42+
?: TranslationManager.getCurrentLanguage()) + ".lang")) // Get the file of the translation
4243
val mainColor = this.mainColor ?: "" // Get the main color of the translation
4344
var translation = mainColor.plus(
44-
if(file.has(id)) { // If the translation exists
45-
file.getString(id) // Get the translation from the file
46-
} else { // If the translation doesn't exist
47-
defaultValue // Get the default value
48-
}
45+
if (file.has(id)) { // If the translation exists
46+
file.getString(id) // Get the translation from the file
47+
} else { // If the translation doesn't exist
48+
defaultValue // Get the default value
49+
}
4950
)
50-
for(i in colors.indices) { // For each color
51+
for (i in colors.indices) { // For each color
5152
try {
5253
val color = colors[i] // Get the color
5354
val string = Regex("\\*\\*(.+?)\\*\\*").findAll(translation).first().groupValues[1] // Get the string to replace
5455
translation = translation.replaceFirst("**$string**", "$color$string$mainColor") // Replace the first match with the colorized string
55-
}catch (_: Exception){} // Ignore errors
56+
} catch (_: Exception) {
57+
} // Ignore errors
5658
}
5759

5860
placeholders.forEach { (key, value) -> // For each placeholder
5961
translation = translation.replace("{$key}", value).replace("%$key%", value) // Replace the placeholder using %% and {}
6062
}
6163

62-
return if(colorize) { // Return the translated string
64+
return if (colorize) { // Return the translated string
6365
translation.replace("&", "§")
6466
} else {
6567
translation

src/main/kotlin/xyz/theprogramsrc/translationsmodule/TranslationManager.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package xyz.theprogramsrc.translationsmodule
22

33
import xyz.theprogramsrc.filesmodule.config.YmlConfig
4-
import xyz.theprogramsrc.filesmodule.utils.folder
4+
import xyz.theprogramsrc.simplecoreapi.global.utils.extensions.folder
55
import java.io.File
66

77
/**
@@ -47,7 +47,7 @@ class TranslationManager {
4747
fun registerTranslations(group: String = "common", translations: Collection<Translation>) {
4848
val translationsCache = this.translationsCache[group] ?: mutableListOf()
4949
translations.forEach { t ->
50-
if(translationsCache.find { it == t } == null) {
50+
if (translationsCache.find { it == t } == null) {
5151
translationsCache.add(t)
5252
}
5353
}
@@ -94,16 +94,16 @@ class TranslationManager {
9494
val cfg = YmlConfig(it)
9595
cfg.keys(true).forEach { id ->
9696
val t = translationsCache[groupFolder.name]?.find { t1 -> t1.id == id }
97-
if(t != null){
97+
if (t != null) {
9898
langCache[id] = t.translate(it.nameWithoutExtension)
9999
}
100100
}
101-
if(langCache.isNotEmpty()){
101+
if (langCache.isNotEmpty()) {
102102
cached[it.nameWithoutExtension] = langCache
103103
}
104104
}
105105

106-
if(cached.isNotEmpty()) {
106+
if (cached.isNotEmpty()) {
107107
cache[groupFolder.name] = cached
108108
}
109109
}
@@ -115,21 +115,21 @@ class TranslationManager {
115115
* @param lang The language of the translation. If null it'll count all the languages. Defaults to null
116116
*/
117117
fun countTranslations(group: String? = null, lang: String? = null): Int {
118-
return if(group == null){
118+
return if (group == null) {
119119
cache.values.sumOf {
120-
if(lang != null){
120+
if (lang != null) {
121121
it[lang]?.size ?: 0
122-
}else {
122+
} else {
123123
it.values.sumOf { it2 ->
124124
it2.values.size
125125
}
126126
}
127127
}
128128
} else {
129129
val c = (this.cache[group] ?: return -2)
130-
if(lang != null){
130+
if (lang != null) {
131131
c[lang]?.size ?: 0
132-
}else {
132+
} else {
133133
c.values.sumOf { it2 ->
134134
it2.values.size
135135
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package xyz.theprogramsrc.translationsmodule
2+
3+
import xyz.theprogramsrc.simplecoreapi.global.models.module.Module
4+
import xyz.theprogramsrc.simplecoreapi.global.models.module.ModuleDescription
5+
6+
class Main : Module {
7+
override val description: ModuleDescription =
8+
ModuleDescription(
9+
name = "TranslationsModule",
10+
version = "@version@",
11+
authors = listOf("Im-Fran"),
12+
)
13+
14+
override fun onEnable() {
15+
TranslationManager()
16+
}
17+
18+
override fun onDisable() {
19+
20+
}
21+
22+
23+
}

src/main/resources/module.properties

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)