Skip to content

Commit 83a3a93

Browse files
committed
Adjust the project framework.
1 parent d22743d commit 83a3a93

File tree

21 files changed

+157
-101
lines changed

21 files changed

+157
-101
lines changed

build.gradle.kts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ plugins {
33
id("org.jetbrains.dokka") version "1.4.10.2" apply false
44
id("org.jlleitschuh.gradle.ktlint") version "9.4.1" apply false
55
id("com.github.johnrengelman.shadow") version "6.1.0" apply false
6+
id("net.kyori.blossom") version "1.1.0" apply false
67
id("maven")
78
id("maven-publish")
89
}
@@ -11,7 +12,7 @@ group = "me.scoretwo"
1112
version = "1.0.1-SNAPSHOT"
1213
description = "FastScript is a Spigot plugin, which can run JavaScript-based scripts more efficiently."
1314

14-
defaultTasks = mutableListOf("shadowJar")
15+
defaultTasks = mutableListOf("publishToMavenLocal")
1516

1617
subprojects {
1718
group = rootProject.group
@@ -22,6 +23,8 @@ subprojects {
2223
jcenter()
2324
mavenCentral()
2425
mavenLocal()
26+
maven("https://repo.lucko.me/")
27+
maven("http://repo.iroselle.com/snapshots/")
2528
}
2629
}
2730

common/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@ plugins {
88
}
99

1010
repositories {
11-
maven("http://repo.iroselle.com/snapshots/")
1211
}
1312

1413
dependencies {
1514
implementation(project(":common"))
1615

1716
compileOnly("org.apache.commons:commons-lang3:3.10")
1817
compileOnly("com.google.code.gson:gson:2.8.6")
18+
compileOnly("org.slf4j:slf4j-log4j12:1.7.30")
1919
implementation("commons-io:commons-io:2.7")
2020
implementation("me.scoretwo:commons-syntaxes:2.0-SNAPSHOT")
21+
implementation("me.scoretwo:commons-command:2.0-SNAPSHOT")
2122
implementation("me.scoretwo:commons-bukkit-configuration:2.0-SNAPSHOT")
2223
}
2324

common/src/main/kotlin/me/scoretwo/fastscript/FastScript.kt

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,38 @@
11
package me.scoretwo.fastscript
22

3-
import me.scoretwo.fastscript.api.plugin.FastScriptMain
3+
import me.scoretwo.fastscript.api.plugin.FastScriptPlugin
44
import me.scoretwo.fastscript.script.ScriptManager
55
import me.scoretwo.fastscript.commands.CommandManager
66
import me.scoretwo.fastscript.config.SettingConfig
77
import me.scoretwo.fastscript.utils.Utils
88
import me.scoretwo.utils.bukkit.configuration.yaml.patchs.getLowerCaseNode
9+
import me.scoretwo.utils.command.GlobalSender
910
import java.io.File
1011
import java.io.IOException
1112
import java.io.InputStream
1213
import java.net.URL
1314

