@@ -47,23 +47,26 @@ internal class ScriptManager(val plugin: Kite) {
4747 fun isScriptLoaded (name : String ): Boolean = loadedScripts.containsKey(name)
4848
4949 // Collects all available script files to a list and returns it.
50- fun gatherAvailableScriptFiles (): List <ScriptHolder > {
51- // Creating 'plugins/Kite/scripts/' directory in case it doesn't exist.
52- if (! scriptsFolder.exists())
53- scriptsFolder.mkdirs()
54- // Otherwise, iterating over all files inside scripts directory.
55- else if (scriptsFolder.isDirectory) {
56- return scriptsFolder.listFiles()
57- .mapNotNull { ScriptHolder .fromName(it.nameWithoutExtensions, scriptsFolder) }
58- .distinctBy { it.name }
59- .toList()
50+ fun gatherAvailableScriptFiles (logDuplicates : Boolean = false): List <ScriptHolder > {
51+ // Creating scripts directory in case it does not exist.
52+ scriptsFolder.mkdirs()
53+ // Otherwise, iterating over all files inside scripts directory and gathering them to a list.
54+ // If logDuplicates is set to true, conflicting scripts are logged to the console.
55+ if (scriptsFolder.isDirectory) {
56+ val allScripts = scriptsFolder.listFiles().toList().mapNotNull { ScriptHolder .fromName(it.nameWithoutExtensions, scriptsFolder) }
57+ if (logDuplicates) {
58+ allScripts.groupBy { it.name }.values.filter { it.size > 1 }.flatten().drop(1 ).forEach {
59+ logger.errorRich(" Conflicting script <yellow>${it.entryPoint.toRelativeString(scriptsFolder)} </yellow> will not be loaded. Other script named <yellow>${it.name} </yellow> has taken priority and will be loaded instead." )
60+ }
6061 }
62+ return allScripts.distinctBy { it.name }.sortedBy { it.name }
63+ }
6164 return emptyList()
6265 }
6366
6467 // Compiles and loads all available scripts.
6568 fun loadAll () {
66- val scriptHolders = gatherAvailableScriptFiles()
69+ val scriptHolders = gatherAvailableScriptFiles(true )
6770 logger.infoRich(" Compiling <yellow>${scriptHolders.size} <reset>script(s)..." )
6871 // Compiling all available scripts in parallel.
6972 val compiledScripts = runBlocking {
0 commit comments