Skip to content

Commit 9a855c2

Browse files
authored
Merge pull request #23 from simplecloudapp/fix/directory-repository-resource-loading
fix: using correct resource directory for default config loading
2 parents 1473323 + 3be999a commit 9a855c2

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

plugin-shared/src/main/kotlin/app/simplecloud/plugin/api/shared/config/repository/DirectoryRepository.kt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import java.util.concurrent.ConcurrentHashMap
1212
import java.util.concurrent.atomic.AtomicReference
1313
import java.util.jar.JarFile
1414
import kotlin.coroutines.CoroutineContext
15+
import kotlin.io.path.pathString
1516

1617
/**
1718
* A directory repository that manages files of a specific type.
@@ -68,16 +69,19 @@ class DirectoryRepository<I : Any, T : Any> constructor(
6869

6970
private fun loadDefaultsFromResources(defaultEntities: Map<I, T>) {
7071
if (directory.toFile().list()?.isEmpty() == true) {
71-
val resourceUrl = DirectoryRepository::class.java.getResource("/defaults/") ?: run {
72-
println("Resource folder '/defaults/' not found.")
72+
73+
val last = directory.pathString.split('/').last()
74+
75+
val resourceUrl = DirectoryRepository::class.java.getResource("/$last") ?: run {
76+
logger.warn("Resource folder '/$last' not found.")
7377
return
7478
}
7579

7680
when (resourceUrl.protocol) {
7781
"file" -> handleFileProtocol(resourceUrl, directory.toFile())
7882
"jar" -> handleJarProtocol(resourceUrl, directory.toFile())
7983

80-
else -> println("Unsupported protocol: ${resourceUrl.protocol}")
84+
else -> logger.warn("Unsupported protocol: ${resourceUrl.protocol}")
8185
}
8286

8387
defaultEntities.forEach { (id, entity) -> save(id, entity) }
@@ -90,7 +94,7 @@ class DirectoryRepository<I : Any, T : Any> constructor(
9094
if (resourceDir.exists()) {
9195
resourceDir.copyRecursively(targetDirectory, overwrite = true)
9296
} else {
93-
println("Resource directory does not exist: ${resourceUrl.path}")
97+
logger.warn("Resource directory does not exist: ${resourceUrl.path}")
9498
}
9599
}
96100

@@ -114,21 +118,20 @@ class DirectoryRepository<I : Any, T : Any> constructor(
114118
}
115119
}
116120
} catch (e: Exception) {
117-
println("Error copying file ${entry.name}: ${e.message}")
121+
logger.error("Error copying file ${entry.name}: ${e.message}")
118122
}
119123
}
120124
}
121125
} catch (e: Exception) {
122-
println("Error processing JAR file: ${e.message}")
126+
logger.error("Error processing JAR file: ${e.message}")
123127
e.printStackTrace()
124128
}
125129
}
126130

127-
private fun load() {
131+
private fun load() =
128132
Files.walk(directory)
129133
.filter { !it.toFile().isDirectory && it.toString().endsWith(fileHandler.fileExtension) }
130134
.forEach { loadFile(it.toFile()) }
131-
}
132135

133136
private fun loadFile(file: File) {
134137
try {

0 commit comments

Comments
 (0)