14-
class FastScript(main: FastScriptMain) {
15+
class FastScript(plugin: FastScriptPlugin) {
1516

16-
private val main: FastScriptMain = main
17+
private val plugin: FastScriptPlugin = plugin
1718

1819
val dataFolder: File
1920
val classLoader: ClassLoader
2021

2122
val scriptManager: ScriptManager
2223
val commandManager: CommandManager
2324

24-
fun hasPermission(sender: Any, string: String) = main.hasPermission(sender, string)
25-
fun setPlaceholder(player: Any, string: String) = main.setPlaceholder(player, string)
26-
fun sendMessage(sender: Any, string: String, colorIndex: Boolean) = main.sendMessage(sender, string, colorIndex)
27-
fun translateStringColors(string: String): String = main.translateStringColors(string)
25+
fun setPlaceholder(player: Any, string: String) = plugin.setPlaceholder(player, string)
26+
fun translateStringColors(string: String): String = plugin.translateStringColors(string)
2827

2928
init {
3029
instance = this
31-
console = main.console
30+
console = plugin.console
3231
printLogo()
3332
println("[FastScript | INIT] 正在初始化...")
3433

35-
dataFolder = main.getDataFolder()
36-
classLoader = main.getPluginClassLoader()
34+
dataFolder = plugin.getDataFolder()
35+
classLoader = plugin.getPluginClassLoader()
3736
scriptManager = ScriptManager()
3837
commandManager = CommandManager()
3938

@@ -72,7 +71,7 @@ class FastScript(main: FastScriptMain) {
7271
if (!dataFolder.exists()) {
7372
dataFolder.mkdirs()
7473
}
75-
main.onReload()
74+
plugin.onReload()
7675
initLanguageFiles()
7776
initInternalScripts()
7877
scriptManager.loadScripts()
@@ -109,13 +108,18 @@ class FastScript(main: FastScriptMain) {
109108

110109
companion object {
111110
lateinit var instance: FastScript
112-
var console = Any()
111+
var console = object : GlobalSender {
112+
override val name = "console"
113+
override fun hasPermission(name: String) = true
114+
override fun sendMessage(messages: Array<String>) = println(messages)
115+
override fun sendMessage(message: String) = println(message)
116+
}
113117

114-
fun setBootstrap(main: FastScriptMain) {
118+
fun setBootstrap(plugin: FastScriptPlugin) {
115119
/*if (initialized) {
116120
throw UnsupportedOperationException("Cannot redefine instance")
117121
}*/
118-
FastScript(main)
122+
FastScript(plugin)
119123
}
120124
/*
121125
@JvmStatic
@@ -187,31 +191,17 @@ class FastScript(main: FastScriptMain) {
187191

188192
enum class FormatHeader { INFO, WARN, ERROR, TIPS, HOOKED, DEBUG }
189193

190-
fun Any.hasPermission(string: String): Boolean {
191-
return FastScript.instance.hasPermission(this, string)
192-
}
193-
194-
195-
fun Any.sendMessage(formatHeader: FormatHeader, strings: Array<String>, colorIndex: Boolean = true) {
194+
fun GlobalSender.sendMessage(formatHeader: FormatHeader, strings: Array<String>, colorIndex: Boolean = true) {
196195
strings.forEach {
197196
this.sendMessage(formatHeader, it, colorIndex)
198197
}
199198
}
200199

201-
fun Any.sendMessage(formatHeader: FormatHeader, string: String, colorIndex: Boolean = true) {
202-
this.sendMessage(
203-
"${SettingConfig.instance.defaultLanguage.getString(SettingConfig.instance.defaultLanguage.getLowerCaseNode("format-header.${formatHeader.name.toLowerCase()}"))}${string}", colorIndex
204-
)
205-
}
206-
207-
fun Any.sendMessage(string: String, colorIndex: Boolean = true) {
208-
FastScript.instance.sendMessage(this, string, colorIndex)
209-
}
210-
211-
fun Any.sendMessage(strings: Array<String>, colorIndex: Boolean = true) {
212-
strings.forEach {
213-
this.sendMessage(it, colorIndex)
214-
}
200+
fun GlobalSender.sendMessage(formatHeader: FormatHeader, string: String, colorIndex: Boolean = true) {
201+
if (colorIndex)
202+
this.sendMessage("${SettingConfig.instance.defaultLanguage.getString(SettingConfig.instance.defaultLanguage.getLowerCaseNode("format-header.${formatHeader.name.toLowerCase()}"))}${string}")
203+
else
204+
this.sendMessage(FastScript.instance.translateStringColors("${SettingConfig.instance.defaultLanguage.getString(SettingConfig.instance.defaultLanguage.getLowerCaseNode("format-header.${formatHeader.name.toLowerCase()}"))}${string}"))
215205
}
216206

217207
fun String.setPlaceholder(sender: Any): String {

common/src/main/kotlin/me/scoretwo/fastscript/api/plugin/FastScriptMain.kt

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package me.scoretwo.fastscript.api.plugin
2+
3+
import me.scoretwo.fastscript.api.plugin.logging.ScriptLogger
4+
import me.scoretwo.utils.command.GlobalSender
5+
import java.io.File
6+
7+
interface FastScriptPlugin {
8+
9+
val console: GlobalSender
10+
val dataFolder: File
11+
val pluginClassLoader: ClassLoader
12+
val scriptLogger: ScriptLogger
13+
14+
fun setPlaceholder(player: Any, string: String): String
15+
fun translateStringColors(string: String): String
16+
17+
fun onReload()
18+
19+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package me.scoretwo.fastscript.api.plugin.logging
2+
3+
import java.util.logging.Level
4+
import java.util.logging.Logger
5+
6+
class JavaLogger(val logger: Logger): ScriptLogger {
7+
8+
override fun info(msg: String) = logger.info(msg)
9+
10+
override fun warn(msg: String) = logger.warning(msg)
11+
12+
override fun warn(msg: String, t: Throwable) = logger.log(Level.WARNING, msg, t)
13+
14+
override fun error(msg: String) = logger.log(Level.SEVERE, msg)
15+
16+
override fun error(msg: String, t: Throwable) = logger.log(Level.SEVERE, msg, t)
17+
18+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package me.scoretwo.fastscript.api.plugin.logging
2+
3+
interface ScriptLogger {
4+
5+
fun info(msg: String)
6+
7+
fun warn(msg: String)
8+
fun warn(msg: String, t: Throwable)
9+
10+
fun error(msg: String)
11+
fun error(msg: String, t: Throwable)
12+
13+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package me.scoretwo.fastscript.api.plugin.logging
2+
3+
import org.slf4j.Logger
4+
5+
class Slf4jLogger(val logger: Logger): ScriptLogger {
6+
7+
override fun info(msg: String) = logger.info(msg)
8+
9+
override fun warn(msg: String) = logger.warn(msg)
10+
11+
override fun warn(msg: String, t: Throwable) = logger.warn(msg, t)
12+
13+
override fun error(msg: String) = logger.error(msg)
14+
15+
override fun error(msg: String, t: Throwable) = logger.error(msg, t)
16+
17+
}

common/src/main/kotlin/me/scoretwo/fastscript/api/placeholder/Placeholders.kt renamed to common/src/main/kotlin/me/scoretwo/fastscript/placeholder/Placeholders.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package me.scoretwo.fastscript.api.placeholder
1+
package me.scoretwo.fastscript.placeholder
22

33
object Placeholders {
44

version-control/bukkit/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ repositories {
1414

1515
dependencies {
1616
implementation(project(":common"))
17-
17+
implementation("me.scoretwo:commons-bukkit-command:2.0-SNAPSHOT")
1818

1919
compileOnly("org.spigotmc:spigot-api:1.16.4-R0.1-SNAPSHOT")
2020
compileOnly("me.clip:placeholderapi:2.10.9")

0 commit comments

Comments
 (0)