diff --git a/README.md b/README.md
index 21128f6..370ee9d 100644
--- a/README.md
+++ b/README.md
@@ -1,65 +1 @@
-
-[
](https://discord.gg/GVM6vx9)
-[
](https://github.com/Score2/FastScript/issues)
-[
](https://github.com/Score2/FastScript/pulls)
-[
](https://github.com/Score2/FastScript/blob/master/LICENSE)
-[
](https://github.com/Score2/FastScript/commits/master)
-[
](https://bstats.org/plugin/bukkit/FastScript/9014)
-> Because the structure of the project is too confusing, the project will stop updating until major errors are discovered. Reset the project when [Insinuate](https://github.com/InsinuateProjects/Insinuate) completes development and testing.
-***
-### About
-Support multiple scripting languages, use scripts to change Minecraft!
-
->At present, the project is still unfinished and cannot be used.
-***
-### Build
-In the project root directory:
-```
-./gradle shadowJar
- or
-./gradle
-```
-***
-### Developer
-> Maven usage
-```
-
-
- roselle-repo
- http://repo.iroselle.com/snapshots/
-
-
-
-
-
- me.scoretwo
- FastScript
- 1.0.1-SNAPSHOT
- provided
-
-
-```
-> Gradle
-```
-repositories {
- maven {url 'http://repo.iroselle.com/snapshots/'}
-}
-dependencies {
- implementation 'me.scoretwo:FastScript:1.0.1-SNAPSHOT'
-}
-```
-> Gradle Kotlin DSL
-```
-repositories {
- maven("http://repo.iroselle.com/snapshots/")
-}
-dependencies {
- implementation("me.scoretwo:FastScript-common:1.0.1-SNAPSHOT")
-}
-```
-
-### Links
-
-[
](https://github.com/Score2/FastScript)
-[
](https://github.com/Score2/FastScript/wiki)
-[
](https://discord.gg/GVM6vx9)
+### FastScript v2
\ No newline at end of file
diff --git a/build.gradle.kts b/build.gradle.kts
index 5fb17df..6f712dc 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -1,166 +1,14 @@
plugins {
- kotlin("jvm") version "1.5.0"
- id("org.jetbrains.dokka") version "1.4.10.2"
- id("org.jlleitschuh.gradle.ktlint") version "9.4.1"
- id("com.github.johnrengelman.shadow") version "6.1.0"
- id("maven")
- id("maven-publish")
+ kotlin("jvm") version "1.5.20"
}
-group = "me.scoretwo"
-version = "1.1.5-SNAPSHOT"
-description = "FastScript is a Spigot plugin, which can run JavaScript-based scripts more efficiently."
+group = "io.insinuate"
+version = "2.0.0"
-defaultTasks = mutableListOf("ShadowJar", "publishToMavenLocal")
-
-extra.apply {
- set("commonsVersion", "2.0.15-SNAPSHOT")
- set("kotlinVersion", "1.5.0")
-}
-
-allprojects {
- repositories {
- jcenter()
- mavenCentral()
- mavenLocal()
- maven("http://mc3.roselle.vip:609/repository/maven-snapshots/")
- maven("http://mc3.roselle.vip:609/repository/maven-public/")
- maven("https://maven.aliyun.com/nexus/content/groups/public/")
- maven("https://nexus.velocitypowered.com/repository/velocity-artifacts-snapshots/")
- maven("https://repo.spongepowered.org/maven")
- maven("https://jitpack.io")
- maven("https://hub.spigotmc.org/nexus/content/repositories/sonatype-nexus-snapshots/")
- maven("https://repo.codemc.io/repository/maven-snapshots/")
- maven("https://repo.codemc.io/repository/maven-public/")
- maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
- maven("https://repo.opencollab.dev/maven-snapshots/")
- }
-
- group = rootProject.group
- version = rootProject.version
- description = rootProject.description
-
- tasks.withType {
- kotlinOptions.jvmTarget = "1.8"
- }
+repositories {
+ mavenCentral()
}
dependencies {
- implementation(project(":FastScript-common"))
- implementation(project(":version-control:FastScript-bukkit"))
- implementation(project(":version-control:FastScript-bungee"))
- implementation(project(":version-control:FastScript-sponge"))
- implementation(project(":version-control:FastScript-velocity"))
- implementation(project(":version-control:FastScript-nukkit"))
-
- implementation("me.scoretwo:commons-sponge-plugin:${rootProject.extra.get("commonsVersion")}")
- implementation("me.scoretwo:commons-bungee-plugin:${rootProject.extra.get("commonsVersion")}")
- implementation("me.scoretwo:commons-bukkit-plugin:${rootProject.extra.get("commonsVersion")}")
- implementation("me.scoretwo:commons-velocity-plugin:${rootProject.extra.get("commonsVersion")}")
- implementation("me.scoretwo:commons-nukkit-plugin:${rootProject.extra.get("commonsVersion")}")
-
- implementation("org.bstats:bstats-bukkit:1.8")
- implementation("com.iroselle:cstats-bukkit:1.7")
- implementation("org.bstats:bstats-bungeecord:1.8")
- implementation("com.iroselle:cstats-bungeecord:1.7")
- implementation("commons-io:commons-io:2.8.0")
- implementation("commons-lang:commons-lang:2.6")
- implementation("net.md-5:bungeecord-chat:1.16-R0.5-SNAPSHOT")
-
- implementation("me.scoretwo:commons-syntaxes:${rootProject.extra.get("commonsVersion")}")
- implementation("me.scoretwo:commons-server:${rootProject.extra.get("commonsVersion")}")
- implementation("me.scoretwo:commons-bukkit-configuration:${rootProject.extra.get("commonsVersion")}")
+ implementation(kotlin("stdlib"))
}
-
-
-tasks.withType {
- dependencies {
- include(dependency("org.jetbrains.kotlin:kotlin-stdlib"))
-
- include(dependency(":FastScript-common"))
- include(dependency(":FastScript-bukkit"))
- include(dependency(":FastScript-bungee"))
- include(dependency(":FastScript-sponge"))
- include(dependency(":FastScript-velocity"))
- include(dependency(":FastScript-nukkit"))
-
- include(dependency("me.scoretwo:commons-velocity-plugin:${rootProject.extra.get("commonsVersion")}"))
- include(dependency("me.scoretwo:commons-sponge-plugin:${rootProject.extra.get("commonsVersion")}"))
- include(dependency("me.scoretwo:commons-bungee-plugin:${rootProject.extra.get("commonsVersion")}"))
- include(dependency("me.scoretwo:commons-bukkit-plugin:${rootProject.extra.get("commonsVersion")}"))
- include(dependency("me.scoretwo:commons-nukkit-plugin:${rootProject.extra.get("commonsVersion")}"))
-
- include(dependency("org.bstats:bstats-bukkit:1.8"))
- include(dependency("com.iroselle:cstats-bukkit:1.7"))
- include(dependency("org.bstats:bstats-bungeecord:1.8"))
- include(dependency("com.iroselle:cstats-bungeecord:1.7"))
-
- include(dependency("net.md-5:bungeecord-chat:1.16-R0.5-SNAPSHOT"))
- include(dependency("commons-io:commons-io:2.8.0"))
- include(dependency("commons-lang:commons-lang:2.6"))
-
- include(dependency("me.scoretwo:commons-syntaxes:${rootProject.extra.get("commonsVersion")}"))
- include(dependency("me.scoretwo:commons-server:${rootProject.extra.get("commonsVersion")}"))
- include(dependency("me.scoretwo:commons-bukkit-configuration:${rootProject.extra.get("commonsVersion")}"))
- }
- relocate("kotlin", "me.scoretwo.utils.shaded.kotlin")
- relocate("org.apache","me.scoretwo.utils.shaded.org.apache")
- relocate("org.bstats","me.scoretwo.utils.shaded.org.bstats")
- relocate("com.iroselle.cstats","me.scoretwo.utils.shaded.com.iroselle.cstats")
-
- exclude("META-INF/versions/9/module-info.class")
- exclude("META-INF/*.kotlin_module")
- exclude("mojang-translations/*.*")
-
- classifier = null
-}
-
-tasks.processResources {
- from("src/main/resources") {
- include("plugin.yml")
- expand(mapOf(
- "name" to rootProject.name,
- "main" to "${rootProject.group}.${rootProject.name.toLowerCase()}.bukkit.BukkitBootStrap",
- "version" to rootProject.version,
- "description" to rootProject.description
- ))
- }
- from("src/main/resources") {
- include("bungee.yml")
- expand(mapOf(
- "name" to rootProject.name,
- "main" to "${rootProject.group}.${rootProject.name.toLowerCase()}.bungee.BungeeBootStrap",
- "version" to project.version,
- "description" to project.description
- ))
- }
- from("src/main/resources") {
- include("mcmod.info")
- expand(mapOf(
- "id" to rootProject.name.toLowerCase(),
- "name" to rootProject.name,
- "version" to project.version,
- "description" to project.description
- ))
- }
- from("src/main/resources") {
- include("velocity-plugin.json")
- expand(mapOf(
- "id" to rootProject.name.toLowerCase(),
- "name" to rootProject.name,
- "version" to project.version,
- "main" to "${rootProject.group}.${rootProject.name.toLowerCase()}.velocity.VelocityBootStrap",
- "description" to project.description
- ))
- }
- from("src/main/resources") {
- include("nukkit.yml")
- expand(mapOf(
- "id" to rootProject.name.toLowerCase(),
- "name" to rootProject.name,
- "version" to project.version,
- "main" to "${rootProject.group}.${rootProject.name.toLowerCase()}.nukkit.NukkitBootStrap",
- "description" to project.description
- ))
- }
-}
\ No newline at end of file
diff --git a/common/build.gradle.kts b/common/build.gradle.kts
deleted file mode 100644
index eae958a..0000000
--- a/common/build.gradle.kts
+++ /dev/null
@@ -1,50 +0,0 @@
-plugins {
- kotlin("jvm")
- id("org.jetbrains.dokka")
- id("org.jlleitschuh.gradle.ktlint")
- id("com.github.johnrengelman.shadow")
- id("maven")
- id("maven-publish")
-}
-
-dependencies {
- compileOnly("com.google.code.gson:gson:2.8.6")
- compileOnly("org.slf4j:slf4j-log4j12:1.7.30")
- compileOnly("net.md-5:bungeecord-chat:1.16-R0.5-SNAPSHOT")
-
- compileOnly("org.openjdk.nashorn:nashorn-core:15.2")
- compileOnly("org.scala-lang:scala-compiler:2.12.9")
- compileOnly("commons-lang:commons-lang:2.6")
- compileOnly("commons-io:commons-io:2.8.0")
- compileOnly("me.scoretwo:commons-bukkit-configuration:${rootProject.extra.get("commonsVersion")}")
- compileOnly("org.jetbrains.kotlin:kotlin-script-util:${rootProject.extra.get("kotlinVersion")}")
- compileOnly("org.jetbrains.kotlin:kotlin-compiler:${rootProject.extra.get("kotlinVersion")}")
- implementation("me.scoretwo:commons-syntaxes:${rootProject.extra.get("commonsVersion")}")
- implementation("me.scoretwo:commons-server:${rootProject.extra.get("commonsVersion")}")
-}
-
-tasks.withType {
- dependencies {
- exclude(dependency("org.jetbrains.kotlin:kotlin-stdlib"))
- exclude(dependency("org.jetbrains.kotlin:kotlin-stdlib-common"))
-
- exclude(dependency("commons-io:commons-io:2.8.0"))
- exclude(dependency("commons-lang:commons-lang:2.6"))
-
- exclude(dependency("me.scoretwo:commons-bukkit-configuration:${rootProject.extra.get("commonsVersion")}"))
-
- include(dependency("me.scoretwo:commons-syntaxes:${rootProject.extra.get("commonsVersion")}"))
- include(dependency("me.scoretwo:commons-server:${rootProject.extra.get("commonsVersion")}"))
- }
- relocate("org.apache","me.scoretwo.utils.libs.org.apache")
-
- classifier = null
-}
-
-configure {
- publications {
- create("shadow") {
- shadow.component(this)
- }
- }
-}
\ No newline at end of file
diff --git a/common/src/main/kotlin/me/scoretwo/fastscript/FastScript.kt b/common/src/main/kotlin/me/scoretwo/fastscript/FastScript.kt
deleted file mode 100644
index a75a41b..0000000
--- a/common/src/main/kotlin/me/scoretwo/fastscript/FastScript.kt
+++ /dev/null
@@ -1,224 +0,0 @@
-package me.scoretwo.fastscript
-
-import me.scoretwo.fastscript.api.expansion.ExpansionManager
-import me.scoretwo.fastscript.api.format.FormatHeader
-import me.scoretwo.fastscript.api.language.LanguageManager
-import me.scoretwo.fastscript.api.plugin.ScriptPlugin
-import me.scoretwo.fastscript.api.plugin.ScriptPluginState
-import me.scoretwo.fastscript.command.FSCommandNexus
-import me.scoretwo.fastscript.config.SettingConfig
-import me.scoretwo.fastscript.api.script.ScriptManager
-import me.scoretwo.fastscript.api.utils.ExecType
-import me.scoretwo.fastscript.api.utils.ExecUtils
-import me.scoretwo.fastscript.api.utils.maven.MavenArtifact
-import me.scoretwo.fastscript.api.utils.process.ProcessResultType
-import me.scoretwo.fastscript.command.commands.ScriptCommand
-import me.scoretwo.fastscript.utils.Assist
-import me.scoretwo.fastscript.utils.assist
-import me.scoretwo.utils.bukkit.configuration.yaml.patchs.ignoreCase
-import me.scoretwo.utils.sender.GlobalPlayer
-import me.scoretwo.utils.sender.GlobalSender
-import net.md_5.bungee.api.ChatColor
-
-class FastScript(val plugin: ScriptPlugin) {
-
- lateinit var commandNexus: FSCommandNexus
- lateinit var scriptManager: ScriptManager
- lateinit var expansionManager: ExpansionManager
-
- fun setPlaceholder(player: GlobalPlayer, string: String) = plugin.setPlaceholder(player, string)
-
- private val libs = arrayOf(
- MavenArtifact("org.openjdk.nashorn:nashorn-core:15.2"),
- MavenArtifact("org.ow2.asm:asm-commons:7.3.1"),
- MavenArtifact("org.ow2.asm:asm-analysis:7.3.1"),
- MavenArtifact("org.ow2.asm:asm:7.3.1"),
- MavenArtifact("org.ow2.asm:asm-util:7.3.1"),
- MavenArtifact("org.ow2.asm:asm-tree:7.3.1"),
-
- MavenArtifact("org.scala-lang:scala-compiler:2.12.9"),
- MavenArtifact("org.scala-lang:scala-library:2.12.9"),
- MavenArtifact("org.scala-lang:scala-reflect:2.12.9"),
- MavenArtifact("org.scala-lang.modules:scala-xml_2.12:1.1.0"),
- )
-
- init {
- instance = this
- me.scoretwo.fastscript.plugin = plugin
-
- arrayOf(
- "___________ __ _________ .__ __ ",
- "\\_ _____/____ _______/ |_/ _____/ ___________|__|______/ |_ ",
- " | __) \\__ \\ / ___/\\ __\\_____ \\_/ ___\\_ __ \\ \\____ \\ __\\",
- " | \\ / __ \\_\\___ \\ | | / \\ \\___| | \\/ | |_> > | ",
- " \\___ / (____ /____ > |__|/_______ /\\___ >__| |__| __/|__| ",
- " \\/ \\/ \\/ \\/ \\/ |__| ",
- ""
- ).forEach {
- plugin.server.console.sendMessage("§3$it")
- }
-
- plugin.server.console.sendMessage("§3FastScript[§bV${plugin.description.version}§3] initializing...")
-
- if (!plugin.dataFolder.exists()) {
- plugin.dataFolder.mkdirs()
- }
- val startTime = System.currentTimeMillis()
- assist = Assist()
- settings = SettingConfig()
- languages = LanguageManager()
- plugin.server.console.sendMessage(FormatHeader.TREE, "Loaded config and language system.§8(${System.currentTimeMillis() - startTime}ms)")
-
- ExecUtils.execPeriod(ExecType.Loaded, languages["EXEC-ID.CONFIGS"]) {
- reload("config")
- }
-
- ExecUtils.execPeriod(ExecType.Loaded, languages["EXEC-ID.LIBS"]) {
- fun download(artifact: MavenArtifact) {
- val start = System.currentTimeMillis()
- val processResult = artifact.download()
- if (processResult.type == ProcessResultType.FAILED) {
- plugin.server.console.sendMessage(FormatHeader.ERROR, languages["DOWNLOAD-LIBS-FAILED"])
- throw Throwable(languages["DOWNLOAD-LIBS-FAILED"])
- }
- if (processResult.type == ProcessResultType.SUCCESS) {
- val format = if (stats == ScriptPluginState.RUNNING) FormatHeader.INFO else FormatHeader.TREE
- plugin.server.console.sendMessage(format, languages["DOWNLOADED-LIB"].setPlaceholder(mapOf(
- "lib_name" to "${artifact.artifactId}-${artifact.version}.jar",
- "millisecond" to "${System.currentTimeMillis() - start}"
- )))
- }
- }
- libs.forEach { download(it) }
- plugin.libs.forEach { download(it) }
- }
-
- ExecUtils.execPeriod(ExecType.Initialized, "script manager") {
- scriptManager = ScriptManager()
- }
-
- ExecUtils.execPeriod(ExecType.Initialized, "expansion manager") {
- expansionManager = ExpansionManager()
- }
- expansionManager.reload()
-
- ExecUtils.execPeriod(ExecType.Initialized, "CommandNexus") {
- commandNexus = FSCommandNexus()
- }
- }
-
- fun reloadLanguage() {
- languages.current = languages.languages[settings.getString("Options.Language")]?.reload() ?: languages.defaultLanguage.reload().also {
- plugin.server.console.sendMessage(FormatHeader.ERROR, "Language loading failed. The file may not exist. The default language will be used: ${it.name}")
- }
- }
-
- /**
- * 初始化内置脚本
- * 暂时弃坑
- */
- fun initInternalScripts() {
-
- }
-
- fun reloadAll() = reload("config", "script", "plugin")
-
- fun reload(vararg modes: String) {
- if (!plugin.dataFolder.exists()) {
- plugin.dataFolder.mkdirs()
- }
- try {
- commandNexus.register()
- } catch (t: Throwable) {
-
- }
- modes.forEach {mode ->
- when (mode) {
- "config" -> {
- settings.reload()
- reloadLanguage()
- }
- "script" -> {
- initInternalScripts()
- scriptManager.loadScripts()
- // Try to Fix Mohist and CatServer
- if (::commandNexus.isInitialized) {
- commandNexus = FSCommandNexus()
- }
- plugin.server.dispatchCommand(plugin.server.console, "fs script :reload")
- }
- "plugin" -> {
- plugin.reload()
- if (stats == ScriptPluginState.RUNNING)
- if (settings.getBoolean(settings.ignoreCase("options.debug")))
- plugin.server.dispatchCommand(plugin.server.console, "fs ::enable_debug")
- else
- plugin.server.dispatchCommand(plugin.server.console, "fs ::disable_debug")
- }
- }
- }
- }
-
- companion object {
- lateinit var instance: FastScript
- var stats = ScriptPluginState.INITIALIZING
-
- fun setBootstrap(plugin: ScriptPlugin) {
- if (::instance.isInitialized) {
- throw UnsupportedOperationException("Cannot redefine instance")
- }
- FastScript(plugin)
- }
-
- }
-
-}
-var debug = false
-
-lateinit var plugin: ScriptPlugin
-
-lateinit var settings: SettingConfig
-lateinit var languages: LanguageManager
-
-fun GlobalSender.sendMessage(format: FormatHeader, texts: Array, color: Boolean = true) = texts.forEach {
- this.sendMessage(format, it, color)
-}
-
-fun GlobalSender.sendMessage(format: FormatHeader, text: String, color: Boolean = true) {
- if (format == FormatHeader.DEBUG && !debug)
- return
- if (!color)
- this.sendMessage("${format.toLanguageFormat()}${text}")
- else
- this.sendMessage(
- ChatColor.translateAlternateColorCodes('&', "${format.toLanguageFormat()}${text}"))
-}
-
-
-
-fun GlobalSender.sendMessage(format: FormatHeader, text: String, placeholders: Map) {
- if (format == FormatHeader.DEBUG && !debug)
- return
- this.sendMessage("${format.toLanguageFormat()}$text", placeholders)
-}
-
-fun GlobalSender.sendMessage(text: String, placeholders: Map) {
- var rawText = text
- placeholders.forEach {
- rawText = rawText.replace("{${it.key}}", it.value)
- }
- this.sendMessage(text)
-}
-
-fun String.setPlaceholder(player: GlobalPlayer) = FastScript.instance.setPlaceholder(player, this)
-
-
-fun String.setPlaceholder(placeholder: Pair, player: GlobalPlayer? = null) = this.setPlaceholder(mapOf(placeholder), player)
-
-fun String.setPlaceholder(placeholders: Map, player: GlobalPlayer? = null): String {
- var rawText = if (player == null) this else setPlaceholder(player)
- placeholders.forEach {
- rawText = rawText.replace("{${it.key}}", it.value)
- }
- return rawText
-}
\ No newline at end of file
diff --git a/common/src/main/kotlin/me/scoretwo/fastscript/api/config/Config.kt b/common/src/main/kotlin/me/scoretwo/fastscript/api/config/Config.kt
deleted file mode 100644
index c406996..0000000
--- a/common/src/main/kotlin/me/scoretwo/fastscript/api/config/Config.kt
+++ /dev/null
@@ -1,21 +0,0 @@
-package me.scoretwo.fastscript.config
-
-import me.scoretwo.utils.bukkit.configuration.yaml.file.YamlConfiguration
-import java.io.File
-
-abstract class Config(val file: File) : YamlConfiguration() {
-
- open fun reload() {
- if (!file.exists()) {
- file.parentFile.mkdirs()
- save(file)
- } else {
- this.load(file)
- save(file)
- }
- onReload()
- }
-
- abstract fun onReload()
-
-}
\ No newline at end of file
diff --git a/common/src/main/kotlin/me/scoretwo/fastscript/api/exception/ProcessException.kt b/common/src/main/kotlin/me/scoretwo/fastscript/api/exception/ProcessException.kt
deleted file mode 100644
index 9fa4f8c..0000000
--- a/common/src/main/kotlin/me/scoretwo/fastscript/api/exception/ProcessException.kt
+++ /dev/null
@@ -1,4 +0,0 @@
-package me.scoretwo.fastscript.api.exception
-
-class ProcessException(message: String): Exception(message) {
-}
\ No newline at end of file
diff --git a/common/src/main/kotlin/me/scoretwo/fastscript/api/exception/ScriptException.kt b/common/src/main/kotlin/me/scoretwo/fastscript/api/exception/ScriptException.kt
deleted file mode 100644
index 39acddc..0000000
--- a/common/src/main/kotlin/me/scoretwo/fastscript/api/exception/ScriptException.kt
+++ /dev/null
@@ -1,3 +0,0 @@
-package me.scoretwo.fastscript.api.exception
-
-open class ScriptException(msg: String): Exception(msg)
\ No newline at end of file
diff --git a/common/src/main/kotlin/me/scoretwo/fastscript/api/exception/ScriptNotFound.kt b/common/src/main/kotlin/me/scoretwo/fastscript/api/exception/ScriptNotFound.kt
deleted file mode 100644
index 6148bfd..0000000
--- a/common/src/main/kotlin/me/scoretwo/fastscript/api/exception/ScriptNotFound.kt
+++ /dev/null
@@ -1,3 +0,0 @@
-package me.scoretwo.fastscript.api.exception
-
-class ScriptNotFound: ScriptException("Unknown script, it doesn't exist.")
\ No newline at end of file
diff --git a/common/src/main/kotlin/me/scoretwo/fastscript/api/expansion/ExpansionDescription.kt b/common/src/main/kotlin/me/scoretwo/fastscript/api/expansion/ExpansionDescription.kt
deleted file mode 100644
index 893ced8..0000000
--- a/common/src/main/kotlin/me/scoretwo/fastscript/api/expansion/ExpansionDescription.kt
+++ /dev/null
@@ -1,27 +0,0 @@
-package me.scoretwo.fastscript.api.expansion
-
-import me.scoretwo.utils.bukkit.configuration.yaml.ConfigurationSection
-import java.util.*
-import kotlin.NullPointerException
-import kotlin.jvm.Throws
-
-/**
- * @author Score2
- * @date 2021/2/4 21:41
- *
- * @project FastScript
- */
-class ExpansionDescription(val name: String, val main: String, val version: String? = null, val authors: Array = arrayOf(), val description: String? = null) {
-
- companion object {
-
- @Throws(NullPointerException::class)
- fun readConfig(section: ConfigurationSection) = ExpansionDescription(
- section.getString("name") ?: "Expansion-${UUID.randomUUID()}",
- section.getString("main") ?: throw NullPointerException("'main' cannot be null!"),
- section.getString("version"),
- section.getStringList("authors").toTypedArray(),
- section.getString("description")
- )
- }
-}
\ No newline at end of file
diff --git a/common/src/main/kotlin/me/scoretwo/fastscript/api/expansion/ExpansionManager.kt b/common/src/main/kotlin/me/scoretwo/fastscript/api/expansion/ExpansionManager.kt
deleted file mode 100644
index 3bb4f36..0000000
--- a/common/src/main/kotlin/me/scoretwo/fastscript/api/expansion/ExpansionManager.kt
+++ /dev/null
@@ -1,190 +0,0 @@
-package me.scoretwo.fastscript.api.expansion
-
-import me.scoretwo.fastscript.*
-import me.scoretwo.fastscript.api.format.FormatHeader
-import me.scoretwo.fastscript.api.plugin.ScriptPluginState
-import me.scoretwo.fastscript.api.utils.process.ProcessResult
-import me.scoretwo.fastscript.api.utils.process.ProcessResultType
-import me.scoretwo.fastscript.expansion.javascript.JavaScriptExpansion
-import me.scoretwo.fastscript.expansion.scala.ScalaExpansion
-import me.scoretwo.fastscript.utils.Utils
-import me.scoretwo.utils.bukkit.configuration.yaml.file.YamlConfiguration
-import me.scoretwo.utils.bukkit.configuration.yaml.patchs.ignoreCase
-import java.io.File
-import java.net.URL
-import java.net.URLClassLoader
-import java.util.jar.JarFile
-
-class ExpansionManager {
-
- val expansionFolder = File(plugin.dataFolder, "expansions")
- val expansions = mutableSetOf()
- val localExpansions = mutableMapOf()
-
- init {
- if (!expansionFolder.exists()) expansionFolder.mkdirs()
- }
-
- fun register(expansion: FastScriptExpansion) {
- expansions.add(expansion)
- }
-
- fun unregister(expansion: FastScriptExpansion) {
- expansions.remove(expansion)
- }
-
- fun getExpansionByName(name: String): FastScriptExpansion? {
- for (expansion in expansions) {
- if (expansion.name.equals(name, ignoreCase = true))
- return expansion
- }
- return null
- }
-
- fun getExpansionBySign(sign: String): FastScriptExpansion? {
- for (expansion in expansions) {
- if (expansion.sign.equals(sign, ignoreCase = true))
- return expansion
- }
- return null
- }
-
- @Synchronized
- fun reload() {
- val startTime = System.currentTimeMillis()
- expansions.clear()
- var success = 1
- var fail = 0
- var total = 1
- try {
- if (settings.getBoolean(settings.ignoreCase("Options.Internal-Expansions.JavaScript")))
- register(JavaScriptExpansion().reload())
- if (settings.getBoolean(settings.ignoreCase("Options.Internal-Expansions.Scala")))
- register(ScalaExpansion().reload())
- } catch (t: Throwable) {
- fail++
- plugin.server.console.sendMessage(FormatHeader.ERROR, languages["EXPANSION.ERROR-BY-CAUSE.LOAD-ERROR"].setPlaceholder(
- mapOf(
- "file_name" to "InternalExpansion",
- "reason" to t.stackTraceToString()
- )
- ))
- }
-
- if (!expansionFolder.exists())
- expansionFolder.mkdirs()
-
-
- for (file in expansionFolder.listFiles() ?: arrayOf()) {
- total++
- val rawExpansion = fromFileExpansion(file)
-
- if (rawExpansion.first.type == ProcessResultType.FAILED) {
- fail++
- continue
- }
-
- try {
- expansions.add(rawExpansion.second!!.reload())
- success++
- } catch (t: Throwable) {
- fail++
-// plugin.server.console.sendMessage(FormatHeader.ERROR, "An exception occurred while loading expansion ${file.name}, reason:\n§8${t.stackTraceToString()}")
- }
- }
- val format = if (FastScript.stats == ScriptPluginState.RUNNING) FormatHeader.INFO else FormatHeader.TREE
-
- val placeholders = mapOf(
- "id" to "expansions",
- "total" to "$total",
- "success" to "$success",
- "fail" to "$fail",
- "millisecond" to "${System.currentTimeMillis() - startTime}"
- )
- if (fail == 0)
- plugin.server.console.sendMessage(format, languages["LOADED-COUNTS-PROCESS-SUCCESS"].setPlaceholder(placeholders))
- else
- plugin.server.console.sendMessage(format, languages["LOADED-COUNTS-PROCESS-SUCCESS-HAS-FAILED"].setPlaceholder(placeholders))
- }
-
- private fun fromFileExpansion(file: File): Pair {
- val description: ExpansionDescription
- val expansionClass = try {
- Utils.addPath(file)
-
- val jarFile = JarFile(file)
- description = try {
- ExpansionDescription.readConfig(YamlConfiguration().also { it.load(jarFile.getInputStream(jarFile.getJarEntry("expansion.yml")).reader()) })
- } catch (t: Throwable) {
- plugin.server.console.sendMessage(FormatHeader.ERROR, languages["EXPANSION.ERROR-BY-CAUSE.LOAD-DESCRIPTION-FILE-ERROR"].setPlaceholder(
- mapOf(
- "file_name" to file.name,
- "reason" to t.stackTraceToString()
- )
- ))
- return Pair(ProcessResult(ProcessResultType.FAILED), null)
- }
- val clazz = try {
- Class.forName(description.main)
- } catch (t: Throwable) {
- plugin.server.console.sendMessage(FormatHeader.ERROR, languages["EXPANSION.ERROR-BY-CAUSE.LOAD-MAIN-CLASS-ERROR"].setPlaceholder(
- mapOf(
- "file_name" to file.name,
- "description_main" to description.main,
- "reason" to t.stackTraceToString()
- )
- ))
- return Pair(ProcessResult(ProcessResultType.FAILED), null)
- }
-
- val instance = try {
- clazz.newInstance()
- } catch (t: Throwable) {
- plugin.server.console.sendMessage(FormatHeader.ERROR, languages["EXPANSION.ERROR-BY-CAUSE.LOAD-MAIN-CLASS-ERROR"].setPlaceholder(
- mapOf(
- "file_name" to file.name,
- "description_main" to description.main,
- "reason" to t.stackTraceToString()
- )
- ))
- return Pair(ProcessResult(ProcessResultType.FAILED), null)
- }
-
- if (instance !is FastScriptExpansion) {
- plugin.server.console.sendMessage(FormatHeader.ERROR, languages["EXPANSION.ERROR-BY-CAUSE.LOAD-MAIN-CLASS-MAIN-NOT-DEPEND"].setPlaceholder(
- mapOf(
- "file_name" to file.name,
- "description_main" to description.main
- )
- ))
- return Pair(ProcessResult(ProcessResultType.FAILED), null)
- }
-
- clazz.asSubclass(FastScriptExpansion::class.java)
- } catch (t: Throwable) {
- plugin.server.console.sendMessage(FormatHeader.ERROR, languages["EXPANSION.ERROR-BY-CAUSE.LOAD-ERROR"].setPlaceholder(
- mapOf(
- "file_name" to file.name,
- "reason" to t.stackTraceToString()
- )
- ))
- return Pair(ProcessResult(ProcessResultType.FAILED), null)
- }
-
- if (expansionClass == null) {
- plugin.server.console.sendMessage(FormatHeader.ERROR, "Unable to load the extension '${file.name}' because it has no FastScriptExpansion class available!")
- return Pair(ProcessResult(ProcessResultType.FAILED), null)
- }
- return Pair(ProcessResult(ProcessResultType.SUCCESS), expansionClass.newInstance().also {
- localExpansions[description] = it
- })
- }
-
- fun unregister(name: String) = expansions.forEach {
- if (it.name == name) {
- expansions.remove(it)
- return@forEach
- }
- }
-
-}
\ No newline at end of file
diff --git a/common/src/main/kotlin/me/scoretwo/fastscript/api/expansion/FastScriptExpansion.kt b/common/src/main/kotlin/me/scoretwo/fastscript/api/expansion/FastScriptExpansion.kt
deleted file mode 100644
index 2f89cd5..0000000
--- a/common/src/main/kotlin/me/scoretwo/fastscript/api/expansion/FastScriptExpansion.kt
+++ /dev/null
@@ -1,25 +0,0 @@
-package me.scoretwo.fastscript.api.expansion
-
-import me.scoretwo.fastscript.api.script.Script
-import me.scoretwo.utils.sender.GlobalSender
-
-abstract class FastScriptExpansion {
-
- abstract val name: String
- abstract val sign: String
- abstract val fileSuffix: String
-
- @Deprecated("已不需要该 boolean 进行判断, 脚本不应该在每次 execute 时进行 evaluate")
- abstract val needEval: Boolean
-
- abstract fun reload(): FastScriptExpansion
-
- abstract fun eval(text: String, sender: GlobalSender, args: Array = arrayOf(), otherBindings: Map = mutableMapOf()): Any?
- abstract fun eval(script: Script, sender: GlobalSender, args: Array = arrayOf(), otherBindings: Map = mutableMapOf()): Any?
- abstract fun execute(script: Script, sender: GlobalSender, main: String = script.option.main, args: Array = arrayOf(), otherBindings: Map = mutableMapOf()): Any?
- abstract fun execute(text: String, sender: GlobalSender, main: String = "main", args: Array = arrayOf(), otherBindings: Map = mutableMapOf()): Any?
-
- // abstract fun eval(script: Script, sender: GlobalSender): Any?
-
- // abstract fun execute(script: Script, sender: GlobalSender, main: String, args: Array): Any?
-}
\ No newline at end of file
diff --git a/common/src/main/kotlin/me/scoretwo/fastscript/api/format/FormatHeader.kt b/common/src/main/kotlin/me/scoretwo/fastscript/api/format/FormatHeader.kt
deleted file mode 100644
index 3fe0642..0000000
--- a/common/src/main/kotlin/me/scoretwo/fastscript/api/format/FormatHeader.kt
+++ /dev/null
@@ -1,16 +0,0 @@
-package me.scoretwo.fastscript.api.format
-
-import me.scoretwo.fastscript.languages
-
-enum class FormatHeader {
- INFO, WARN, ERROR, TIPS, HOOKED, DEBUG, TREE;
-
- fun toLanguageFormat(): String {
- if (this == TREE) {
- return " §7├ "
- }
-
- return languages["format-header.${name}"]
- }
-
-}
\ No newline at end of file
diff --git a/common/src/main/kotlin/me/scoretwo/fastscript/api/language/Language.kt b/common/src/main/kotlin/me/scoretwo/fastscript/api/language/Language.kt
deleted file mode 100644
index 0d0f133..0000000
--- a/common/src/main/kotlin/me/scoretwo/fastscript/api/language/Language.kt
+++ /dev/null
@@ -1,41 +0,0 @@
-package me.scoretwo.fastscript.api.language
-
-import me.scoretwo.fastscript.languages
-import me.scoretwo.fastscript.plugin
-import me.scoretwo.utils.bukkit.configuration.yaml.file.YamlConfiguration
-import me.scoretwo.utils.bukkit.configuration.yaml.patchs.ignoreCase
-import me.scoretwo.utils.bukkit.configuration.yaml.patchs.saveConfiguration
-import me.scoretwo.utils.server.task.TaskType
-import java.io.File
-import java.util.concurrent.TimeUnit
-
-class Language(val version: String, val name: String = "en_US") {
-
- val file: File = File(plugin.dataFolder, "language/$name.yml")
-
- var defaultConfig = en_US
-
- val config = YamlConfiguration()
-
- operator fun set(node: String, any: Any?) = config.set(node.toUpperCase(), any)
-
- operator fun get(node: String) = config.getString(node.toUpperCase()) ?: defaultConfig.getString(node.toUpperCase())!!
-
- fun getList(node: String): MutableList = config.getStringList(node.toUpperCase())!!
-
- fun reload() = this.also {
- if (!file.exists()) {
- file.saveConfiguration(defaultConfig)
- } else {
- config.load(file)
- val configVersion = config.getString(config.ignoreCase("version"))
-
- if (configVersion == null || version != configVersion) {
- defaultConfig.getKeys(true).forEach { if (!config.contains(it)) { config.set(it, defaultConfig[it]) } }
- config.save(file)
- }
-
- }
- }
-
-}
diff --git a/common/src/main/kotlin/me/scoretwo/fastscript/api/language/LanguageManager.kt b/common/src/main/kotlin/me/scoretwo/fastscript/api/language/LanguageManager.kt
deleted file mode 100644
index 245b5bd..0000000
--- a/common/src/main/kotlin/me/scoretwo/fastscript/api/language/LanguageManager.kt
+++ /dev/null
@@ -1,38 +0,0 @@
-package me.scoretwo.fastscript.api.language
-
-import me.scoretwo.fastscript.plugin
-import net.md_5.bungee.api.ChatColor
-import java.io.File
-
-class LanguageManager {
- val version = Companion.version
- val defaultLanguage = Language(version).reload()
- val languages = mutableMapOf().also {
- File(plugin.dataFolder, "language/zh_CN.yml").also {
- if (!it.exists()) zh_CN.save(it)
- }
-
- it["en_US"] = defaultLanguage
- it["zh_CN"] = Language(version, "zh_CN").also { it.defaultConfig = zh_CN }
- }
-
- init {
- File(plugin.dataFolder, "language").listFiles()?.forEach {
- val name = it.name.substringBeforeLast(".")
- languages[name] = Language(version, name)
- }
- }
-
- var current = defaultLanguage
-
- operator fun set(node: String, any: Any?) = current.set(node, any)
-
- operator fun get(node: String): String = ChatColor.translateAlternateColorCodes('&', current[node])
-
- fun getList(node: String) = current.getList(node).also { it.toMutableList().forEachIndexed { i, s -> it[i] = ChatColor.translateAlternateColorCodes('&', s) } }
-
- companion object {
- const val version = "2"
- }
-
-}
\ No newline at end of file
diff --git a/common/src/main/kotlin/me/scoretwo/fastscript/api/language/Languages.kt b/common/src/main/kotlin/me/scoretwo/fastscript/api/language/Languages.kt
deleted file mode 100644
index 29d491a..0000000
--- a/common/src/main/kotlin/me/scoretwo/fastscript/api/language/Languages.kt
+++ /dev/null
@@ -1,402 +0,0 @@
-package me.scoretwo.fastscript.api.language
-
-import me.scoretwo.fastscript.languages
-import me.scoretwo.utils.bukkit.configuration.yaml.file.YamlConfiguration
-
-/**
- * @author 83669
- * @date 2021/3/18 21:52
- *
- * @project FastScript
- */
-
-val zh_CN get() = YamlConfiguration().also {
- it["FORMAT-HEADER"] = YamlConfiguration().also {
- it["INFO"] = "&7[&3Fast&bScript&7] &b信息 &8| &7"
- it["WARN"] = "&7[&3Fast&bScript&7] &e警告 &8| &7"
- it["ERROR"] = "&7[&3Fast&bScript&7] &c错误 &8| &7"
- it["TIPS"] = "&7[&3Fast&bScript&7] &2提示 &8| &7"
- it["HOOKED"] = "&7[&3Fast&bScript&7] &6挂钩 &8| &7"
- it["DEBUG"] = "&7[&3Fast&bScript&7] &3调试 &8| &7"
- }
- it["SUBSTANTIVE"] = YamlConfiguration().also {
- it["ARGS"] = "参数"
- it["USAGE"] = "用法"
- it["EVALUATED"] = "评估成功"
- it["ENABLED"] = "启用"
- it["DISABLED"] = "禁用"
- }
- it["EXEC-ID"] = YamlConfiguration().also {
- it["CONFIGS"] = "配置文件"
- it["LIBS"] = "运行库"
- it["SCRIPT-MANAGER"] = "脚本管理器"
- it["EXPANSION-MANAGER"] = "拓展管理器"
- it["COMMAND-NEXUS"] = "命令中枢"
- }
- it["DOWNLOADED-LIB"] = "正在下载 &b{lib_name}&7...&8({millisecond}ms)"
- it["DOWNLOAD-LIBS-FAILED"] = "&c无法下载运行库文件, 请检查您的网络, FastScript 无法启动."
- it["HOOKED-PLUGIN"] = "成功挂钩插件 &e{plugin_name} &7, 现在您可以使用该插件的相关功能!"
- it["COMMAND-NEXUS"] = YamlConfiguration().also {
- it["TIPS"] = YamlConfiguration().also {
- it["ONLY-CONSOLE"] = "&c该命令只能在控制台上执行."
- it["ONLY-PLAYER"] = "&c该命令只能由玩家执行."
- it["NO-PERMISSION"] = "&c您没有该命令的权限."
- it["UNKNOWN-USAGE"] = "&c当前用法 &e{usage_error} &c不正确, 正确用法 &e{usage_guess}&c."
- }
- it["HELPER"] = YamlConfiguration().also {
- it["NOT-FOUND-COMMANDS"] = "&7没有可用的命令数据."
- it["CLICK-INSERT-COMMAND"] = "&7点击插入命令: &f/{command}"
- it["CLICK-TO-GO-URL"] = "&7点击进入网页: &f{url}"
- it["PLAYER-IS-OFFLINE"] = "&7目标玩家 &a{player_name} &7不在线"
- }
- it["COMMANDS"] = YamlConfiguration().also {
- it["MIGRATE"] = YamlConfiguration().also {
- it["DESCRIPTION"] = "从其它插件迁移."
-
- it["UNKNOWN-ACTION"] = "未知迁移动作 {action_name}"
- }
-
- it["EXPANSION"] = YamlConfiguration().also {
- it["NOT-FOUND-NAME-OR-SIGN"] = "找不到拓展指定的名称或标识 &c{expansion_name}&7! 请检查名称或标识是否正确."
- it["LOADED-EXPANSIONS"] = "当前可用的拓展: &6{expansions}"
- it["DESCRIPTION"] = "查看所有拓展的操作."
- it["SUB-EXPANSION-DESCRIPTION"] = "关于 {expansion_name} 的命令."
-
- it["INFO"] = YamlConfiguration().also {
- it["DESCRIPTION"] = "查看该拓展的详细信息."
- it["TITLE"] = "拓展 &6{expansion_name}&7 的详细信息."
- it["TEXTS"] = mutableListOf(
- " &3&l* &7标识: &a{expansion_sign}",
- " &3&l* &7文件后缀: &a{expansion_file_suffix}",
- " &3&l* &7绑定的脚本: &f{expansion_bind_scripts}",
- "",
- " &7关于拓展 &6{expansion_name} &7的更多帮助, 请输入:"
-
- )
- }
- it["EVALUATE"] = YamlConfiguration().also {
- it["DESCRIPTION"] = "评估指定内容获得返回值 (':s' 添加在末尾可不显示返回值信息)"
- it["EVALUATE-RESULT"] = "使用拓展 &6{expansion_name} &7评估的结果: &b{result}"
- }
- }
- it["SCRIPT"] = YamlConfiguration().also {
- it["DESCRIPTION"] = "查看该脚本的信息."
- it["NOT-FOUND-SCRIPT"] = "找不到脚本 &b{script_name}&7! 请检查名称."
- it["SUB-SCRIPT-DESCRIPTION"] = "关于 {script_name} 的命令."
-
- it["EXECUTE"] = YamlConfiguration().also {
- it["DESCRIPTION"] = "执行指定内容获取返回值 (':s' 添加在末尾可不显示返回值信息)"
-
- it["EXECUTE-RESULT"] = "使用 &6{expansion_name} &7执行脚本 &b{script_name} &7的返回值: {result}"
- }
- it["EVALUATE"] = YamlConfiguration().also {
- it["DESCRIPTION"] = "评估指定内容获得返回值 (':s' 添加在末尾可不显示返回值信息)"
-
- it["EXECUTE-RESULT"] = "使用 &6{expansion_name} &7评估脚本 &b{script_name} &7的返回值: {result}"
- }
- it["RELOAD"] = YamlConfiguration().also {
- it["DESCRIPTION"] = "重新载入这个脚本."
- it["RELOADED-SCRIPT"] = "成功重新载入脚本 &b{script_name}&7!"
- }
-
- it["INFO"] = YamlConfiguration().also {
- it["DESCRIPTION"] = "查看该脚本的详细信息."
- it["TITLE"] = "脚本 &b{script_name} &7的详细信息."
- it["TEXTS"] = mutableListOf(
- " &3&l* &7版本: &2{script_version}",
- " &3&l* &7作者: &3{script_authors}",
- " &3&l* &7描述: &f{script_description}",
- " &3&l* &7受保护: &f{script_init_protected}",
- " &3&l* &7异步初始化: &f{script_init_use_async}",
- " &3&l* &7主函数: &f{script_main}",
- " &3&l* &7绑定的拓展: &6{script_bind_expansions}",
- "",
- " &7关于脚本 &6{script_name} &7的更多帮助, 请输入:"
-
- )
- }
-
- }
- it["RELOAD"] = YamlConfiguration().also {
- it["DESCRIPTION"] = "重新载入配置文件或设置."
- it["MODE"] = YamlConfiguration().also {
- it["ALL"] = "重新载入所有."
- it["CONFIG"] = "重新载入配置文件."
- it["SCRIPT"] = "重新载入脚本文件."
- it["PLUGIN"] = "重新载入插件设置."
- }
- it["LOADED-ALL"] = "载入所有设置成功."
- it["LOADED-CONFIG"] = "载入配置文件成功."
- it["LOADED-SCRIPT"] = "载入脚本文件成功."
- it["LOADED-PLUGIN"] = "载入插件设置成功."
-
- it["ASYNC-LOADED-ALL"] = "异步载入所有设置成功."
- it["ASYNC-LOADED-CONFIG"] = "异步载入配置文件成功."
- it["ASYNC-LOADED-SCRIPT"] = "异步载入脚本文件成功."
- it["ASYNC-LOADED-PLUGIN"] = "异步载入插件设置成功."
- }
- it["TOOLS"] = YamlConfiguration().also {
- it["DESCRIPTION"] = "一些实用的工具库."
-
- it["COMMAND"] = YamlConfiguration().also {
- it["DESCRIPTION"] = "以指定身份执行命令('@CONSOLE' 代表控制台身份)."
- }
-
- it["BUKKIT"] = YamlConfiguration().also {
- it["SOUNDS"] = YamlConfiguration().also {
- it["DESCRIPTION"] = "播放指定声音给玩家."
- it["NOT-FOUND-SOUND"] = "声音 &8{sound_name} &7没有找到."
- }
- }
- }
- it["DEBUG"] = YamlConfiguration().also {
- it["DESCRIPTION"] = "用于启动调试或查看一些调试信息."
- }
- }
- }
- it["EXPANSION"] = YamlConfiguration().also {
- it["TYPE-ENGINE"] = YamlConfiguration().also {
- it["EVALUATE-SCRIPT-ERROR"] = "评估脚本 {script_name} 时发送错误, 请检查脚本格式. 原因: \n&8{reason}"
- it["EVALUATE-TEMP-SCRIPT-ERROR"] = "评估临时脚本时发送错误, 请检查脚本格式. 原因: \n&8{reason}"
- it["EXECUTE-SCRIPT-ERROR"] = "脚本 {script_name} 执行函数 {execute_main} 时发生错误, 请检查脚本格式. 原因: \n&8{reason}"
- it["EXECUTE-SCRIPT-FUNCTION-NOT-FOUND-ERROR"] = "脚本 {script_name} 执行函数 {execute_main} 时发生错误, 原因: &8this function not found!"
- it["EXECUTE-TEMP-SCRIPT-ERROR"] = "临时脚本执行函数 {execute_main} 时发生错误, 请检查脚本格式, 原因: \n&8{reason}"
- it["EXECUTE-SCRIPT-FUNCTION-NOT-FOUND-ERROR"] = "临时脚本执行函数 {execute_main} 时发生错误, 原因: &8this function not found!"
- }
- it["ERROR-BY-CAUSE"] = YamlConfiguration().also {
- it["LOAD-ERROR"] = "载入扩展 {file_name} 时发生异常, 原因: \n&8{reason}"
- it["LOAD-DESCRIPTION-FILE-ERROR"] = "载入拓展描述文件 '{file_name}' 时发送错误, 原因: \n&8{reason}"
- it["LOAD-MAIN-CLASS-ERROR"] = "载入扩展 '{file_name}' 的主类 {description_main} 时发生错误, 原因: \n&8{reason}"
- it["LOAD-MAIN-CLASS-MAIN-NOT-DEPEND"] = "载入拓展 {description_main} 描述文件 '{file_name}' 发送错误, 原因: &c主类没有继承 FastScriptExpansion."
- it["CAN-NOT-LOAD-MAIN-CLASS"] = "无法载入扩展 '{file_name}' , 因为它没有找到继承 FastScriptExpansion 的类!"
- }
- }
- it["SCRIPT"] = YamlConfiguration().also {
- it["PROCESS-RESULT"] = YamlConfiguration().also {
- it["SCRIPT-OPTION-FILE-NOT-EXISTS"] = "脚本选项文件存在!"
- it["SCRIPT-TYPE-NOT-SUPPORTED"] = "脚本文件扩展名不受支持!"
- it["SCRIPT-FILE-NAME-CANNOT-SPACES"] = "文件名不能包含空格!"
- }
- it["LISTENERS"] = YamlConfiguration().also {
- it["FAILED-REGISTER"] = "脚本 {script_name} 的一个监听器注册失败, 可能监听类语法存在问题."
- it["FAILED-UNREGISTER"] = "脚本 {script_name} 的一个无法取消注册, 可能是该监听器没有被注册或类的实例不同."
- }
-
- it["SCRIPT-FAILED-LOAD-BY-PROCESS-RESULT"] = "载入脚本 &3{file_name} &7时发生错误, 原因: &8{reason}"
- }
- it["LOADED-COUNTS-PROCESS-SUCCESS"] = "成功载入 &b{total} &7个 {id}, &7成功数 &a{success}&7.&8({millisecond}ms)"
- it["LOADED-COUNTS-PROCESS-SUCCESS-HAS-FAILED"] = "成功载入 &b{total} &7个 {id}, &7成功数 &a{success}&7, &7失败数 &c{fail}&7.&8({millisecond}ms)"
-
-
- it["INVOKE"] = YamlConfiguration().also {
- it["ASYNC-SUCCESS"] = "异步 {exec_type} {exec_name}.&8({millisecond}ms)"
- it["ASYNC-SUCCESS-HAS-DESCRIPTION"] = "异步 {exec_type} {exec_name}, {exec_description}.&8({millisecond}ms)"
- it["ASYNC-FAILED"] = "&cAsync failed to invoke {exec_name}, 原因:\n&8{reason}"
-
- it["SUCCESS"] = "{exec_type} {exec_name}.&8({millisecond}ms)"
- it["SUCCESS-HAS-DESCRIPTION"] = "{exec_type} {exec_name}, {exec_description}.&8({millisecond}ms)"
- it["FAILED"] = "&c调用 {exec_name} 失败, 原因:\n&8{reason}"
- }
-
- it["FILE-LISTENER"] = YamlConfiguration().also {
- it["SCRIPT"] = YamlConfiguration().also {
- it["LOADED"] = "监听到文件 &6{file_name} &7改动, 成功重新载入脚本 &b{script_name}&7.&8({millisecond}ms)"
- }
- }
-
- it["VERSION"] = LanguageManager.version
-}
-val en_US get() = YamlConfiguration().also {
- it["FORMAT-HEADER"] = YamlConfiguration().also {
- it["INFO"] = "&7[&3Fast&bScript&7] &bINFO &8| &7"
- it["WARN"] = "&7[&3Fast&bScript&7] &eWARN &8| &7"
- it["ERROR"] = "&7[&3Fast&bScript&7] &cERROR &8| &7"
- it["TIPS"] = "&7[&3Fast&bScript&7] &2TIPS &8| &7"
- it["HOOKED"] = "&7[&3Fast&bScript&7] &6HOOKED &8| &7"
- it["DEBUG"] = "&7[&3Fast&bScript&7] &3DEBUG &8| &7"
- }
- it["SUBSTANTIVE"] = YamlConfiguration().also {
- it["ARGS"] = "args"
- it["USAGE"] = "usage"
- it["EVALUATED"] = "evaluated"
- it["ENABLED"] = "Enabled"
- it["DISABLED"] = "Disabled"
- }
- it["EXEC-ID"] = YamlConfiguration().also {
- it["CONFIGS"] = "configs"
- it["LIBS"] = "libs"
- it["SCRIPT-MANAGER"] = "script manager"
- it["EXPANSION-MANAGER"] = "expansion manager"
- it["COMMAND-NEXUS"] = "CommandNexus"
- }
- it["DOWNLOADED-LIB"] = "Downloaded &b{lib_name}&7...&8({millisecond}ms)"
- it["DOWNLOAD-LIBS-FAILED"] = "&cFailed to download the pre-library file, please check your network, FastScript failed to start."
- it["HOOKED-PLUGIN"] = "Hook to the plugin &e{plugin_name} &7successfully, now you can use the relevant functions of this plugin!"
- it["COMMAND-NEXUS"] = YamlConfiguration().also {
- it["TIPS"] = YamlConfiguration().also {
- it["ONLY-CONSOLE"] = "&cThis command can only be executed on the console."
- it["ONLY-PLAYER"] = "&cThis command can only be executed by the player."
- it["NO-PERMISSION"] = "&cYou do not have permission to execute the command."
- it["UNKNOWN-USAGE"] = "&cUsage &e{usage_error} &cis incorrect, you may want to use &e{usage_guess}&c."
- }
- it["HELPER"] = YamlConfiguration().also {
- it["NOT-FOUND-COMMANDS"] = "&7No command data available."
- it["CLICK-INSERT-COMMAND"] = "&7Click insert command: &f/{command}"
- it["CLICK-TO-GO-URL"] = "&7Click to go to url: &f{url}"
- it["PLAYER-IS-OFFLINE"] = "&7Player &a{player_name} &7is not online"
- }
- it["COMMANDS"] = YamlConfiguration().also {
- it["MIGRATE"] = YamlConfiguration().also {
- it["DESCRIPTION"] = "Migrate from other plugins."
-
- it["UNKNOWN-ACTION"] = "No action found {action_name}"
- }
-
- it["EXPANSION"] = YamlConfiguration().also {
- it["NOT-FOUND-NAME-OR-SIGN"] = "Cannot find the extension name or sign &c{expansion_name}&7! Please check the name."
- it["LOADED-EXPANSIONS"] = "Currently available extensions: &6{expansions}"
- it["DESCRIPTION"] = "View all expansions or operations."
- it["SUB-EXPANSION-DESCRIPTION"] = "About {expansion_name} commands."
-
- it["INFO"] = YamlConfiguration().also {
- it["DESCRIPTION"] = "View the information of this expansion."
- it["TITLE"] = "Expansion &6{expansion_name}&7's information."
- it["TEXTS"] = mutableListOf(
- " &3&l* &7Sign: &a{expansion_sign}",
- " &3&l* &7File suffix: &a{expansion_file_suffix}",
- " &3&l* &7Bind scripts: &f{expansion_bind_scripts}",
- "",
- " &7About expansions &6{expansion_name} &7more help, please enter:"
-
- )
- }
- it["EVALUATE"] = YamlConfiguration().also {
- it["DESCRIPTION"] = "Evaluate the specified content to get the return value (':s' added at the end does not return a message)"
- it["EVALUATE-RESULT"] = "Use extension &6{expansion_name} &7to evaluate the result of the content: &b{result}"
- }
- }
- it["SCRIPT"] = YamlConfiguration().also {
- it["DESCRIPTION"] = "View the information of this script."
- it["NOT-FOUND-SCRIPT"] = "Not found script &b{script_name}&7! Please check the name."
- it["SUB-SCRIPT-DESCRIPTION"] = "About {script_name} commands."
-
- it["EXECUTE"] = YamlConfiguration().also {
- it["DESCRIPTION"] = "Execute the specified content to get the return value (':s' added at the end does not return a message)"
-
- it["EXECUTE-RESULT"] = "Execute script &b{script_name} &7used expansion &6{expansion_name} &7to return result: {result}"
- }
- it["EVALUATE"] = YamlConfiguration().also {
- it["DESCRIPTION"] = "Evaluate the specified content to get the return value (':s' added at the end does not return a message)"
-
- it["EXECUTE-RESULT"] = "Evaluate script &b{script_name} &7used expansion &6{expansion_name} &7to return result: {result}"
- }
- it["RELOAD"] = YamlConfiguration().also {
- it["DESCRIPTION"] = "Reload this script."
- it["RELOADED-SCRIPT"] = "Reloaded script &b{script_name} &7successful!"
- }
-
- it["INFO"] = YamlConfiguration().also {
- it["DESCRIPTION"] = "View the information of this script."
- it["TITLE"] = "Script &b{script_name}&7's information."
- it["TEXTS"] = mutableListOf(
- " &3&l* &7Version: &2{script_version}",
- " &3&l* &7Authors: &3{script_authors}",
- " &3&l* &7Description: &f{script_description}",
- " &3&l* &7Protected: &f{script_init_protected}",
- " &3&l* &7UseAsync: &f{script_init_use_async}",
- " &3&l* &7Main: &f{script_main}",
- " &3&l* &7Bind expansions: &6{script_bind_expansions}",
- "",
- " &7About script &6{script_name} &7more help, please enter:"
-
- )
- }
-
- }
- it["RELOAD"] = YamlConfiguration().also {
- it["DESCRIPTION"] = "Reload configuration files or settings."
- it["MODE"] = YamlConfiguration().also {
- it["ALL"] = "Reload all."
- it["CONFIG"] = "Reload configuration file."
- it["SCRIPT"] = "Reload script file."
- it["PLUGIN"] = "Reload plugin settings."
- }
- it["LOADED-ALL"] = "Loaded all settings successful."
- it["LOADED-CONFIG"] = "Loaded configuration file successful."
- it["LOADED-SCRIPT"] = "Loaded script file successful."
- it["LOADED-PLUGIN"] = "Loaded plugin settings successful."
-
- it["ASYNC-LOADED-ALL"] = "Async loaded all settings successful."
- it["ASYNC-LOADED-CONFIG"] = "Async loaded configuration file successful."
- it["ASYNC-LOADED-SCRIPT"] = "Async loaded script file successful."
- it["ASYNC-LOADED-PLUGIN"] = "Async loaded plugin settings successful."
- }
- it["TOOLS"] = YamlConfiguration().also {
- it["DESCRIPTION"] = "Some useful tool libraries."
-
- it["COMMAND"] = YamlConfiguration().also {
- it["DESCRIPTION"] = "Send a command as sender('@CONSOLE' means console)."
- }
-
- it["BUKKIT"] = YamlConfiguration().also {
- it["SOUNDS"] = YamlConfiguration().also {
- it["DESCRIPTION"] = "Play Sound to the player."
- it["NOT-FOUND-SOUND"] = "Sound &8{sound_name} &7not found."
- }
- }
- }
- it["DEBUG"] = YamlConfiguration().also {
- it["DESCRIPTION"] = "Used to start debugging or view some debugging information."
- }
- }
- }
- it["EXPANSION"] = YamlConfiguration().also {
- it["TYPE-ENGINE"] = YamlConfiguration().also {
- it["EVALUATE-SCRIPT-ERROR"] = "An error occurred during script {script_name} evaluation, please check the script format. reason: \n&8{reason}"
- it["EVALUATE-TEMP-SCRIPT-ERROR"] = "An error occurred during temp script evaluation, please check the script format. reason: \n&8{reason}"
- it["EXECUTE-SCRIPT-ERROR"] = "An error occurred when the script {script_name} executes the function {execute_main}, please check the script format. reason: \n&8{reason}"
- it["EXECUTE-SCRIPT-FUNCTION-NOT-FOUND-ERROR"] = "An error occurred when the script {script_name} executes the function {execute_main}, reason: &8this function not found!"
- it["EXECUTE-TEMP-SCRIPT-ERROR"] = "An error occurred when the temp script executes the function {execute_main}, please check the script format, reason: \n&8{reason}"
- it["EXECUTE-SCRIPT-FUNCTION-NOT-FOUND-ERROR"] = "An error occurred when the temp script executes the function {execute_main}, reason: &8this function not found!"
- }
- it["ERROR-BY-CAUSE"] = YamlConfiguration().also {
- it["LOAD-ERROR"] = "An exception occurred while loading expansion {file_name}, reason: \n&8{reason}"
- it["LOAD-DESCRIPTION-FILE-ERROR"] = "An error occurred while loading the expansion '{file_name}' description file, reason: \n&8{reason}"
- it["LOAD-MAIN-CLASS-ERROR"] = "An error occurred while loading the main class {description_main} of expansion '{file_name}', reason: \n&8{reason}"
- it["LOAD-MAIN-CLASS-MAIN-NOT-DEPEND"] = "An error occurred while loading the main class {description_main} of expansion '{file_name}', reason: &cThe main class does not depend on FastScriptExpansion."
- it["CAN-NOT-LOAD-MAIN-CLASS"] = "Unable to load the extension '{file_name}' because it has no FastScriptExpansion class available!"
- }
- }
- it["SCRIPT"] = YamlConfiguration().also {
- it["PROCESS-RESULT"] = YamlConfiguration().also {
- it["SCRIPT-OPTION-FILE-NOT-EXISTS"] = "Script option file exists!"
- it["SCRIPT-TYPE-NOT-SUPPORTED"] = "The script file extension is not supported!"
- it["SCRIPT-FILE-NAME-CANNOT-SPACES"] = "File name cannot contain spaces!"
- }
- it["LISTENERS"] = YamlConfiguration().also {
- it["FAILED-REGISTER"] = "A listener of script {script_name} failed to register, there may be a problem with the syntax of the listener."
- it["FAILED-UNREGISTER"] = "One of the script {script_name} cannot be unregistered, it may be that the listener is not registered or the instance of the class is different."
- }
- it["SCRIPT-FAILED-LOAD-BY-PROCESS-RESULT"] = "An error occurred while loading script &3{file_name}&7, reason: &8{reason}"
- }
- it["LOADED-COUNTS-PROCESS-SUCCESS"] = "Loaded &b{total} &7{id}, &a{success} &7successes.&8({millisecond}ms)"
- it["LOADED-COUNTS-PROCESS-SUCCESS-HAS-FAILED"] = "Loaded &b{total} &7{id}, &a{success} &7successes, &c{fail} &7failures.&8({millisecond}ms)"
-
-
- it["INVOKE"] = YamlConfiguration().also {
- it["ASYNC-SUCCESS"] = "Async {exec_type} {exec_name}.&8({millisecond}ms)"
- it["ASYNC-SUCCESS-HAS-DESCRIPTION"] = "Async {exec_type} {exec_name}, {exec_description}.&8({millisecond}ms)"
- it["ASYNC-FAILED"] = "&cAsync failed to invoke {exec_name}, reason:\n&8{reason}"
-
- it["SUCCESS"] = "{exec_type} {exec_name}.&8({millisecond}ms)"
- it["SUCCESS-HAS-DESCRIPTION"] = "{exec_type} {exec_name}, {exec_description}.&8({millisecond}ms)"
- it["FAILED"] = "&cFailed to invoke {exec_name}, reason:\n&8{reason}"
- }
-
- it["FILE-LISTENER"] = YamlConfiguration().also {
- it["SCRIPT"] = YamlConfiguration().also {
- it["LOADED"] = "Detected file &6{file_name} &7changes, successfully reloaded script &b{script_name}&7.&8({millisecond}ms)"
- }
- }
- it["VERSION"] = LanguageManager.version
-}
diff --git a/common/src/main/kotlin/me/scoretwo/fastscript/api/plugin/ScriptPlugin.kt b/common/src/main/kotlin/me/scoretwo/fastscript/api/plugin/ScriptPlugin.kt
deleted file mode 100644
index 88c7df0..0000000
--- a/common/src/main/kotlin/me/scoretwo/fastscript/api/plugin/ScriptPlugin.kt
+++ /dev/null
@@ -1,41 +0,0 @@
-package me.scoretwo.fastscript.api.plugin
-
-import me.scoretwo.fastscript.api.utils.maven.MavenArtifact
-import me.scoretwo.utils.plugin.GlobalPlugin
-import me.scoretwo.utils.plugin.PluginDescription
-import me.scoretwo.utils.plugin.logging.GlobalLogger
-import me.scoretwo.utils.sender.GlobalPlayer
-import me.scoretwo.utils.sender.GlobalSender
-import me.scoretwo.utils.server.GlobalServer
-import java.io.File
-
-abstract class ScriptPlugin(val plugin: GlobalPlugin): GlobalPlugin {
-
- abstract fun setPlaceholder(player: GlobalPlayer, string: String): String
-
- open val libs: MutableList = mutableListOf()
-
- val scriptKits = mutableMapOf()
-
- abstract fun toOriginalPlugin(): Any?
- abstract fun toOriginalSender(sender: GlobalSender): Any?
- abstract fun toGlobalSender(any: Any?): GlobalSender
- abstract fun toOriginalPlayer(player: GlobalPlayer): Any?
- abstract fun toGlobalPlayer(any: Any?): GlobalPlayer
- abstract fun toOriginalServer(): Any?
-
- abstract fun registerListener(any: Any?): Boolean
- abstract fun unregisterListener(any: Any?): Boolean
-
- open fun load() {}
- open fun reload() {}
- open fun enable() {}
- open fun disable() {}
-
- override val dataFolder: File = plugin.dataFolder
- override val description: PluginDescription get() = plugin.description
- override val logger: GlobalLogger = plugin.logger
- override val pluginClassLoader: ClassLoader = plugin.pluginClassLoader
- override val server: GlobalServer = plugin.server
-
-}
\ No newline at end of file
diff --git a/common/src/main/kotlin/me/scoretwo/fastscript/api/plugin/ScriptPluginState.kt b/common/src/main/kotlin/me/scoretwo/fastscript/api/plugin/ScriptPluginState.kt
deleted file mode 100644
index ea8005e..0000000
--- a/common/src/main/kotlin/me/scoretwo/fastscript/api/plugin/ScriptPluginState.kt
+++ /dev/null
@@ -1,14 +0,0 @@
-package me.scoretwo.fastscript.api.plugin
-
-/**
- * @author Score2
- * @date 2021/2/20 16:01
- *
- * @project FastScript
- */
-enum class ScriptPluginState {
- INITIALIZING,
- RUNNING,
- RELOADING,
- DISABLE
-}
\ No newline at end of file
diff --git a/common/src/main/kotlin/me/scoretwo/fastscript/api/script/Script.kt b/common/src/main/kotlin/me/scoretwo/fastscript/api/script/Script.kt
deleted file mode 100644
index 6337a39..0000000
--- a/common/src/main/kotlin/me/scoretwo/fastscript/api/script/Script.kt
+++ /dev/null
@@ -1,84 +0,0 @@
-package me.scoretwo.fastscript.api.script
-
-import me.scoretwo.fastscript.*
-import me.scoretwo.fastscript.api.expansion.FastScriptExpansion
-import me.scoretwo.fastscript.api.format.FormatHeader
-import me.scoretwo.utils.sender.GlobalSender
-
-/**
- * @author Scre2
- * @date 2021/2/8 13:33
- *
- * @project FastScript
- */
-abstract class Script(
- val name: String,
- val option: ScriptOption,
- // sign, text
- var texts : MutableMap = mutableMapOf()
-) {
-
- val main get() = option.getString("main") ?: "main"
- val version get() = option.getString("version") ?: "1.0-default"
- val description get() = option.getString("description") ?: "Not more..."
- val authors get() = option.getStringList("authors") ?: listOf()
-
- class Init(val option: ScriptOption) {
- val useAsync get() = option.getBoolean("init.use-async")
- val protected get() = option.getBoolean("init.protected")
- }
- val init = Init(option)
-
- val listeners = mutableListOf()
-
- fun bindExpansions() =
- mutableListOf().also { expansions ->
- texts.keys.forEach {
- expansions.add(FastScript.instance.expansionManager.getExpansionBySign(it) ?: return@forEach)
- }
- }
-
- open fun eval(sign: String, sender: GlobalSender, vararg args: String): Any? =
- eval(FastScript.instance.expansionManager.getExpansionBySign(sign), sender, *args)
-
- fun eval(expansion: FastScriptExpansion?, sender: GlobalSender, vararg args: String): Any? =
- expansion?.eval(this, sender, arrayOf(*args))
-
- open fun execute(sign: String, sender: GlobalSender, main: String = option.main, args: Array = arrayOf()): Any? =
- execute(FastScript.instance.expansionManager.getExpansionBySign(sign), sender, main, args)
-
- fun execute(expansion: FastScriptExpansion?, sender: GlobalSender, main: String = option.main, args: Array = arrayOf()): Any? =
- expansion?.execute(this, sender, main, args)
-
- fun eval(script: String, sign: String, sender: GlobalSender, vararg args: String) = let {
- FastScript.instance.scriptManager.eval(FastScript.instance.scriptManager.getScript(script) ?: return@let null, sign, sender, *args)
- }
-
- fun execute(script: String, sign: String, sender: GlobalSender, main: String = FastScript.instance.scriptManager.getScript(script)?.configOption?.main ?: "main", args: Array = arrayOf()) = let {
- FastScript.instance.scriptManager.execute(FastScript.instance.scriptManager.getScript(script) ?: return@let null, sign, sender, main, args)
- }
-
- fun registerListener(any: Any?) {
- if (!plugin.registerListener(any))
- plugin.server.console.sendMessage(
- FormatHeader.WARN,
- languages["SCRIPT.LISTENERS.FAILED-REGISTER"].setPlaceholder("script_name" to name)
- )
- else
- listeners.add(any)
- }
-
- fun unregisterListener(any: Any?) {
- if (!plugin.unregisterListener(any))
- plugin.server.console.sendMessage(
- FormatHeader.WARN,
- languages["SCRIPT.LISTENERS.FAILED-UNREGISTER"].setPlaceholder("script_name" to name)
- )
- else
- listeners.remove(any)
- }
-
- fun unregisterListeners() {
- listeners.toMutableList().forEach { unregisterListener(it) }
- }
-}
\ No newline at end of file
diff --git a/common/src/main/kotlin/me/scoretwo/fastscript/api/script/ScriptDescription.kt b/common/src/main/kotlin/me/scoretwo/fastscript/api/script/ScriptDescription.kt
deleted file mode 100644
index b2edc61..0000000
--- a/common/src/main/kotlin/me/scoretwo/fastscript/api/script/ScriptDescription.kt
+++ /dev/null
@@ -1,57 +0,0 @@
-package me.scoretwo.fastscript.api.script
-
-import me.scoretwo.utils.bukkit.configuration.yaml.ConfigurationSection
-import me.scoretwo.utils.bukkit.configuration.yaml.patchs.ignoreCase
-import javax.security.auth.login.Configuration
-
-@Deprecated("现可使用 Script 中的 meta 进行获取, 且 Script 已内置这些其中的基本变量.")
-interface ScriptDescription {
-
- val name: String
- // function name
- val main: String
-
- val version: String?
- val description: String?
-
- val authors: Array
-
- companion object {
-
- fun fromSection(section: ConfigurationSection) = parseDescription(
- section.getString(section.ignoreCase("name")),
- section.getString(section.ignoreCase("main")),
- section.getString(section.ignoreCase("version")),
- section.getString(section.ignoreCase("description")),
- if (section.isList(section.ignoreCase("authors")))
- section.getStringList(section.ignoreCase("authors"))
- else
- mutableListOf(section.getString(section.ignoreCase("authors")))
- )
-
- fun parseDescription(
- name: String,
- main: String,
- version: String? = null,
- description: String? = null,
- authors: MutableList = mutableListOf()
- ) = parseDescription(name, main, version, description, *authors.toTypedArray())
-
- fun parseDescription(
- name: String,
- main: String,
- version: String? = null,
- description: String? = null,
- vararg authors: String = arrayOf()
- ) = object : ScriptDescription {
- override val name: String = name
- override val main: String = main
- override val version: String? = version
- override val description: String? = description
- override val authors: Array = arrayOf(*authors)
-
- }
-
-
- }
-}
\ No newline at end of file
diff --git a/common/src/main/kotlin/me/scoretwo/fastscript/api/script/ScriptManager.kt b/common/src/main/kotlin/me/scoretwo/fastscript/api/script/ScriptManager.kt
deleted file mode 100644
index 0bb27e0..0000000
--- a/common/src/main/kotlin/me/scoretwo/fastscript/api/script/ScriptManager.kt
+++ /dev/null
@@ -1,269 +0,0 @@
-package me.scoretwo.fastscript.api.script
-
-import me.scoretwo.fastscript.*
-import me.scoretwo.fastscript.api.format.FormatHeader
-import me.scoretwo.fastscript.api.script.custom.ConfigScriptOption
-import me.scoretwo.fastscript.api.script.custom.CustomScript
-import me.scoretwo.fastscript.api.script.temp.TempScript
-import me.scoretwo.fastscript.api.utils.process.ProcessResult
-import me.scoretwo.fastscript.api.utils.process.ProcessResultType
-import me.scoretwo.fastscript.listeners.ScriptFileListener
-import me.scoretwo.utils.bukkit.configuration.yaml.ConfigurationSection
-import me.scoretwo.utils.bukkit.configuration.yaml.patchs.ignoreCase
-import me.scoretwo.utils.sender.GlobalPlayer
-import me.scoretwo.utils.sender.GlobalSender
-import me.scoretwo.utils.server.task.TaskType
-import org.apache.commons.io.monitor.FileAlterationListener
-import org.apache.commons.io.monitor.FileAlterationMonitor
-import org.apache.commons.io.monitor.FileAlterationObserver
-import java.io.File
-
-class ScriptManager {
-
- private val folders = mutableMapOf()
-
- val scripts = mutableMapOf()
-
- // bStats
- var evaluateCount = 0
- var executeCount = 0
-
- var operationCount = 0
-
- val defaultFolder: File get() {
- folders.forEach {
- return it.key
- }
- return null!!
- }
-
- private fun addFolder(folder: File) {
- folders[folder] = ScriptFileListener()
- }
-
- init {
- addFolder(File(plugin.dataFolder, "scripts"))
- if (!defaultFolder.exists()) {
- defaultFolder.mkdirs()
- File(defaultFolder, "example.js").writeText(
- """
- function main() {
- sender.sendMessage("§athis is demo.")
- }
- """.trimIndent()
- )
- }
- }
-
- val tempScripts = mutableMapOf()
-
- fun getScript(name: String) = scripts[name]
-
- private fun loadGeneralScript(scriptFile: File): Pair {
- val scriptName = scriptFile.name.substringBeforeLast(".")
- scriptFile.parentFile.listFiles()?.forEach {
- if (it.name == "$scriptName.yml") {
- return Pair(null, ProcessResult(ProcessResultType.OTHER, languages["SCRIPT.PROCESS-RESULT.SCRIPT-OPTION-FILE-NOT-EXISTS"], "file" to scriptFile.name))
- }
- }
-
- val file = let {
- FastScript.instance.expansionManager.expansions.forEach { expansion ->
- if (!scriptFile.name.endsWith(expansion.fileSuffix))
- return@forEach
-
- return@let scriptFile
- }
- return Pair(null, ProcessResult(ProcessResultType.FAILED, languages["SCRIPT.PROCESS-RESULT.SCRIPT-TYPE-NOT-SUPPORTED"], "file" to scriptFile.name))
- }
- val script = CustomScript(
-/* object : ScriptDescription {
- override val name: String = scriptName
- override val main: String = "main"
- override val version: String? = null
- override val description: String? = null
- override val authors: Array = arrayOf()
-
- },*/
- scriptName,
- ConfigScriptOption(),
- mutableListOf(file)
- ).reload()
-
- scripts[scriptName] = script
- return Pair(script, ProcessResult(ProcessResultType.SUCCESS))
- }
-
- /**
- * 仅接受文件后缀为yml的文件或者可用的脚本文件夹才能被处理
- */
- private fun loadScript(file: File): Pair {
- if (file.name.contains(" ")) return Pair(null, ProcessResult(ProcessResultType.FAILED, languages["SCRIPT.PROCESS-RESULT.SCRIPT-FILE-NAME-CANNOT-SPACES"]))
- if (file.isDirectory) {
- return loadFromFolderScript(file)
- }
-
- val scriptName = if (file.name.endsWith(".yml"))
- file.name.substringBeforeLast(".")
- else
- return loadGeneralScript(file)
-
- val option = ConfigScriptOption(file)
- val script = CustomScript(option.getString("name") ?: scriptName, option).reload()
-
- script.scriptFiles = mutableListOf().also { files ->
- FastScript.instance.expansionManager.expansions.forEach { expansion ->
- val candidateFile = File(file.parentFile, "$scriptName.${expansion.fileSuffix}")
- if (candidateFile.exists()) {
- files.add(candidateFile)
- }
- }
- }
-
- script.texts.keys.forEach { sign ->
- val expansion = FastScript.instance.expansionManager.getExpansionBySign(sign) ?: return@forEach
-
-/* if (expansion.needEval) {
- expansion.eval(sign, plugin.server.console)
- }
-*/
- }
-
- scripts[file.name.substringBeforeLast(".")] = script
- return Pair(script, ProcessResult(ProcessResultType.SUCCESS))
- }
-
- private fun loadFromFolderScript(folder: File): Pair {
- val optionsFiles = arrayOf("option.yml", "${folder.name}.yml", "setting.yml")
-
- val optionsFile: File = optionsFiles.let {
- for (fileName in it) {
- val file = File(folder, fileName)
- if (file.exists()) return@let file
- }
-
- return Pair(null, ProcessResult(ProcessResultType.FAILED, "Option file not found in ${folder.name}."))
- }
- val option = ConfigScriptOption(optionsFile)
- val script = CustomScript(option.getString("name") ?: folder.name, option).reload()
-
- script.scriptFiles = mutableListOf().also { files ->
- folder.listFiles()?.forEach { file ->
- FastScript.instance.expansionManager.expansions.forEach {
- if (file.name.endsWith(it.fileSuffix))
- files.add(file)
- }
- }
- }
-
-/*
- script.bindExpansions().forEach {
- if (it.needEval)
- script.eval(it.sign, plugin.server.console)
- }
-*/
-
- scripts[folder.name] = script
-
- return Pair(script, ProcessResult(ProcessResultType.SUCCESS))
- }
-
- fun loadScripts() {
- val startTime = System.currentTimeMillis()
- var total = 0
- var success = 0
- var fail = 0
-
- // unload fileListener
- folders.forEach {
- try {
- it.value.monitor?.stop()
- } catch (t: Throwable) {
-
- }
- }
-
- val protects = mutableMapOf()
- scripts.forEach {
- if (it.value.init.protected && it.value.configOption.file?.exists() == true) {
- protects[it.key] = it.value
- return@forEach
- }
- it.value.bindExpansions().forEach { expansion ->
- it.value.execute(expansion, plugin.server.console, "unload")
- }
- it.value.unregisterListeners()
- }
- scripts.clear()
- total += protects.size
-
- settings.getStringList(settings.ignoreCase("load-script-files")).forEach {
- addFolder(File(it))
- }
-
- folders.keys.forEach { file ->
- if (file.isDirectory && file.exists()) file.listFiles()?.forEach {
- loadScript(it).also {
- total++
- if (it.second.type == ProcessResultType.FAILED || it.first == null) {
- fail++
- plugin.server.console.sendMessage(FormatHeader.ERROR, languages["SCRIPT.SCRIPT-FAILED-LOAD-BY-PROCESS-RESULT"].setPlaceholder(
- mapOf("file_name" to (it.second.infos["file"] ?: "Unknown"), "reason" to it.second.message)
- ))
- }
- else if (it.second.type == ProcessResultType.SUCCESS)
- success++
- }
- }
- }
-
- if (settings.getBoolean(settings.ignoreCase("options.file-listener"))) {
- folders.forEach {
- val observer = FileAlterationObserver(it.key)
- observer.addListener(it.value)
- val monitor = FileAlterationMonitor(100L, observer)
- it.value.observer = observer
- it.value.monitor = monitor
- monitor.start()
- }
- }
-
- val placeholders = mapOf(
- "id" to "scripts",
- "total" to "$total",
- "success" to "$success",
- "fail" to "$fail",
- "millisecond" to "${System.currentTimeMillis() - startTime}"
- )
- if (fail == 0)
- plugin.server.console.sendMessage(FormatHeader.INFO, languages["LOADED-COUNTS-PROCESS-SUCCESS"].setPlaceholder(placeholders))
- else
- plugin.server.console.sendMessage(FormatHeader.INFO, languages["LOADED-COUNTS-PROCESS-SUCCESS-HAS-FAILED"].setPlaceholder(placeholders))
- }
-
- fun isConfigScriptOption(section: ConfigurationSection) =
- section.isString(section.ignoreCase("name")) &&
- (section.isString(section.ignoreCase("version")) || section.isInt(section.ignoreCase("version"))) &&
- section.isString(section.ignoreCase("main"))
-
-
-
- fun eval(script: CustomScript, sign: String, sender: GlobalSender, vararg args: String) =
- script.eval(sign, sender, *args).also { evaluateCount += 1; operationCount += 1 }
-
- fun execute(script: CustomScript, sign: String, sender: GlobalSender, main: String = script.configOption.main, args: Array = arrayOf()) =
- script.execute(sign, sender, main, args).also { executeCount += 1; operationCount += 1 }
-
-
- fun eval(script: String, sign: String, sender: GlobalSender, vararg args: String) = let {
- eval(getScript(script) ?: return@let null, sign, sender, *args)
- }
-
- fun execute(script: String, sign: String, sender: GlobalSender, main: String = getScript(script)?.configOption?.main ?: "main", args: Array = arrayOf()) = let {
- execute(getScript(script) ?: return@let null, sign, sender, main, args)
- }
-
- fun setPlaceholder(player: GlobalPlayer, text: String) = plugin.setPlaceholder(player, text)
-
- fun setPlaceholder(sender: Any, text: String) = plugin.setPlaceholder(plugin.toGlobalPlayer(sender), text)
-}
\ No newline at end of file
diff --git a/common/src/main/kotlin/me/scoretwo/fastscript/api/script/ScriptOption.kt b/common/src/main/kotlin/me/scoretwo/fastscript/api/script/ScriptOption.kt
deleted file mode 100644
index 488642f..0000000
--- a/common/src/main/kotlin/me/scoretwo/fastscript/api/script/ScriptOption.kt
+++ /dev/null
@@ -1,49 +0,0 @@
-package me.scoretwo.fastscript.api.script
-
-import me.scoretwo.fastscript.api.script.custom.ConfigScriptOption
-
-/**
- * @author Score2
- * @date 2021/2/8 13:28
- *
- * @project FastScript
- */
-interface ScriptOption {
-
- var main: String
- var meta: MutableMap
-
- fun toConfigOption() = try {
- this as ConfigScriptOption
- } catch (t: Throwable) {
- null
- }
-
- fun get(path: String): Any? = meta[path.toLowerCase()]
-
- fun getString(path: String): String? = meta[path.toLowerCase()]?.toString()
-
- fun set(path: String, value: Any?) {
- meta[path] = value
- }
-
- fun getBoolean(path: String) = meta[path.toLowerCase()] == true
-
- fun getStringList(path: String): List? {
- val list = getList(path)
- val rawList = mutableListOf()
- list?.forEach {
- rawList.add(it.toString())
- } ?: return null
- return rawList
- }
-
- fun getList(path: String): List<*>? {
- val list = meta[path]
- if (list !is List<*>) {
- return null
- }
- return list
- }
-
-}
\ No newline at end of file
diff --git a/common/src/main/kotlin/me/scoretwo/fastscript/api/script/custom/ConfigScriptOption.kt b/common/src/main/kotlin/me/scoretwo/fastscript/api/script/custom/ConfigScriptOption.kt
deleted file mode 100644
index f468228..0000000
--- a/common/src/main/kotlin/me/scoretwo/fastscript/api/script/custom/ConfigScriptOption.kt
+++ /dev/null
@@ -1,45 +0,0 @@
-package me.scoretwo.fastscript.api.script.custom
-
-import me.scoretwo.fastscript.api.script.ScriptOption
-import me.scoretwo.utils.bukkit.configuration.yaml.ConfigurationSection
-import me.scoretwo.utils.bukkit.configuration.yaml.MemorySection
-import me.scoretwo.utils.bukkit.configuration.yaml.file.YamlConfiguration
-import me.scoretwo.utils.bukkit.configuration.yaml.patchs.ignoreCase
-import me.scoretwo.utils.bukkit.configuration.yaml.patchs.ignoreCase
-import me.scoretwo.utils.bukkit.configuration.yaml.patchs.loadConfiguration
-import java.io.File
-
-open class ConfigScriptOption(val file: File? = null, val config: YamlConfiguration = file?.loadConfiguration() ?: YamlConfiguration().also { it.set("main", "main") }): ScriptOption {
- override var main: String = config.getString(config.ignoreCase("main")) ?: "main"
- override var meta = mutableMapOf().also { map ->
- config.getStringList(config.ignoreCase("meta"))?.forEach {
- map[it.substringBefore(":")] = it.substringAfter(":")
- }
- config.getKeys(true).forEach {
- if (!arrayOf("main", "meta").contains(it.toLowerCase()))
- map[it.toLowerCase()] = config.getConfigurationSection(config.ignoreCase(it))
- }
- }
-
- fun reload() {
- main = config.getString(config.ignoreCase("main")) ?: "main"
- meta = mutableMapOf().also { map ->
- config.getStringList(config.ignoreCase("meta"))?.forEach {
- map[it.substringBefore(":")] = it.substringAfter(":")
- }
- config.getKeys(true).forEach {
- if (!arrayOf("main", "meta").contains(it.toLowerCase()))
- map[it.toLowerCase()] = config.getConfigurationSection(config.ignoreCase(it))
- }
- }
- }
-
- fun getSection(): ConfigurationSection = config
-
- fun getSection(path: String): ConfigurationSection {
- val raw = meta[path]
- if (raw is ConfigurationSection) return raw
- return YamlConfiguration()
- }
-
-}
\ No newline at end of file
diff --git a/common/src/main/kotlin/me/scoretwo/fastscript/api/script/custom/CustomScript.kt b/common/src/main/kotlin/me/scoretwo/fastscript/api/script/custom/CustomScript.kt
deleted file mode 100644
index d611406..0000000
--- a/common/src/main/kotlin/me/scoretwo/fastscript/api/script/custom/CustomScript.kt
+++ /dev/null
@@ -1,61 +0,0 @@
-package me.scoretwo.fastscript.api.script.custom
-
-import me.scoretwo.fastscript.FastScript
-import me.scoretwo.fastscript.api.expansion.FastScriptExpansion
-import me.scoretwo.fastscript.api.format.FormatHeader
-import me.scoretwo.fastscript.api.script.Script
-import me.scoretwo.fastscript.api.script.ScriptDescription
-import me.scoretwo.fastscript.plugin
-import me.scoretwo.fastscript.sendMessage
-import me.scoretwo.utils.server.globalServer
-import me.scoretwo.utils.server.task.TaskType
-import java.io.File
-
-open class CustomScript(
- name: String,
- val configOption: ConfigScriptOption,
- var scriptFiles: MutableList = mutableListOf()
-): Script(name, configOption) {
-
- open fun reload() = also {
- if (configOption.file != null && !configOption.file.exists()) {
- globalServer.schedule.task(plugin, TaskType.ASYNC, Runnable {
- configOption.config.save(configOption.file)
- })
- }
- mergeToTexts()
- }
-
- fun mergeToTexts() {
- if (init.useAsync) {
- globalServer.schedule.task(plugin, TaskType.ASYNC, Runnable {
- texts.clear()
- FastScript.instance.expansionManager.expansions.forEach { mergeToText(it) }
- plugin.server.console.sendMessage(FormatHeader.DEBUG, "script §b$name §6async §7loaded!")
- })
- return
- }
-
- texts.clear()
- FastScript.instance.expansionManager.expansions.forEach { mergeToText(it) }
- }
-
- fun mergeToText(expansion: FastScriptExpansion) {
- if (let {
- scriptFiles.forEach { if (it.name.endsWith(expansion.fileSuffix, true)) { return@let false } }
- return@let true
- })
- return
-
- texts[expansion.sign] = StringBuilder().also {
- scriptFiles.forEach { file ->
- if (file.exists() && file.name.endsWith(".${expansion.fileSuffix}")) {
- it.append(file.readText()).append("\n")
- }
- }
- }.toString()
- expansion.eval(this, plugin.server.console)
- expansion.execute(this, plugin.server.console, "load")
- }
-
-}
\ No newline at end of file
diff --git a/common/src/main/kotlin/me/scoretwo/fastscript/api/script/temp/TempScript.kt b/common/src/main/kotlin/me/scoretwo/fastscript/api/script/temp/TempScript.kt
deleted file mode 100644
index 5297d1b..0000000
--- a/common/src/main/kotlin/me/scoretwo/fastscript/api/script/temp/TempScript.kt
+++ /dev/null
@@ -1,33 +0,0 @@
-package me.scoretwo.fastscript.api.script.temp
-
-import me.scoretwo.fastscript.FastScript
-import me.scoretwo.fastscript.api.script.Script
-import me.scoretwo.utils.sender.GlobalSender
-import java.util.*
-
-/**
- * @author Score2
- * @date 2021/2/8 11:37
- *
- * @project FastScript
- */
-class TempScript(texts : MutableMap = mutableMapOf()): Script("temp-${UUID.randomUUID()}", TempScriptOption(), texts) {
-
- override fun eval(sign: String, sender: GlobalSender, vararg args: String): Any? {
- for (expansion in FastScript.instance.expansionManager.expansions) {
- if (expansion.sign != sign)
- continue
- return expansion.eval(texts[sign] ?: "", sender, arrayOf(*args))
- }
- return null
- }
-
- override fun execute(sign: String, sender: GlobalSender, main: String, args: Array): Any? {
- for (expansion in FastScript.instance.expansionManager.expansions) {
- if (expansion.sign != sign)
- continue
- return expansion.execute(texts[sign] ?: "", sender, main, args)
- }
- return null
- }
-}
\ No newline at end of file
diff --git a/common/src/main/kotlin/me/scoretwo/fastscript/api/script/temp/TempScriptDescription.kt b/common/src/main/kotlin/me/scoretwo/fastscript/api/script/temp/TempScriptDescription.kt
deleted file mode 100644
index 9102624..0000000
--- a/common/src/main/kotlin/me/scoretwo/fastscript/api/script/temp/TempScriptDescription.kt
+++ /dev/null
@@ -1,19 +0,0 @@
-package me.scoretwo.fastscript.api.script.temp
-
-import me.scoretwo.fastscript.api.script.ScriptDescription
-import java.util.*
-
-/**
- * @author Score2
- * @date 2021/2/8 11:39
- *
- * @project FastScript
- */
-@Deprecated("现可使用 Script 中的 meta 进行获取, 且 Script 已内置这些其中的基本变量.")
-class TempScriptDescription: ScriptDescription {
- override val name: String = "temp-${UUID.randomUUID()}"
- override val main: String = "main"
- override val version: String? = null
- override val description: String? = null
- override val authors: Array = arrayOf()
-}
\ No newline at end of file
diff --git a/common/src/main/kotlin/me/scoretwo/fastscript/api/script/temp/TempScriptOption.kt b/common/src/main/kotlin/me/scoretwo/fastscript/api/script/temp/TempScriptOption.kt
deleted file mode 100644
index 17dac04..0000000
--- a/common/src/main/kotlin/me/scoretwo/fastscript/api/script/temp/TempScriptOption.kt
+++ /dev/null
@@ -1,14 +0,0 @@
-package me.scoretwo.fastscript.api.script.temp
-
-import me.scoretwo.fastscript.api.script.ScriptOption
-
-/**
- * @author Score2
- * @date 2021/2/8 13:38
- *
- * @project FastScript
- */
-class TempScriptOption: ScriptOption {
- override var main: String = "execute"
- override var meta: MutableMap = mutableMapOf()
-}
\ No newline at end of file
diff --git a/common/src/main/kotlin/me/scoretwo/fastscript/api/utils/ExecType.kt b/common/src/main/kotlin/me/scoretwo/fastscript/api/utils/ExecType.kt
deleted file mode 100644
index 7252e2a..0000000
--- a/common/src/main/kotlin/me/scoretwo/fastscript/api/utils/ExecType.kt
+++ /dev/null
@@ -1,17 +0,0 @@
-package me.scoretwo.fastscript.api.utils
-
-/**
- * @author Score2
- * @date 2021/2/19 13:16
- *
- * @project FastScript
- */
-enum class ExecType {
- Load,
- Loaded,
- Initialize,
- Initialized,
- Reload,
- Reloaded
-
-}
\ No newline at end of file
diff --git a/common/src/main/kotlin/me/scoretwo/fastscript/api/utils/ExecUtils.kt b/common/src/main/kotlin/me/scoretwo/fastscript/api/utils/ExecUtils.kt
deleted file mode 100644
index a44edec..0000000
--- a/common/src/main/kotlin/me/scoretwo/fastscript/api/utils/ExecUtils.kt
+++ /dev/null
@@ -1,56 +0,0 @@
-package me.scoretwo.fastscript.api.utils
-
-import me.scoretwo.fastscript.api.format.FormatHeader
-import me.scoretwo.fastscript.plugin
-import me.scoretwo.utils.server.task.TaskType
-import me.scoretwo.fastscript.*
-import me.scoretwo.fastscript.api.utils.process.ProcessResult
-import me.scoretwo.fastscript.api.utils.process.ProcessResultType
-
-object ExecUtils {
-
- fun execPeriod(execType: ExecType, execName: String, description: String? = null, taskType: TaskType = TaskType.SYNC, unit: () -> Unit): ProcessResult {
- val start = System.currentTimeMillis()
-
- if (taskType == TaskType.ASYNC) {
- val placeholders = mutableMapOf(
- "exec_type" to execType.name.toLowerCase(),
- "exec_name" to execName,
- "exec_description" to (description ?: ""),
- "millisecond" to "${System.currentTimeMillis() - start}"
- )
- plugin.server.schedule.task(plugin, taskType, Runnable {
- try {
- unit.invoke()
- if (description == null)
- plugin.server.console.sendMessage(FormatHeader.TREE, languages["INVOKE.ASYNC-SUCCESS"].setPlaceholder(placeholders))
- else
- plugin.server.console.sendMessage(FormatHeader.TREE, languages["INVOKE.ASYNC-SUCCESS-HAS-DESCRIPTION"].setPlaceholder(placeholders))
- } catch (e: Exception) {
- plugin.server.console.sendMessage(FormatHeader.TREE, languages["INVOKE.ASYNC-FAILED"].setPlaceholder(placeholders.also { it["reason"] = e.stackTraceToString() }))
- }
- })
- return ProcessResult(ProcessResultType.SUCCESS)
- } else {
- val placeholders = mutableMapOf(
- "exec_type" to execType.name,
- "exec_name" to execName,
- "exec_description" to (description ?: ""),
- "millisecond" to "${System.currentTimeMillis() - start}"
- )
- return try {
- unit.invoke()
- if (description == null)
- plugin.server.console.sendMessage(FormatHeader.TREE, languages["INVOKE.SUCCESS"].setPlaceholder(placeholders))
- else
- plugin.server.console.sendMessage(FormatHeader.TREE, languages["INVOKE.SUCCESS-HAS-DESCRIPTION"].setPlaceholder(placeholders))
- ProcessResult(ProcessResultType.SUCCESS)
- } catch (e: Exception) {
- plugin.server.console.sendMessage(FormatHeader.TREE, languages["INVOKE.FAILED"].setPlaceholder(placeholders.also { it["reason"] = e.stackTraceToString() }))
- ProcessResult(ProcessResultType.FAILED)
- }
- }
-
- }
-
-}
\ No newline at end of file
diff --git a/common/src/main/kotlin/me/scoretwo/fastscript/api/utils/Utils.kt b/common/src/main/kotlin/me/scoretwo/fastscript/api/utils/Utils.kt
deleted file mode 100644
index 3a9b1c0..0000000
--- a/common/src/main/kotlin/me/scoretwo/fastscript/api/utils/Utils.kt
+++ /dev/null
@@ -1,157 +0,0 @@
-package me.scoretwo.fastscript.utils
-
-import me.scoretwo.fastscript.FastScript
-import me.scoretwo.fastscript.api.format.FormatHeader
-import me.scoretwo.fastscript.config.SettingConfig
-import me.scoretwo.fastscript.languages
-import me.scoretwo.fastscript.plugin
-import me.scoretwo.utils.bukkit.configuration.yaml.patchs.ignoreCase
-import me.scoretwo.utils.command.CommandBuilder
-import me.scoretwo.utils.command.CommandNexus
-import me.scoretwo.utils.sender.GlobalPlayer
-import me.scoretwo.utils.sender.GlobalSender
-import me.scoretwo.utils.syntaxes.FileUtils
-import net.md_5.bungee.api.ChatColor
-import sun.misc.Unsafe
-import java.io.File
-import java.io.InputStream
-import java.lang.invoke.MethodHandle
-import java.lang.invoke.MethodHandles
-import java.lang.invoke.MethodType
-import java.lang.reflect.Field
-import java.lang.reflect.Method
-import java.net.URL
-
-object Utils {
-
- fun saveDefaultResource(target: File, inputStream: InputStream) {
- target.parentFile.mkdirs()
- if (!target.exists()) {
- saveResource(target, inputStream)
- }
- }
-
- fun saveResource(target: File, inputStream: InputStream) {
- target.parentFile.mkdirs()
- FileUtils.save(target, inputStream)
- }
-
-
- // Copy in https://github.com/TabooLib/TabooLib-Loader
- val unsafe: Unsafe = let {
- val field = Unsafe::class.java.getDeclaredField("theUnsafe")
- field.isAccessible = true
- field[null] as Unsafe
- }
- // Copy in https://github.com/TabooLib/TabooLib-Loader
- val lookup: MethodHandles.Lookup = let {
- val lookupField = MethodHandles.Lookup::class.java.getDeclaredField("IMPL_LOOKUP")
- val lookupBase = unsafe.staticFieldBase(lookupField)
- val lookupOffset = unsafe.staticFieldOffset(lookupField)
- unsafe.getObject(lookupBase, lookupOffset) as MethodHandles.Lookup
- }
-
- // Copy in https://github.com/TabooLib/TabooLib-Loader
- fun addPath(file: File): Boolean {
- try {
- val loader: ClassLoader = FastScript.instance.plugin.pluginClassLoader
- if (loader.javaClass.simpleName == "LaunchClassLoader") {
- val methodHandle: MethodHandle = lookup.findVirtual(
- loader.javaClass, "addURL", MethodType.methodType(
- Void.TYPE,
- URL::class.java
- )
- )
- methodHandle.invoke(loader, file.toURI().toURL())
- } else {
- val ucpField: Field? = try {
- loader.javaClass.getDeclaredField("ucp")
- } catch (e: NoSuchFieldError) {
- loader.javaClass.superclass.getDeclaredField("ucp")
- } catch (e: NoSuchFieldException) {
- loader.javaClass.superclass.getDeclaredField("ucp")
- }
- val ucpOffset: Long = unsafe.objectFieldOffset(ucpField)
- val ucp: Any = unsafe.getObject(loader, ucpOffset)
- val methodHandle: MethodHandle = lookup.findVirtual(
- ucp.javaClass, "addURL", MethodType.methodType(
- Void.TYPE,
- URL::class.java
- )
- )
- methodHandle.invoke(ucp, file.toURI().toURL())
- }
- return true
- } catch (t: Throwable) {
- t.printStackTrace()
- }
- return false
- }
-}
-
-class Assist {
-
- fun createCommandNexus(vararg alias: String) = CommandNexus(plugin, arrayOf(*alias))
-
- fun createCommandBuilder() = CommandBuilder()
-
- fun setPlaceholder(player: GlobalPlayer, text: String) = plugin.setPlaceholder(player, text)
-
-}
-lateinit var assist: Assist
-
-fun String.subStringWithEscape(from: Int, to: Int, escapes: List): String {
- val builder = StringBuilder()
- if (escapes.isEmpty())
- return substring(from, to)
- val it = escapes.iterator()
- var currentfrom = from
- var currentto = it.next()
- while (currentto != to) {
- builder.append(currentfrom, currentto)
- currentfrom = currentto + 1
- currentto = if (it.hasNext())
- it.next()
- else
- to
- }
- if (currentfrom != currentto)
- builder.append(currentfrom, currentto)
- return builder.toString()
-}
-
-// 可能存在问题
-fun String.protectedSplit(index: Char, protector: Pair): ArrayList {
- val list = ArrayList()
- var inner = false
- var startIndex = 0
- val len = this.length
- val escapes = ArrayList()
- for (endIndex in 0 until len) {
- val c = this[endIndex]
- if (inner) {
- if (c == protector.second) {
- inner = false
- escapes.add(endIndex)
- }
- }
- else {
- when (c) {
- index -> {
- list.add(subStringWithEscape(startIndex, endIndex, escapes))
- escapes.clear()
- startIndex = endIndex + 1
- }
- protector.first -> {
- inner = true
- escapes.add(endIndex)
- }
- }
- }
- }
- if (startIndex < len)
- list.add(subStringWithEscape(startIndex, len, escapes))
- return list
-}
-
-fun Boolean.toText() = if (this) "§a${languages["SUBSTANTIVE.ENABLED"]}" else "§c${languages["SUBSTANTIVE.DISABLED"]}"
\ No newline at end of file
diff --git a/common/src/main/kotlin/me/scoretwo/fastscript/api/utils/maven/MavenArtifact.kt b/common/src/main/kotlin/me/scoretwo/fastscript/api/utils/maven/MavenArtifact.kt
deleted file mode 100644
index 3a37e73..0000000
--- a/common/src/main/kotlin/me/scoretwo/fastscript/api/utils/maven/MavenArtifact.kt
+++ /dev/null
@@ -1,107 +0,0 @@
-package me.scoretwo.fastscript.api.utils.maven
-
-import sun.misc.Unsafe;
-import me.scoretwo.fastscript.FastScript
-import me.scoretwo.fastscript.api.utils.process.ProcessResult
-import me.scoretwo.fastscript.api.utils.process.ProcessResultType
-import me.scoretwo.fastscript.plugin
-import me.scoretwo.fastscript.utils.Utils
-import java.io.File
-import java.io.FileOutputStream
-import java.io.InputStream
-import java.lang.invoke.MethodHandle
-import java.lang.invoke.MethodHandles
-import java.lang.invoke.MethodType
-import java.lang.reflect.Field
-import java.lang.reflect.Method
-import java.net.HttpURLConnection
-import java.net.URL
-import java.net.URLClassLoader
-
-
-/**
- * @author Score2
- * @date 2021/2/25 19:05
- *
- * @project FastScript
- */
-class MavenArtifact {
-
- val groupId: String
- val artifactId: String
- val version: String
-
- constructor(groupId: String, artifactId: String, version: String, vararg repositories: String) {
- this.groupId = groupId
- this.artifactId = artifactId
- this.version = version
- this.repositories = arrayOf(*repositories, "https://maven.aliyun.com/nexus/content/groups/public/")
- }
-
- constructor(combined: String, vararg repositories: String) {
- val split = combined.split(":")
- this.groupId = split[0]
- this.artifactId = split[1]
- this.version = split[2]
- this.repositories = arrayOf(*repositories, "https://maven.aliyun.com/nexus/content/groups/public/")
- }
-
- val repositories: Array
-
- fun toURL(repository: String) = StringBuilder(repository).also {
- if (repository.last() != '/') it.append("/")
- it.append("${groupId.replace(".", "/")}/")
- it.append("$artifactId/")
- it.append("$version/")
- it.append("$artifactId-$version.jar")
- }.toString()
-
- fun download(): ProcessResult {
- repositories.forEach {
- if (downLoad(it).type == ProcessResultType.FAILED) return@forEach
- return ProcessResult(ProcessResultType.SUCCESS)
- }
- return ProcessResult(ProcessResultType.FAILED)
- }
-
- private fun downLoad(repository: String): ProcessResult {
- try {
- val url = toURL(repository)
- val folder = File(plugin.dataFolder, "lib")
- val file = File(folder, "$artifactId-$version.jar")
- if (file.exists()) {
- return ProcessResult(ProcessResultType.OTHER, "exists")
- }
-
- val httpURLConnection = (URL(url).openConnection() as HttpURLConnection).also {
- it.connectTimeout = 20 * 1000
- it.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)")
- }
-
- val inputStream: InputStream = httpURLConnection.inputStream
- val bytes: ByteArray = inputStream.readBytes()
-
- if (!folder.exists()) {
- folder.mkdir()
- }
-
- val fileOutputStream = FileOutputStream(file)
- fileOutputStream.write(bytes)
- fileOutputStream.close()
- inputStream.close()
-
- Utils.addPath(file)
- /*val method = URLClassLoader::class.java.getDeclaredMethod("addURL", URL::class.java)
- method.isAccessible = true
- method.invoke(plugin.pluginClassLoader, file.toURI().toURL())*/
- return ProcessResult(ProcessResultType.SUCCESS)
- } catch (t: Throwable) {
- t.printStackTrace()
- return ProcessResult(ProcessResultType.FAILED)
- }
- }
-
-
- override fun toString() = "$groupId:$artifactId:$version"
-
-}
\ No newline at end of file
diff --git a/common/src/main/kotlin/me/scoretwo/fastscript/api/utils/process/ProcessResult.kt b/common/src/main/kotlin/me/scoretwo/fastscript/api/utils/process/ProcessResult.kt
deleted file mode 100644
index 3be90e0..0000000
--- a/common/src/main/kotlin/me/scoretwo/fastscript/api/utils/process/ProcessResult.kt
+++ /dev/null
@@ -1,25 +0,0 @@
-package me.scoretwo.fastscript.api.utils.process
-
-import me.scoretwo.fastscript.api.exception.ProcessException
-
-class ProcessResult(val type: ProcessResultType, message: String? = null, vararg infos: Pair) {
-
- var message: String = message ?: type.message
-
- val infos = mutableMapOf()
-
- init {
- infos.forEach {
- this.infos[it.first] = it.second
- }
- }
-
- fun throwException() {
- throw ProcessException(message)
- }
-
- fun message(message: String) = this.also {
- this.message = message
- }
-
-}
\ No newline at end of file
diff --git a/common/src/main/kotlin/me/scoretwo/fastscript/api/utils/process/ProcessResultType.kt b/common/src/main/kotlin/me/scoretwo/fastscript/api/utils/process/ProcessResultType.kt
deleted file mode 100644
index 8c0f680..0000000
--- a/common/src/main/kotlin/me/scoretwo/fastscript/api/utils/process/ProcessResultType.kt
+++ /dev/null
@@ -1,8 +0,0 @@
-package me.scoretwo.fastscript.api.utils.process
-
-enum class ProcessResultType(val message: String) {
- SUCCESS("The process runs successfully."),
- FAILED("The process failed!"),
- OTHER("Other problems in the process."),
- DISABILITY("The process ran successfully, but was incomplete!")
-}
\ No newline at end of file
diff --git a/common/src/main/kotlin/me/scoretwo/fastscript/command/FSCommandNexus.kt b/common/src/main/kotlin/me/scoretwo/fastscript/command/FSCommandNexus.kt
deleted file mode 100644
index d2469fb..0000000
--- a/common/src/main/kotlin/me/scoretwo/fastscript/command/FSCommandNexus.kt
+++ /dev/null
@@ -1,145 +0,0 @@
-package me.scoretwo.fastscript.command
-
-import me.scoretwo.fastscript.*
-import me.scoretwo.fastscript.command.commands.*
-import me.scoretwo.utils.bukkit.configuration.yaml.patchs.ignoreCase
-import me.scoretwo.utils.command.CommandBuilder
-import me.scoretwo.utils.command.CommandNexus
-import me.scoretwo.utils.command.SendLimit
-import me.scoretwo.utils.command.SubCommand
-import me.scoretwo.utils.command.executor.Executors
-import me.scoretwo.utils.command.helper.DefaultHelpGenerator
-import me.scoretwo.utils.command.helper.HelpGenerator
-import me.scoretwo.utils.command.language.CommandLanguage
-import me.scoretwo.utils.sender.GlobalPlayer
-import me.scoretwo.utils.sender.GlobalSender
-import me.scoretwo.utils.server.globalServer
-import net.md_5.bungee.api.chat.ClickEvent
-import net.md_5.bungee.api.chat.HoverEvent
-import net.md_5.bungee.api.chat.TextComponent
-import net.md_5.bungee.api.chat.hover.content.Text
-
-class FSCommandNexus: CommandNexus(
- FastScript.instance.plugin,
- arrayOf("FastScript", "script", "fs", "fs${globalServer.brand.name.lowercase()}"),
- SendLimit.ALL,
- language,
- helpGenerator
-) {
-
- val debugCommand = DebugCommand()
-
- init {
- register(ScriptCommand())
- register(ExpansionCommand())
- register(MigrateCommand())
- register(ToolsCommand())
- register(ReloadCommand())
- if (settings.getBoolean(settings.ignoreCase("options.debug")))
- plugin.server.dispatchCommand(plugin.server.console, "fs ::enable_debug")
- }
-
- override fun execute(sender: GlobalSender, parents: Array, args: Array): Boolean {
- if (sender !is GlobalPlayer && args.isNotEmpty()) {
- when (args[0].toLowerCase()) {
- "::enable_debug" -> {
- if (!isRegistered(debugCommand))
- register(debugCommand)
- return true
- }
- "::disable_debug" -> {
- unregister(debugCommand)
- return true
- }
- }
- }
- return super.execute(sender, parents, args)
- }
-
- companion object {
- var safeMode = false
-
- val helpGenerator = try {
- object : HelpGenerator {
- override fun translateTexts(command: SubCommand, parents: MutableList, args: MutableList): MutableList>> {
- val texts = mutableListOf>()
-
- texts.addAll(upperModule)
-
- val displayParents = parents.joinToString(" ")
-
- command.subCommands.forEach { subCommand ->
- val displayAlia = subCommand.alias[0]
- val displayAlias =
- if (subCommand.alias.size < 2)
- ""
- else
- subCommand.alias.slice(1 until subCommand.alias.size)
- .joinToString("/","§8[","§8]§7")
-
- val displayArgs =
- if (subCommand.subCommands.isEmpty() && subCommand.customCommands.isNotEmpty())
- "§7<${languages["SUBSTANTIVE.ARGS"]}...> "
- else if (subCommand.subCommands.isNotEmpty()) {
- subCommand.subCommands.joinToString("/", "§7<", "§7> ", 5, "§8...") { it.alias[0] }
- } else
- ""
-
- texts.add(arrayOf(TextComponent("§7/$displayParents §f$displayAlia$displayAlias §7$displayArgs§8§l- §7${subCommand.description}").also {
- it.hoverEvent = HoverEvent(HoverEvent.Action.SHOW_TEXT, Text(languages["COMMAND-NEXUS.HELPER.CLICK-INSERT-COMMAND"].setPlaceholder(
- mapOf("command" to "$displayParents $displayAlia"))))
- it.clickEvent = ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/$displayParents $displayAlia ")
- }))
- }
-
- command.customCommands.forEach {
- val displayAlia = it.key
- val displayArgs = it.value.first?.joinToString("/", "§7<", "§7> ", 5, "§8...") ?: ""
- texts.add(arrayOf(TextComponent("§7/$displayParents §f$displayAlia §7$displayArgs§8§l- §7${it.value.second}").also {
- it.hoverEvent = HoverEvent(HoverEvent.Action.SHOW_TEXT, Text(languages["COMMAND-NEXUS.HELPER.CLICK-INSERT-COMMAND"].setPlaceholder(
- mapOf("command" to "$displayParents $displayAlia"))))
- it.clickEvent = ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/$displayParents $displayAlia ")
- }))
- }
-
- if (upperModule.size == texts.size) {
- texts.add(arrayOf(TextComponent(languages["COMMAND-NEXUS.HELPER.NOT-FOUND-COMMANDS"]).also {
- it.hoverEvent = HoverEvent(HoverEvent.Action.SHOW_TEXT, Text(languages["COMMAND-NEXUS.HELPER.NOT-FOUND-COMMANDS"]))
- }))
- }
-
-
- return mutableListOf(texts)
- }
-
- val upperModule = mutableListOf(
- arrayOf(TextComponent("")),
- arrayOf(
- TextComponent(" §3${plugin.description.name} §7v${plugin.description.version}").also {
- it.hoverEvent = HoverEvent(
- HoverEvent.Action.SHOW_TEXT, Text(languages["COMMAND-NEXUS.HELPER.CLICK-TO-GO-URL"].setPlaceholder(
- mapOf("url" to "https://github.com/FastScriptModule/FastScript")))
- )
- it.clickEvent = ClickEvent(ClickEvent.Action.OPEN_URL, "https://github.com/FastScriptModule/FastScript")
- },
- TextComponent(" §8§l- §bCOMMANDS")
- ),
- arrayOf(TextComponent(""))
- )
-
- }
- } catch (t: Throwable) {
- safeMode = true
- DefaultHelpGenerator(plugin)
- }
-
-
- val language = object : CommandLanguage {
- override val COMMAND_NO_PERMISSION = languages["COMMAND-NEXUS.TIPS.NO-PERMISSION"]
- override val COMMAND_ONLY_CONSOLE = languages["COMMAND-NEXUS.TIPS.ONLY-CONSOLE"]
- override val COMMAND_ONLY_PLAYER = languages["COMMAND-NEXUS.TIPS.ONLY-PLAYER"]
- override val COMMAND_UNKNOWN_USAGE = languages["COMMAND-NEXUS.TIPS.UNKNOWN-USAGE"]
- }
- }
-
-}
\ No newline at end of file
diff --git a/common/src/main/kotlin/me/scoretwo/fastscript/command/SimpleCommand.kt b/common/src/main/kotlin/me/scoretwo/fastscript/command/SimpleCommand.kt
deleted file mode 100644
index 7bbf618..0000000
--- a/common/src/main/kotlin/me/scoretwo/fastscript/command/SimpleCommand.kt
+++ /dev/null
@@ -1,20 +0,0 @@
-package me.scoretwo.fastscript.command
-
-import me.scoretwo.fastscript.FastScript
-import me.scoretwo.fastscript.plugin
-import me.scoretwo.utils.command.CommandBuilder
-import me.scoretwo.utils.command.SendLimit
-import me.scoretwo.utils.command.SubCommand
-import me.scoretwo.utils.command.helper.HelpGenerator
-
-/**
- * @author Score2
- * @date 2021/2/6 14:51
- *
- * @project FastScript
- */
-abstract class SimpleCommand(alias: Array, limit: SendLimit = SendLimit.ALL): SubCommand(plugin, alias, limit) {
-
- override var helpGenerator = FSCommandNexus.helpGenerator
-
-}
\ No newline at end of file
diff --git a/common/src/main/kotlin/me/scoretwo/fastscript/command/commands/DebugCommand.kt b/common/src/main/kotlin/me/scoretwo/fastscript/command/commands/DebugCommand.kt
deleted file mode 100644
index 21c1907..0000000
--- a/common/src/main/kotlin/me/scoretwo/fastscript/command/commands/DebugCommand.kt
+++ /dev/null
@@ -1,101 +0,0 @@
-package me.scoretwo.fastscript.command.commands
-
-import me.scoretwo.fastscript.FastScript
-import me.scoretwo.fastscript.api.format.FormatHeader
-import me.scoretwo.fastscript.command.SimpleCommand
-import me.scoretwo.fastscript.debug
-import me.scoretwo.fastscript.languages
-import me.scoretwo.fastscript.sendMessage
-import me.scoretwo.utils.command.executor.CommandExecutor
-import me.scoretwo.utils.command.executor.Executors
-import me.scoretwo.utils.sender.GlobalSender
-
-/**
- * @author Score2
- * @date 2021/2/22 17:34
- *
- * @project FastScript
- */
-class DebugCommand: SimpleCommand(arrayOf("debug", "test")) {
-
- override var description = languages["COMMAND-NEXUS.COMMANDS.DEBUG.DESCRIPTION"]
-
- override var subCommands = mutableListOf(
- nextBuilder().alias("languages", "language")
- .description("Debugging related to language.")
- .subCommand(
- nextBuilder().alias("config")
- .description("Content related to configuration files.")
- .subCommand(
- nextBuilder().alias("sections")
- .description("Print config all sections.")
- .execute(object : CommandExecutor {
- override fun execute(sender: GlobalSender, parents: Array, args: Array): Boolean {
- val name = if (args.isEmpty()) { languages.current.name } else { args[0] }
- if (!languages.languages.containsKey(name)) {
- return false
- }
- languages.languages[name]?.config?.getKeys(true)?.forEach {
- sender.sendMessage("§7$it: §f${languages.languages[name]?.get(it)}")
- }
- return true
- }
- }).also { builder ->
- languages.languages.forEach {
- builder.customCommand(it.key, null, "Print ${it.key}'s sections")
- }
- }
- )
- .subCommand(
- nextBuilder().alias("get")
- .description("Get language content through nodes.")
- .executor(object : Executors {
- override fun execute(sender: GlobalSender, parents: Array, args: Array): Boolean {
- val path = args.joinToString(" ")
- if (!languages.current.config.contains(path)) {
- sender.sendMessage("Section $path not found")
- return true
- }
- if (languages.current.config.isList(path)) {
- sender.sendMessage("$path:")
- languages.current.config.getStringList(path).forEach {
- sender.sendMessage(it)
- }
- sender.sendMessage()
- } else {
- sender.sendMessage("$path: ${languages.current[path]}")
- }
-
- return true
- }
-
- override fun tabComplete(sender: GlobalSender, parents: Array, args: Array): MutableList? {
- return languages.current.config.getKeys(true)?.toMutableList()
- }
- })
- )
- )
- .build(),
- nextBuilder().alias("enable")
- .description("Enable debug mode.")
- .execute(object : CommandExecutor {
- override fun execute(sender: GlobalSender, parents: Array, args: Array): Boolean {
- debug = true
- sender.sendMessage(FormatHeader.DEBUG, "Debug mode enabled. The server will start sending messages with debug.")
- return true
- }
- })
- .build(),
- nextBuilder().alias("disable")
- .description("Disable debug mode.")
- .execute(object : CommandExecutor {
- override fun execute(sender: GlobalSender, parents: Array, args: Array): Boolean {
- debug = false
- sender.sendMessage(FormatHeader.INFO, "Debug mode disabled.")
- return true
- }
- })
- .build()
- )
-
-}
\ No newline at end of file
diff --git a/common/src/main/kotlin/me/scoretwo/fastscript/command/commands/ExpansionCommand.kt b/common/src/main/kotlin/me/scoretwo/fastscript/command/commands/ExpansionCommand.kt
deleted file mode 100644
index f897bc3..0000000
--- a/common/src/main/kotlin/me/scoretwo/fastscript/command/commands/ExpansionCommand.kt
+++ /dev/null
@@ -1,137 +0,0 @@
-package me.scoretwo.fastscript.command.commands
-
-import me.scoretwo.fastscript.FastScript
-import me.scoretwo.fastscript.api.format.FormatHeader
-import me.scoretwo.fastscript.api.script.custom.CustomScript
-import me.scoretwo.fastscript.command.FSCommandNexus
-import me.scoretwo.fastscript.command.SimpleCommand
-import me.scoretwo.fastscript.languages
-import me.scoretwo.fastscript.sendMessage
-import me.scoretwo.fastscript.setPlaceholder
-import me.scoretwo.utils.command.executor.CommandExecutor
-import me.scoretwo.utils.command.executor.Executors
-import me.scoretwo.utils.sender.GlobalSender
-import net.md_5.bungee.api.chat.ClickEvent
-import net.md_5.bungee.api.chat.HoverEvent
-import net.md_5.bungee.api.chat.TextComponent
-import net.md_5.bungee.api.chat.hover.content.Text
-import org.jetbrains.kotlin.util.capitalizeDecapitalize.capitalizeFirstWord
-
-/**
- * @author Score2
- * @date 2021/2/19 12:26
- *
- * @project FastScript
- */
-class ExpansionCommand: SimpleCommand(arrayOf("expansion")) {
-
- override var description = languages["COMMAND-NEXUS.COMMANDS.EXPANSION.DESCRIPTION"]
-
- private val evaluateCommand = nextBuilder()
- .alias("evaluate", "eval")
- .description(languages["COMMAND-NEXUS.COMMANDS.EXPANSION.EVALUATE.DESCRIPTION"])
- .executor(object : Executors {
- override fun execute(sender: GlobalSender, parents: Array, args: Array): Boolean {
- if (args.isEmpty()) {
- sender.sendMessage(FormatHeader.ERROR, "${languages["SUBSTANTIVE.USAGE"].capitalizeFirstWord()}: /${parents.joinToString(" ")} §f §8:s")
- return true
- }
- val noReturn = if (args.isEmpty()) false else args[args.size - 1] == ":s"
-
- val expansion = FastScript.instance.expansionManager.getExpansionByName(parents[parents.size - 2]) ?: FastScript.instance.expansionManager.getExpansionBySign(parents[parents.size - 2]) ?: let {
- sender.sendMessage(FormatHeader.WARN, languages["COMMAND-NEXUS.COMMANDS.EXPANSION.NOT-FOUND-NAME-OR-SIGN"].setPlaceholder(
- mapOf("expansion_name" to parents[parents.size - 2])
- ))
- sender.sendMessage(FormatHeader.INFO, languages["COMMAND-NEXUS.COMMANDS.EXPANSION.LOADED-EXPANSIONS"].setPlaceholder(
- mapOf("expansions" to FastScript.instance.expansionManager.expansions.joinToString(", ") { it.name })
- ))
- return true
- }
-
- val text = args.sliceArray(0..(if (!noReturn) args.size - 1 else args.size - 2)).joinToString(" ")
-
- val result = expansion.eval(text, sender)
-
- if (!noReturn) {
- sender.sendMessage(FormatHeader.INFO, languages["COMMAND-NEXUS.COMMANDS.EXPANSION.EVALUATE.EVALUATE-RESULT"].setPlaceholder(
- mapOf(
- "expansion_name" to expansion.name,
- "result" to result.toString()
- )
- ))
- }
-
- return true
- }
-
- override fun tabComplete(sender: GlobalSender, parents: Array, args: Array) = mutableListOf(":s")
- })
- .build()
-
-
- private val infoCommand = nextBuilder()
- .alias("info")
- .description(languages["COMMAND-NEXUS.COMMANDS.EXPANSION.INFO.DESCRIPTION"])
- .execute(object : CommandExecutor {
- override fun execute(sender: GlobalSender, parents: Array, args: Array): Boolean {
- val expansion = FastScript.instance.expansionManager.getExpansionByName(parents[parents.size - 2]) ?: FastScript.instance.expansionManager.getExpansionBySign(parents[parents.size - 2]) ?: let {
- sender.sendMessage(FormatHeader.WARN, languages["COMMAND-NEXUS.COMMANDS.EXPANSION.NOT-FOUND-NAME-OR-SIGN"].setPlaceholder(
- mapOf("expansion_name" to parents[parents.size - 2])
- ))
- sender.sendMessage(FormatHeader.INFO, languages["COMMAND-NEXUS.COMMANDS.EXPANSION.LOADED-EXPANSIONS"].setPlaceholder(
- mapOf("expansions" to FastScript.instance.expansionManager.expansions.joinToString(", ") { it.name })
- ))
- return true
- }
-
- val displayParents = parents.slice(0..parents.size - 2).joinToString(" ")
-
- val bindScripts = mutableListOf().also { list -> FastScript.instance.scriptManager.scripts.forEach { if (it.value.texts.keys.contains(expansion.sign)) list.add(it.value) } }
-
- sender.sendMessage(FormatHeader.INFO, languages["COMMAND-NEXUS.COMMANDS.EXPANSION.INFO.TITLE"].setPlaceholder(
- mapOf("expansion_name" to expansion.name)))
- languages.getList("COMMAND-NEXUS.COMMANDS.EXPANSION.INFO.TEXTS").forEach {
- sender.sendMessage(it.setPlaceholder(mapOf(
- "expansion_name" to expansion.name,
- "expansion_sign" to expansion.sign,
- "expansion_file_suffix" to expansion.fileSuffix,
- "expansion_bind_scripts" to bindScripts.joinToString { it.name }
- )))
- }
- sender.sendMessage(TextComponent(" "), TextComponent("§7/$displayParents §fhelp").also {
- if (FSCommandNexus.safeMode) return@also
- it.hoverEvent = HoverEvent(HoverEvent.Action.SHOW_TEXT, Text(languages["COMMAND-NEXUS.HELPER.CLICK-INSERT-COMMAND"].setPlaceholder(
- mapOf("command" to "$displayParents help")
- )))
- it.clickEvent = ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/$displayParents help ")
- })
- sender.sendMessage()
-
- return true
- }
- })
- .build()
-
- init {
- subCommands.clear()
- FastScript.instance.expansionManager.expansions.forEach {
- val subCommand = nextBuilder()
- .alias(it.name.toLowerCase(), it.sign.toLowerCase())
- .description(languages["COMMAND-NEXUS.COMMANDS.EXPANSION.SUB-EXPANSION-DESCRIPTION"].setPlaceholder(mapOf("expansion_name" to it.name)))
- .execute(object : CommandExecutor {
- override fun execute(sender: GlobalSender, parents: Array, args: Array): Boolean {
- if (args.isEmpty()) {
- infoCommand.execute(sender, arrayOf(*parents, "info"), arrayOf())
- return true
- }
- return false
- }
- })
- .subCommand(infoCommand)
- .subCommand(evaluateCommand)
- .build()
- subCommands.add(subCommand)
- }
- }
-
-}
\ No newline at end of file
diff --git a/common/src/main/kotlin/me/scoretwo/fastscript/command/commands/MigrateCommand.kt b/common/src/main/kotlin/me/scoretwo/fastscript/command/commands/MigrateCommand.kt
deleted file mode 100644
index 45b5485..0000000
--- a/common/src/main/kotlin/me/scoretwo/fastscript/command/commands/MigrateCommand.kt
+++ /dev/null
@@ -1,44 +0,0 @@
-package me.scoretwo.fastscript.command.commands
-
-import me.scoretwo.fastscript.api.format.FormatHeader
-import me.scoretwo.fastscript.command.SimpleCommand
-import me.scoretwo.fastscript.languages
-import me.scoretwo.fastscript.sendMessage
-import me.scoretwo.fastscript.setPlaceholder
-import me.scoretwo.utils.sender.GlobalSender
-
-/**
- * @author Score2
- * @date 2021/2/24 10:57
- *
- * @project FastScript
- */
-class MigrateCommand: SimpleCommand(arrayOf("migrate")) {
-
- override var description = languages["COMMAND-NEXUS.COMMANDS.MIGRATE.DESCRIPTION"]
-
- override fun execute(sender: GlobalSender, parents: Array, args: Array): Boolean {
- if (args.isEmpty()) {
- return false
- }
-
- when (args[0]) {
- "PlaceholderAPI:JavaScript" -> {
- sender.sendMessage(FormatHeader.ERROR, "Not currently supported.")
- }
- else -> {
- sender.sendMessage(FormatHeader.ERROR, languages["COMMAND-NEXUS.COMMANDS.MIGRATE.UNKNOWN-ACTION"].setPlaceholder("action_name" to args[0]))
- }
- }
-
- return true
- }
-
- override fun tabComplete(sender: GlobalSender, parents: Array, args: Array): MutableList? {
- if (args.size < 2) {
- return mutableListOf("PlaceholderAPI:JavaScript")
- }
- return null
- }
-
-}
\ No newline at end of file
diff --git a/common/src/main/kotlin/me/scoretwo/fastscript/command/commands/ReloadCommand.kt b/common/src/main/kotlin/me/scoretwo/fastscript/command/commands/ReloadCommand.kt
deleted file mode 100644
index 584651f..0000000
--- a/common/src/main/kotlin/me/scoretwo/fastscript/command/commands/ReloadCommand.kt
+++ /dev/null
@@ -1,76 +0,0 @@
-package me.scoretwo.fastscript.command.commands
-
-import me.scoretwo.fastscript.sendMessage
-import me.scoretwo.fastscript.FastScript
-import me.scoretwo.fastscript.api.format.FormatHeader
-import me.scoretwo.fastscript.command.SimpleCommand
-import me.scoretwo.fastscript.languages
-import me.scoretwo.utils.sender.GlobalSender
-import me.scoretwo.utils.server.task.TaskType
-
-/**
- * @author Score2
- * @date 2021/2/6 14:50
- *
- * @project FastScript
- */
-class ReloadCommand: SimpleCommand(arrayOf("reload")) {
-
- override var description = languages["COMMAND-NEXUS.COMMANDS.RELOAD.DESCRIPTION"]
-
- override var customCommands: MutableMap?, String>> = mutableMapOf(
- "all" to Pair(null, languages["COMMAND-NEXUS.COMMANDS.RELOAD.MODE.ALL"]),
- "config" to Pair(null, languages["COMMAND-NEXUS.COMMANDS.RELOAD.MODE.CONFIG"]),
- "script" to Pair(null, languages["COMMAND-NEXUS.COMMANDS.RELOAD.MODE.SCRIPT"]),
- "plugin" to Pair(null, languages["COMMAND-NEXUS.COMMANDS.RELOAD.MODE.PLUGIN"]),
- )
-
- override fun execute(sender: GlobalSender, parents: Array, args: Array): Boolean {
- var mode = "all"
- if (args.isNotEmpty()) {
- mode = args[0].toLowerCase()
- }
-
- if (args.size > 1 && args[1] == ":async") {
- plugin.server.schedule.task(plugin, TaskType.ASYNC, Runnable {
- if (mode == "all") {
- FastScript.instance.reloadAll()
- sender.sendMessage(FormatHeader.INFO, languages["COMMAND-NEXUS.COMMANDS.RELOAD.ASYNC-LOADED-ALL"])
- return@Runnable
- }
- FastScript.instance.reload(mode)
- when (mode) {
- "config" -> sender.sendMessage(FormatHeader.INFO, languages["COMMAND-NEXUS.COMMANDS.RELOAD.ASYNC-LOADED-CONFIG"])
- "script" -> sender.sendMessage(FormatHeader.INFO, languages["COMMAND-NEXUS.COMMANDS.RELOAD.ASYNC-LOADED-SCRIPT"])
- "plugin" -> sender.sendMessage(FormatHeader.INFO, languages["COMMAND-NEXUS.COMMANDS.RELOAD.ASYNC-LOADED-PLUGIN"])
- }
- })
-
- return true
- }
-
-
- if (mode == "all") {
- FastScript.instance.reloadAll()
- sender.sendMessage(FormatHeader.INFO, languages["COMMAND-NEXUS.COMMANDS.RELOAD.LOADED-ALL"])
- return true
- }
- FastScript.instance.reload(mode)
- when (mode) {
- "config" -> sender.sendMessage(FormatHeader.INFO, languages["COMMAND-NEXUS.COMMANDS.RELOAD.LOADED-CONFIG"])
- "script" -> sender.sendMessage(FormatHeader.INFO, languages["COMMAND-NEXUS.COMMANDS.RELOAD.LOADED-SCRIPT"])
- "plugin" -> sender.sendMessage(FormatHeader.INFO, languages["COMMAND-NEXUS.COMMANDS.RELOAD.LOADED-PLUGIN"])
- }
-
- return true
- }
-
- override fun tabComplete(sender: GlobalSender, parents: Array, args: Array) =
- when {
- args.size < 2 -> mutableListOf("config", "script", "plugin", "all")
- args.size < 3 -> mutableListOf(":async")
- else -> null
- }
-
-
-}
\ No newline at end of file
diff --git a/common/src/main/kotlin/me/scoretwo/fastscript/command/commands/ScriptCommand.kt b/common/src/main/kotlin/me/scoretwo/fastscript/command/commands/ScriptCommand.kt
deleted file mode 100644
index 991324c..0000000
--- a/common/src/main/kotlin/me/scoretwo/fastscript/command/commands/ScriptCommand.kt
+++ /dev/null
@@ -1,273 +0,0 @@
-package me.scoretwo.fastscript.command.commands
-
-import me.scoretwo.fastscript.FastScript
-import me.scoretwo.fastscript.api.format.FormatHeader
-import me.scoretwo.fastscript.command.FSCommandNexus
-import me.scoretwo.fastscript.command.SimpleCommand
-import me.scoretwo.fastscript.languages
-import me.scoretwo.fastscript.sendMessage
-import me.scoretwo.fastscript.setPlaceholder
-import me.scoretwo.fastscript.utils.toText
-import me.scoretwo.utils.command.SubCommand
-import me.scoretwo.utils.command.executor.CommandExecutor
-import me.scoretwo.utils.command.executor.Executors
-import me.scoretwo.utils.sender.GlobalPlayer
-import me.scoretwo.utils.sender.GlobalSender
-import net.md_5.bungee.api.chat.ClickEvent
-import net.md_5.bungee.api.chat.HoverEvent
-import net.md_5.bungee.api.chat.TextComponent
-import net.md_5.bungee.api.chat.hover.content.Text
-
-/**
- * @author Score2
- * @date 2021/1/3 21:42
- *
- * @project FastScript
- */
-class ScriptCommand: SimpleCommand(arrayOf("script")) {
-
- override var description = languages["COMMAND-NEXUS.COMMANDS.SCRIPT.DESCRIPTION"]
-
- init {
- instance = this
- }
-
- private val runCommand = nextBuilder()
- .alias("execute", "run")
- .description(languages["COMMAND-NEXUS.COMMANDS.SCRIPT.EXECUTE.DESCRIPTION"])
- .executor(object : Executors {
- override fun execute(sender: GlobalSender, parents: Array, args: Array): Boolean {
- val noReturn = if (args.isEmpty()) false else args[args.size - 1] == ":s"
-
- val script = FastScript.instance.scriptManager.scripts[parents[parents.size - 2]] ?: let {
- // 似乎不会发生?
- sender.sendMessage(FormatHeader.WARN, languages["COMMAND-NEXUS.COMMANDS.SCRIPT.NOT-FOUND-SCRIPT"].setPlaceholder(
- mapOf("script_name" to parents[parents.size - 2])))
- return true
- }
- if (args.isEmpty()) {
- sender.sendMessage(FormatHeader.ERROR, "${languages["SUBSTANTIVE.USAGE"]}: /${parents.joinToString(" ")} §f<${script.texts.keys.joinToString("/")}> §7<${script.option.main}> §8:s")
- return true
- }
- val sign = args[0]
- if (!script.texts.keys.contains(sign)) {
- sender.sendMessage(FormatHeader.ERROR, "${languages["SUBSTANTIVE.USAGE"]}: /${parents.joinToString(" ")} §f<${script.texts.keys.joinToString("/")}> §7<${script.option.main}> §8:s")
- return true
- }
-
- val args0: Array = when {
- args.size < 3 -> arrayOf()
- noReturn -> arrayOf(*args.sliceArray(2..args.size - 2))
- else -> arrayOf(*args.sliceArray(2 until args.size))
- }
-
- val result = when {
- args.isEmpty() -> script.execute(sign, sender)
- args.size >= 2 -> script.execute(sign, sender, args[1], args0)
- else -> null
- }
-
- if (!noReturn) {
- sender.sendMessage(FormatHeader.INFO, languages["COMMAND-NEXUS.COMMANDS.SCRIPT.EXECUTE.EXECUTE-RESULT"].setPlaceholder(
- mapOf(
- "script_name" to script.name,
- "expansion_name" to (FastScript.instance.expansionManager.getExpansionBySign(sign)?.name ?: "Unknown"),
- "result" to result.toString()
- )))
- }
-
- return true
- }
-
- override fun tabComplete(sender: GlobalSender, parents: Array, args: Array): MutableList {
- val scriptName = parents[parents.size - 2]
- if (args.size < 2) {
- return mutableListOf().also { list -> FastScript.instance.expansionManager.expansions.forEach { list.add(it.sign) } }
- } else if (args.size < 3) {
- val script = FastScript.instance.scriptManager.getScript(scriptName) ?: return mutableListOf(":s")
- return mutableListOf(script.option.main)
- }
- return mutableListOf(":s")
- }
- })
- .build()
-
- private val evaluateCommand = nextBuilder()
- .alias("evaluate", "eval")
- .description(languages["COMMAND-NEXUS.COMMANDS.SCRIPT.EVALUATE.DESCRIPTION"])
- .also { builder ->
- FastScript.instance.expansionManager.expansions.forEach {
- builder.customCommand(it.sign, arrayOf(), "expansion sign")
- }
- }
- .executor(object : Executors {
- override fun execute(sender: GlobalSender, parents: Array, args: Array): Boolean {
- val noReturn = if (args.isEmpty()) false else args[args.size - 1] == ":s"
-
- val script = FastScript.instance.scriptManager.scripts[parents[parents.size - 2]] ?: let {
- // 似乎不会发生?
- sender.sendMessage(FormatHeader.WARN, languages["COMMAND-NEXUS.COMMANDS.SCRIPT.NOT-FOUND-SCRIPT"].setPlaceholder(
- mapOf("script_name" to parents[parents.size - 2])))
- return true
- }
- if (args.isEmpty()) {
- sender.sendMessage(FormatHeader.ERROR, "${languages["SUBSTANTIVE.USAGE"]}: /${parents.joinToString(" ")} §f<${script.texts.keys.joinToString("/")}> §7 §8:s")
- return true
- }
- val sign = args[0]
- if (!script.texts.keys.contains(sign)) {
- sender.sendMessage(FormatHeader.ERROR, "${languages["SUBSTANTIVE.USAGE"]}: /${parents.joinToString(" ")} §f<${script.texts.keys.joinToString("/")}>")
- return true
- }
- val args0: Array = when {
- args.size < 2 -> arrayOf()
- noReturn -> arrayOf(*args.sliceArray(1..args.size - 2))
- else -> arrayOf(*args.sliceArray(1 until args.size))
- }
-
- val result = script.eval(sign, sender, *args0)
-
- if (!noReturn) {
- sender.sendMessage(FormatHeader.INFO, languages["COMMAND-NEXUS.COMMANDS.SCRIPT.EVALUATE.EXECUTE-RESULT"].setPlaceholder(
- mapOf(
- "script_name" to script.name,
- "expansion_name" to (FastScript.instance.expansionManager.getExpansionBySign(sign)?.name ?: "Unknown"),
- "result" to result.toString()
- )))
- }
-
- return true
- }
-
- override fun tabComplete(sender: GlobalSender, parents: Array, args: Array): MutableList {
- if (args.size < 2) {
- return mutableListOf().also { list -> FastScript.instance.expansionManager.expansions.forEach { list.add(it.sign) } }
- }
- return mutableListOf(":s")
- }
- })
- .build()
-
- private val reloadCommand = nextBuilder()
- .alias("reload")
- .description(languages["COMMAND-NEXUS.COMMANDS.SCRIPT.RELOAD.DESCRIPTION"])
- .execute(object : CommandExecutor {
- override fun execute(sender: GlobalSender, parents: Array, args: Array): Boolean {
- val script = FastScript.instance.scriptManager.scripts[parents[parents.size - 2]] ?: let {
- // 似乎不会发生?
- sender.sendMessage(FormatHeader.WARN, languages["COMMAND-NEXUS.COMMANDS.SCRIPT.NOT-FOUND-SCRIPT"].setPlaceholder(
- mapOf("script_name" to parents[parents.size - 2])))
- return true
- }
-
- script.bindExpansions().forEach { expansion ->
- script.execute(expansion, plugin.server.console, "unload")
- }
- script.unregisterListeners()
- script.configOption.reload()
- script.reload()
- sender.sendMessage(FormatHeader.INFO, languages["COMMAND-NEXUS.COMMANDS.SCRIPT.RELOAD.RELOADED-SCRIPT"].setPlaceholder("script_name" to script.name))
- return true
- }
- })
- .build()
-
- private val infoCommand = nextBuilder()
- .alias("info")
- .description(languages["COMMAND-NEXUS.COMMANDS.SCRIPT.INFO.DESCRIPTION"])
- .execute(object : CommandExecutor {
- override fun execute(sender: GlobalSender, parents: Array, args: Array): Boolean {
- val script = FastScript.instance.scriptManager.scripts[parents[parents.size - 2]] ?: let {
- // 似乎不会发生?
- sender.sendMessage(FormatHeader.WARN, languages["COMMAND-NEXUS.COMMANDS.SCRIPT.NOT-FOUND-SCRIPT"].setPlaceholder(
- "script_name" to parents[parents.size - 2])
- )
- return true
- }
-
- val displayParents = parents.slice(0..parents.size - 2).joinToString(" ")
-
- sender.sendMessage(FormatHeader.INFO, languages["COMMAND-NEXUS.COMMANDS.SCRIPT.INFO.TITLE"].setPlaceholder(
- mapOf("script_name" to script.name)))
-
- languages.getList("COMMAND-NEXUS.COMMANDS.SCRIPT.INFO.TEXTS").forEach { string ->
- sender.sendMessage(string.setPlaceholder(mapOf(
- "script_name" to script.name,
- "script_version" to script.version,
- "script_authors" to (if (script.authors.isEmpty()) "..." else script.authors.joinToString(", ")),
- "script_description" to script.description,
- "script_init_protected" to script.init.protected.toText(),
- "script_init_use_async" to script.init.useAsync.toText(),
- "script_main" to script.main,
- "script_bind_expansions" to script.bindExpansions().let { expansions ->
- if (expansions.isEmpty())
- return@let "Not more..."
- mutableListOf().also { signs -> expansions.forEach { expansion -> signs.add(expansion.sign) } }.joinToString()
- }
- )))
- }
-
- sender.sendMessage(TextComponent(" "), TextComponent("§7/$displayParents §fhelp").also {
- if (FSCommandNexus.safeMode) return@also
- it.hoverEvent = HoverEvent(HoverEvent.Action.SHOW_TEXT, Text(languages["COMMAND-NEXUS.HELPER.CLICK-INSERT-COMMAND"].setPlaceholder(
- mapOf("command" to "$displayParents help")
- )))
- it.clickEvent = ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/$displayParents help ")
- })
- sender.sendMessage()
-
- return true
- }
- })
- .build()
-
- override fun execute(sender: GlobalSender, parents: Array, args: Array): Boolean {
- if (sender !is GlobalPlayer && args.isNotEmpty()) {
- when (args[0].toLowerCase()) {
- ":reload" -> {
- reload()
- return true
- }
- ":clear" -> {
- subCommands.clear()
- return true
- }
- }
- }
- return super.execute(sender, parents, args)
- }
-
- @Synchronized
- fun reload() {
- subCommands.clear()
- FastScript.instance.scriptManager.scripts.forEach {
- val subCommand = nextBuilder()
- .alias(it.value.name)
- .description(languages["COMMAND-NEXUS.COMMANDS.SCRIPT.SUB-SCRIPT-DESCRIPTION"].setPlaceholder(mapOf("script_name" to it.key)))
- .execute(object : CommandExecutor {
- override fun execute(sender: GlobalSender, parents: Array, args: Array): Boolean {
- if (args.isEmpty()) {
- infoCommand.execute(sender, arrayOf(*parents, "info"), arrayOf())
- return true
- }
- return false
- }
- })
- .subCommand(runCommand)
- .subCommand(evaluateCommand)
- .subCommand(infoCommand)
- .also { builder ->
- if (!it.value.init.protected)
- builder.subCommand(reloadCommand)
- }
- .build()
- register(subCommand)
- }
- }
-
- companion object {
- lateinit var instance: ScriptCommand
-
- }
-
-}
\ No newline at end of file
diff --git a/common/src/main/kotlin/me/scoretwo/fastscript/command/commands/ToolsCommand.kt b/common/src/main/kotlin/me/scoretwo/fastscript/command/commands/ToolsCommand.kt
deleted file mode 100644
index 60f0815..0000000
--- a/common/src/main/kotlin/me/scoretwo/fastscript/command/commands/ToolsCommand.kt
+++ /dev/null
@@ -1,54 +0,0 @@
-package me.scoretwo.fastscript.command.commands
-
-import me.scoretwo.fastscript.api.format.FormatHeader
-import me.scoretwo.fastscript.command.SimpleCommand
-import me.scoretwo.fastscript.languages
-import me.scoretwo.fastscript.sendMessage
-import me.scoretwo.fastscript.setPlaceholder
-import me.scoretwo.utils.command.SubCommand
-import me.scoretwo.utils.command.executor.Executors
-import me.scoretwo.utils.sender.GlobalSender
-
-/**
- * @author Score2
- * @date 2021/2/22 17:33
- *
- * @project FastScript
- */
-class ToolsCommand: SimpleCommand(arrayOf("tools", "tool", "utils", "util")) {
-
- override var description = languages["COMMAND-NEXUS.COMMANDS.TOOLS.DESCRIPTION"]
-
- override var subCommands = mutableListOf(
- nextBuilder().alias("command", "cmd", "execute", "run")
- .description(languages["COMMAND-NEXUS.COMMANDS.TOOLS.COMMAND.DESCRIPTION"])
- .executor(object : Executors {
- override fun execute(sender: GlobalSender, parents: Array, args: Array): Boolean {
- if (args.isEmpty()) {
- return false
- }
- val command = args.sliceArray(1 until args.size).joinToString(" ")
- if (args[0].toLowerCase() == "@all") {
- plugin.server.getOnlinePlayers().forEach { plugin.server.dispatchCommand(it, command) }
- return true
- }
-
- val target = if (args[0].toLowerCase() == "@console") plugin.server.console else plugin.server.getPlayer(args[0]).let {
- if (it.isPresent) {
- it.get()
- } else {
- sender.sendMessage(FormatHeader.ERROR, languages["COMMAND-NEXUS.HELPER.PLAYER-IS-OFFLINE"].setPlaceholder("player_name" to args[0]))
- return true
- }
- }
- plugin.server.dispatchCommand(target, command)
- return true
- }
-
- override fun tabComplete(sender: GlobalSender, parents: Array, args: Array) =
- mutableListOf("@CONSOLE", "@ALL").also { list -> plugin.server.getOnlinePlayers().forEach { list.add(it.name) } }
- })
- .build()
- )
-
-}
\ No newline at end of file
diff --git a/common/src/main/kotlin/me/scoretwo/fastscript/config/SettingConfig.kt b/common/src/main/kotlin/me/scoretwo/fastscript/config/SettingConfig.kt
deleted file mode 100644
index 2a57e25..0000000
--- a/common/src/main/kotlin/me/scoretwo/fastscript/config/SettingConfig.kt
+++ /dev/null
@@ -1,47 +0,0 @@
-package me.scoretwo.fastscript.config
-
-import me.scoretwo.fastscript.plugin
-import me.scoretwo.utils.bukkit.configuration.yaml.file.YamlConfiguration
-import me.scoretwo.utils.bukkit.configuration.yaml.patchs.ignoreCase
-import java.io.File
-import java.util.*
-
-class SettingConfig: Config(File(plugin.dataFolder, "settings.yml")) {
-
- val version = "2"
-
- val defaultConfig = applyConfig(YamlConfiguration())
-
- fun applyConfig(cfg: YamlConfiguration): YamlConfiguration {
- cfg["Options"] = YamlConfiguration().also {
- it["Debug"] = false
- it["Language"] = "${Locale.getDefault()}"
- it["File-Listener"] = true
- it["Internal-Expansions"] = YamlConfiguration().also {
- it["JavaScript"] = true
- it["Scala"] = false
- }
- }
- cfg["Load-Script-Files"] = listOf("plugins/CustomScriptFolder")
- cfg["Default-Script-Options"] = YamlConfiguration().also {
- it["Main"] = "main"
- it["Meta"] = listOf("key:value")
- }
- cfg["Version"] = version
- return cfg
- }
-
- init {
- applyConfig(this)
- }
-
- override fun onReload() {
- if (getString(ignoreCase("version")) ?: "" != version) {
- defaultConfig.getKeys(true).forEach { if (!this.contains(it)) {
- this[it] = defaultConfig[it]
- } }
- save(file)
- }
- }
-
-}
\ No newline at end of file
diff --git a/common/src/main/kotlin/me/scoretwo/fastscript/expansion/javascript/JavaScriptExpansion.kt b/common/src/main/kotlin/me/scoretwo/fastscript/expansion/javascript/JavaScriptExpansion.kt
deleted file mode 100644
index bf6fde8..0000000
--- a/common/src/main/kotlin/me/scoretwo/fastscript/expansion/javascript/JavaScriptExpansion.kt
+++ /dev/null
@@ -1,13 +0,0 @@
-package me.scoretwo.fastscript.expansion.javascript
-
-import me.scoretwo.fastscript.expansion.typeengine.TypeEngineExpansion
-import org.openjdk.nashorn.api.scripting.NashornScriptEngineFactory
-import javax.script.ScriptEngine
-
-class JavaScriptExpansion: TypeEngineExpansion() {
- override val name = "JavaScript"
- override val sign = "nashorn"
- override val fileSuffix = "js"
- override val engine: ScriptEngine = scriptEngineManager.getEngineByName("nashorn") ?: NashornScriptEngineFactory().scriptEngine
-
-}
\ No newline at end of file
diff --git a/common/src/main/kotlin/me/scoretwo/fastscript/expansion/scala/ScalaExpansion.kt b/common/src/main/kotlin/me/scoretwo/fastscript/expansion/scala/ScalaExpansion.kt
deleted file mode 100644
index 44dee9e..0000000
--- a/common/src/main/kotlin/me/scoretwo/fastscript/expansion/scala/ScalaExpansion.kt
+++ /dev/null
@@ -1,17 +0,0 @@
-package me.scoretwo.fastscript.expansion.scala
-
-import me.scoretwo.fastscript.expansion.typeengine.TypeEngineExpansion
-import javax.script.ScriptEngine
-
-/**
- * @author Score2
- * @date 2021/2/26 2:29
- *
- * @project FastScript
- */
-class ScalaExpansion: TypeEngineExpansion() {
- override val name = "Scala"
- override val sign = "scala"
- override val fileSuffix = "scala"
- override val engine: ScriptEngine = scriptEngineManager.getEngineByName("scala") ?: scriptEngineManager.getEngineByName("scala")
-}
\ No newline at end of file
diff --git a/common/src/main/kotlin/me/scoretwo/fastscript/expansion/typeengine/ScriptInclude.kt b/common/src/main/kotlin/me/scoretwo/fastscript/expansion/typeengine/ScriptInclude.kt
deleted file mode 100644
index a8e67c3..0000000
--- a/common/src/main/kotlin/me/scoretwo/fastscript/expansion/typeengine/ScriptInclude.kt
+++ /dev/null
@@ -1,103 +0,0 @@
-package me.scoretwo.fastscript.expansion.typeengine
-
-import me.scoretwo.fastscript.api.format.FormatHeader
-import me.scoretwo.fastscript.api.script.custom.CustomScript
-import me.scoretwo.fastscript.expansion.typeengine.exception.IncludeFormatException
-import me.scoretwo.fastscript.expansion.typeengine.exception.TypeInferenceException
-import me.scoretwo.fastscript.plugin
-import me.scoretwo.fastscript.sendMessage
-import me.scoretwo.fastscript.expansion.typeengine.ScriptIncludeType.*
-import me.scoretwo.utils.bukkit.configuration.yaml.ConfigurationSection
-import me.scoretwo.utils.bukkit.configuration.yaml.patchs.ignoreCase
-import java.lang.reflect.Method
-
-@Deprecated("已弃用该类, 现有更好的方法代替它: js: Java.type(\"xxxx.xxxx\")")
-class ScriptInclude(
- type: ScriptIncludeType?,
- val obj: Pair?>?,
- val met: Pair?>?
-) {
-
- val type: ScriptIncludeType
-
- init {
- if (type == null) {
- if (hasObject() && hasObjectArgs())
- this.type = INIT
- else if (hasObject() && hasObjectArgs() && hasMethod())
- this.type = OBJECT
- else if (hasObject() && hasMethod())
- this.type = STATIC
- else
- throw TypeInferenceException("Don't to inference script's type")
- } else this.type = type
- }
-
- operator fun get(script: CustomScript): Any? {
- obj ?: throw IncludeFormatException()
- met ?: throw IncludeFormatException()
- val clazz = findClass(script, obj.first) ?: throw ClassNotFoundException()
- when (type) {
- OBJECT -> {
- val method = clazz.getMethod(met.first)
- val constructor = clazz.getDeclaredConstructor()
- constructor.isAccessible = true
- return accessMethod(script, clazz.newInstance(), method)
- }
- INIT -> {
- return try {
- val constructor = clazz.getDeclaredConstructor()
- constructor.isAccessible = true
- constructor.newInstance(*obj.second!!.toTypedArray())
- } catch (e: Exception) {
- plugin.server.console.sendMessage(FormatHeader.ERROR, "脚本 §c${script.name} §7执行初始化时发生错误, 错误如下:\n§8${e.stackTraceToString()}")
- null
- }
- }
- STATIC -> {
- val method = clazz.getMethod(met.first)
- return accessMethod(script, null, method)
- }
- }
- }
-
- fun hasObject() = obj != null
- fun hasObjectArgs() = if (hasObject()) obj!!.second != null else false
-
- fun hasMethod() = met != null
- fun hasMethodArgs() = if (hasMethod()) met!!.second != null else false
-
-
- fun findClass(script: CustomScript, target: String) = try {
- Class.forName(target)
- } catch (e: ClassNotFoundException) {
- plugin.server.console.sendMessage(FormatHeader.ERROR, "脚本 §c${script.name} §7没有找到类 §c${target}§7, 错误如下:\n§8${e.stackTraceToString()}")
- null
- }
-
- fun accessMethod(script: CustomScript, `object`: Any?, method: Method) = try {
- method.invoke(`object`, obj!!.second)
- } catch (e: Exception) {
- plugin.server.console.sendMessage(FormatHeader.ERROR, "脚本 §c${script.name} §7访问方法 §c${method.name} §7时发生错误, 错误如下:\n§8${e.stackTraceToString()}")
- null
- }
-
- companion object {
-
- fun fromSection(section: ConfigurationSection): ScriptInclude {
- val type = ScriptIncludeType.valueOf(section.getString(section.ignoreCase("type")))
-
- val obj: Pair?>?
- section.getConfigurationSection(section.ignoreCase("object")).also {
- obj = Pair(it.getString(it.ignoreCase("class")), it.getList(it.ignoreCase("args")))
- }
- val met: Pair?>?
- section.getConfigurationSection(section.ignoreCase("method")).also {
- met = Pair(it.getString(it.ignoreCase("name")), it.getList(it.ignoreCase("args")))
- }
- return ScriptInclude(type, obj, met)
- }
-
- }
-
-}
\ No newline at end of file
diff --git a/common/src/main/kotlin/me/scoretwo/fastscript/expansion/typeengine/ScriptIncludeType.kt b/common/src/main/kotlin/me/scoretwo/fastscript/expansion/typeengine/ScriptIncludeType.kt
deleted file mode 100644
index 4283b55..0000000
--- a/common/src/main/kotlin/me/scoretwo/fastscript/expansion/typeengine/ScriptIncludeType.kt
+++ /dev/null
@@ -1,8 +0,0 @@
-package me.scoretwo.fastscript.expansion.typeengine
-
-@Deprecated("已弃用该类, 现有更好的方法代替它: js: Java.type(\"xxxx.xxxx\")")
-enum class ScriptIncludeType {
- OBJECT,
- INIT,
- STATIC
-}
\ No newline at end of file
diff --git a/common/src/main/kotlin/me/scoretwo/fastscript/expansion/typeengine/TypeEngineExpansion.kt b/common/src/main/kotlin/me/scoretwo/fastscript/expansion/typeengine/TypeEngineExpansion.kt
deleted file mode 100644
index 5074977..0000000
--- a/common/src/main/kotlin/me/scoretwo/fastscript/expansion/typeengine/TypeEngineExpansion.kt
+++ /dev/null
@@ -1,186 +0,0 @@
-package me.scoretwo.fastscript.expansion.typeengine
-
-import me.scoretwo.fastscript.*
-import me.scoretwo.fastscript.api.expansion.FastScriptExpansion
-import me.scoretwo.fastscript.api.format.FormatHeader
-import me.scoretwo.fastscript.api.script.Script
-import me.scoretwo.fastscript.api.script.custom.CustomScript
-import me.scoretwo.fastscript.utils.assist
-import me.scoretwo.utils.sender.GlobalPlayer
-import me.scoretwo.utils.sender.GlobalSender
-import me.scoretwo.utils.server.globalServer
-import org.apache.commons.lang.StringUtils
-import javax.script.Invocable
-import javax.script.ScriptEngine
-import javax.script.ScriptEngineManager
-import javax.script.ScriptException
-
-abstract class TypeEngineExpansion: FastScriptExpansion() {
- abstract val engine: ScriptEngine
- override val needEval = true
-
- val scriptEngineManager = ScriptEngineManager(plugin.pluginClassLoader)
-
- private val engineTexts = mutableMapOf()
- private val engineScripts = mutableMapOf