Skip to content

Commit d23c63e

Browse files
committed
Enter the first round of testing.
1 parent 323ac35 commit d23c63e

File tree

13 files changed

+99
-101
lines changed

13 files changed

+99
-101
lines changed

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

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,19 @@ class FastScript(val plugin: ScriptPlugin) {
2727
instance = this
2828
me.scoretwo.fastscript.plugin = plugin
2929

30-
printLogo()
30+
arrayOf(
31+
"___________ __ _________ .__ __ ",
32+
"\\_ _____/____ _______/ |_/ _____/ ___________|__|______/ |_ ",
33+
" | __) \\__ \\ / ___/\\ __\\_____ \\_/ ___\\_ __ \\ \\____ \\ __\\",
34+
" | \\ / __ \\_\\___ \\ | | / \\ \\___| | \\/ | |_> > | ",
35+
" \\___ / (____ /____ > |__|/_______ /\\___ >__| |__| __/|__| ",
36+
" \\/ \\/ \\/ \\/ \\/ |__| ",
37+
""
38+
).forEach {
39+
plugin.server.console.sendMessage("§3$it")
40+
}
3141

32-
plugin.server.console.sendMessage("§3FastScript initializing...")
42+
plugin.server.console.sendMessage("§3FastScript[§bV${plugin.description.version}§3] initializing...")
3343

3444
if (!plugin.dataFolder.exists()) {
3545
plugin.dataFolder.mkdirs()
@@ -38,7 +48,9 @@ class FastScript(val plugin: ScriptPlugin) {
3848
settings = SettingConfig()
3949

4050
language = LanguageManager()
41-
language.current = language.languages[settings.getString("Options.Language")]!!
51+
language.current = language.languages[settings.getString("Options.Language")] ?: language.defaultLanguage.also {
52+
plugin.server.console.sendMessage(FormatHeader.ERROR, "Language loading failed. The file may not exist. The default language will be used: en_US")
53+
}
4254

4355
commandNexus = ScriptCommandNexus()
4456
scriptManager = ScriptManager()
@@ -63,34 +75,6 @@ class FastScript(val plugin: ScriptPlugin) {
6375
scriptManager.loadScripts()
6476
}
6577

66-
/**
67-
* 用于随机点亮 FastScript 的 Logo.
68-
* 该创意来源于 TrMenu
69-
* @author Arasple
70-
*/
71-
fun printLogo() = arrayOf(
72-
"___________ __ _________ .__ __ ",
73-
"\\_ _____/____ _______/ |_/ _____/ ___________|__|______/ |_ ",
74-
" | __) \\__ \\ / ___/\\ __\\_____ \\_/ ___\\_ __ \\ \\____ \\ __\\",
75-
" | \\ / __ \\_\\___ \\ | | / \\ \\___| | \\/ | |_> > | ",
76-
" \\___ / (____ /____ > |__|/_______ /\\___ >__| |__| __/|__| ",
77-
" \\/ \\/ \\/ \\/ \\/ |__| "
78-
).also {
79-
it.forEachIndexed { index, raw ->
80-
if (raw.isNotBlank()) {
81-
val line = raw.toCharArray()
82-
val width = (2..8).random()
83-
var randomIndex: Int
84-
do {
85-
randomIndex = (2..line.size - width).random()
86-
} while (String(line.copyOfRange(randomIndex, randomIndex + width)).isBlank())
87-
val replace = String(line.copyOfRange(randomIndex, randomIndex + width))
88-
it[index] = String(line).replaceFirst(replace, "§${arrayOf('a', 'b', '2').random()}$replace§8")
89-
}
90-
}
91-
plugin.server.console.sendMessage(it)
92-
}
93-
9478
companion object {
9579
lateinit var instance: FastScript
9680

FastScript-common/src/main/kotlin/me/scoretwo/fastscript/api/config/Config.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,14 @@ abstract class Config(val file: File) : YamlConfiguration() {
1010
}
1111

1212
open fun reload() {
13+
if (!file.exists()) {
14+
file.parentFile.mkdirs()
15+
save(file)
16+
} else {
17+
this.load(file)
18+
save(file)
19+
}
1320
onReload()
14-
this.load(file)
1521
}
1622

1723
abstract fun onReload()

FastScript-common/src/main/kotlin/me/scoretwo/fastscript/api/language/Language.kt

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,19 @@ class Language {
2929
}
3030

3131
val config = YamlConfiguration().also {
32-
it.addDefault("FORMAT-HEADER", YamlConfiguration().also {
33-
it.addDefault("INFO", "&7[&2Fast&aScript&7] &bINFO &8| &7")
34-
it.addDefault("WARN", "&7[&2Fast&aScript&7] &eWARN &8| &7")
35-
it.addDefault("ERROR", "&7[&2Fast&aScript&7] &cERROR &8| &7")
36-
it.addDefault("TIPS", "&7[&2Fast&aScript&7] &2TIPS &8| &7")
37-
it.addDefault("HOOKED", "&7[&2Fast&aScript&7] &6HOOKED &8| &7")
38-
it.addDefault("DEBUG", "&7[&2Fast&aScript&7] &3DEBUG &8| &7")
32+
it.set("FORMAT-HEADER", YamlConfiguration().also {
33+
it.set("INFO", "&7[&2Fast&aScript&7] &bINFO &8| &7")
34+
it.set("WARN", "&7[&2Fast&aScript&7] &eWARN &8| &7")
35+
it.set("ERROR", "&7[&2Fast&aScript&7] &cERROR &8| &7")
36+
it.set("TIPS", "&7[&2Fast&aScript&7] &2TIPS &8| &7")
37+
it.set("HOOKED", "&7[&2Fast&aScript&7] &6HOOKED &8| &7")
38+
it.set("DEBUG", "&7[&2Fast&aScript&7] &3DEBUG &8| &7")
39+
})
40+
it.set("COMMAND-SECTIONS", YamlConfiguration().also {
41+
it.set("COMMAND_ONLY_CONSOLE", "This command can only be executed on the console.")
42+
it.set("COMMAND_ONLY_PLAYER", "This command can only be executed by the player.")
43+
it.set("COMMAND_NO_PERMISSION", "You do not have permission to execute the command.")
44+
it.set("COMMAND_UNKNOWN_USAGE", "&cUsage &e{usage_error} &cis incorrect, you may want to use &e{usage_guess}")
3945
})
4046

4147
}

FastScript-common/src/main/kotlin/me/scoretwo/fastscript/config/SettingConfig.kt

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,25 @@ package me.scoretwo.fastscript.config
33
import me.scoretwo.fastscript.plugin
44
import me.scoretwo.utils.bukkit.configuration.yaml.file.YamlConfiguration
55
import me.scoretwo.utils.bukkit.configuration.yaml.patchs.saveConfiguration
6+
import me.scoretwo.utils.server.task.TaskType
67
import java.io.File
78

8-
class SettingConfig(): Config(File(plugin.dataFolder, "settings.yml")) {
9+
class SettingConfig: Config(File(plugin.dataFolder, "settings.yml")) {
910

10-
val default = YamlConfiguration().also {
11-
it.set("Options", YamlConfiguration().also {
11+
init {
12+
set("Options", YamlConfiguration().also {
1213
it.set("Debug", false)
1314
it.set("Language", "en_US")
1415
it.set("File-Listener", true)
1516
})
16-
it.set("Load-Script-Files", listOf("plugins/CustomScriptFolder"))
17-
it.set("Default-Script-Options", YamlConfiguration().also {
17+
set("Load-Script-Files", listOf("plugins/CustomScriptFolder"))
18+
set("Default-Script-Options", YamlConfiguration().also {
1819
it.set("Main", "main")
1920
it.set("Meta", listOf("key:value"))
2021
})
2122
}
2223

2324
override fun onReload() {
24-
if (!file.exists()) {
25-
file.parentFile.mkdirs()
26-
file.saveConfiguration(default)
27-
}
2825
}
2926

3027
}

FastScript-plugin/build.gradle.kts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import org.gradle.kotlin.dsl.support.compileKotlinScriptModuleTo
2+
13
plugins {
24
kotlin("jvm")
35
id("org.jetbrains.dokka")
@@ -22,6 +24,7 @@ dependencies {
2224
implementation("net.md-5:bungeecord-chat:1.16-R0.4-SNAPSHOT")
2325
implementation("org.bstats:bstats-bukkit:1.7")
2426
implementation("commons-io:commons-io:2.7")
27+
implementation("commons-lang:commons-lang:2.6")
2528

2629
implementation("me.scoretwo:commons-syntaxes:${rootProject.extra.get("commonsVersion")}")
2730
implementation("me.scoretwo:commons-command:${rootProject.extra.get("commonsVersion")}")
@@ -49,14 +52,16 @@ tasks.withType<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar> {
4952
include(dependency("org.bstats:bstats-bukkit:1.7"))
5053

5154
include(dependency("commons-io:commons-io:2.7"))
55+
include(dependency("commons-lang:commons-lang:2.6"))
5256

5357
include(dependency("me.scoretwo:commons-syntaxes:${rootProject.extra.get("commonsVersion")}"))
5458
include(dependency("me.scoretwo:commons-command:${rootProject.extra.get("commonsVersion")}"))
5559
include(dependency("me.scoretwo:commons-server:${rootProject.extra.get("commonsVersion")}"))
5660
include(dependency("me.scoretwo:commons-bukkit-configuration:${rootProject.extra.get("commonsVersion")}"))
5761
}
58-
relocate("org.apache","me.scoretwo.utils.libs.org.apache")
59-
relocate("org.bstats","me.scoretwo.utils.libs.org.bstats")
62+
relocate("kotlin", "me.scoretwo.utils.shaded.kotlin")
63+
relocate("org.apache","me.scoretwo.utils.shaded.org.apache")
64+
relocate("org.bstats","me.scoretwo.utils.shaded.org.bstats")
6065

6166
classifier = null
6267
}
@@ -74,7 +79,7 @@ tasks.processResources {
7479
from("src/main/resources") {
7580
include("bungee.yml")
7681
expand(mapOf(
77-
"name" to project.name,
82+
"name" to rootProject.name,
7883
"main" to "${rootProject.group}.${rootProject.name.toLowerCase()}.bungee.BungeeBootStrap",
7984
"version" to project.version,
8085
"description" to project.description
@@ -83,17 +88,17 @@ tasks.processResources {
8388
from("src/main/resources") {
8489
include("mcmod.info")
8590
expand(mapOf(
86-
"id" to project.name.toLowerCase(),
87-
"name" to project.name,
91+
"id" to rootProject.name.toLowerCase(),
92+
"name" to rootProject.name,
8893
"version" to project.version,
8994
"description" to project.description
9095
))
9196
}
9297
from("src/main/resources") {
9398
include("velocity-plugin.json")
9499
expand(mapOf(
95-
"id" to project.name.toLowerCase(),
96-
"name" to project.name,
100+
"id" to rootProject.name.toLowerCase(),
101+
"name" to rootProject.name,
97102
"version" to project.version,
98103
"main" to "${rootProject.group}.${rootProject.name.toLowerCase()}.velocity.VelocityBootStrap",
99104
"description" to project.description

FastScript-plugin/src/main/resources/mcmod.info

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
"name": "${name}",
55
"version": "${version}",
66
"description": "${description}",
7-
"authorList": ["Score2"]
7+
"authorList": ["Score2"],
8+
"dependencies": [
9+
"placeholderapi"
10+
]
811
}
912
]

build.gradle.kts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
kotlin("jvm") version "1.4.21"
2+
kotlin("jvm") version "1.4.30"
33
id("org.jetbrains.dokka") version "1.4.10.2" apply false
44
id("org.jlleitschuh.gradle.ktlint") version "9.4.1" apply false
55
id("com.github.johnrengelman.shadow") version "6.1.0"
@@ -15,8 +15,8 @@ description = "FastScript is a Spigot plugin, which can run JavaScript-based scr
1515
defaultTasks = mutableListOf("publishToMavenLocal")
1616

1717
extra.apply {
18-
set("commonsVersion", "2.0.5-SNAPSHOT")
19-
set("kotlinVersion", "1.4.21")
18+
set("commonsVersion", "2.0.7-SNAPSHOT")
19+
set("kotlinVersion", "1.4.30")
2020
}
2121

2222
allprojects {
@@ -43,4 +43,8 @@ subprojects {
4343
group = rootProject.group
4444
version = rootProject.version
4545
description = rootProject.description
46+
47+
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
48+
kotlinOptions.jvmTarget = "1.8"
49+
}
4650
}

version-control/FastScript-sponge/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ plugins {
1010

1111
blossom {
1212
replaceTokenIn("src/main/kotlin/me/scoretwo/fastscript/sponge/SpongeBootStrap.kt")
13-
replaceToken("%%id%%", project.name.toLowerCase())
14-
replaceToken("%%name%%", project.name)
13+
replaceToken("%%id%%", rootProject.name.toLowerCase())
14+
replaceToken("%%name%%", rootProject.name)
1515
replaceToken("%%version%%", project.version)
1616
replaceToken("%%description%%", project.description)
1717
}

version-control/FastScript-sponge/src/main/kotlin/me/scoretwo/fastscript/sponge/SpongeBootStrap.kt

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,20 @@ import me.scoretwo.utils.sponge.plugin.toGlobalPlugin
55
import org.spongepowered.api.event.Listener
66
import org.spongepowered.api.event.game.state.GameInitializationEvent
77
import org.spongepowered.api.event.game.state.GamePreInitializationEvent
8-
import org.spongepowered.api.event.game.state.GameStoppingEvent
98
import org.spongepowered.api.plugin.Dependency
109
import org.spongepowered.api.plugin.Plugin
10+
import org.spongepowered.api.event.game.state.GameStoppingEvent
1111
import org.spongepowered.api.plugin.PluginContainer
1212

1313
@Plugin(
14-
id = "%%id%%",
15-
name = "%%name%%",
14+
id = "fastscript",
15+
name = "FastScript",
16+
version = "1.0.1-SNAPSHOT",
17+
description = "FastScript is a Spigot plugin, which can run JavaScript-based scripts more efficiently.",
1618
authors = ["Score2"],
17-
description = "%%description%%",
18-
dependencies = [Dependency(id = "placeholderapi", optional = true)],
19-
version = "%%version%%"
19+
dependencies = [Dependency(id = "placeholderapi", optional = true)]
2020
)
21-
class SpongeBootStrap {
22-
23-
@Inject
24-
lateinit var pluginContainer: PluginContainer
21+
class SpongeBootStrap @Inject constructor(val pluginContainer: PluginContainer) {
2522

2623
val spongePlugin = SpongePlugin(pluginContainer.toGlobalPlugin())
2724

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package me.scoretwo.fastscript.sponge
22

3-
import me.rojo8399.placeholderapi.PlaceholderService
43
import me.scoretwo.fastscript.FastScript
54
import me.scoretwo.fastscript.api.format.FormatHeader
65
import me.scoretwo.fastscript.api.plugin.ScriptPlugin
@@ -10,20 +9,9 @@ import me.scoretwo.utils.plugin.GlobalPlugin
109
import me.scoretwo.utils.sender.GlobalPlayer
1110
import me.scoretwo.utils.sender.GlobalSender
1211
import me.scoretwo.utils.sponge.command.registerSpongeCommands
13-
import me.scoretwo.utils.sponge.command.toGlobalSender
1412
import me.scoretwo.utils.sponge.command.toSpongePlayer
1513
import me.scoretwo.utils.sponge.command.toSpongeSender
16-
import net.md_5.bungee.api.ChatColor
1714
import org.spongepowered.api.Sponge
18-
import org.spongepowered.api.command.CommandResult
19-
import org.spongepowered.api.command.spec.CommandSpec
20-
import org.spongepowered.api.event.Listener
21-
import org.spongepowered.api.event.game.state.GameAboutToStartServerEvent
22-
import org.spongepowered.api.event.game.state.GameStoppingServerEvent
23-
import org.spongepowered.api.plugin.Dependency
24-
import org.spongepowered.api.plugin.Plugin
25-
import org.spongepowered.api.text.Text
26-
import java.io.File
2715

2816
class SpongePlugin(val plugin: GlobalPlugin): ScriptPlugin(plugin) {
2917

@@ -33,13 +21,13 @@ class SpongePlugin(val plugin: GlobalPlugin): ScriptPlugin(plugin) {
3321

3422
override fun enable() {
3523
FastScript.instance.onReload()
36-
PlaceholderAPIHook.placeholderService = Sponge.getServiceManager().provideUnchecked(PlaceholderService::class.java)
24+
PlaceholderAPIHook.initializePlaceholder()
3725

3826
FastScript.instance.commandNexus.registerSpongeCommands()
3927
}
4028

4129
override fun setPlaceholder(player: GlobalPlayer, string: String): String {
42-
return PlaceholderAPIHook.placeholderService.replaceSourcePlaceholders(string, player.toSpongePlayer()).toPlain()
30+
return PlaceholderAPIHook.parsePlaceholder(string, player.toSpongePlayer())
4331
}
4432

4533
override fun toOriginalSender(sender: GlobalSender) = sender.toSpongeSender()
@@ -49,15 +37,8 @@ class SpongePlugin(val plugin: GlobalPlugin): ScriptPlugin(plugin) {
4937
override fun toOriginalServer(): Any? = Sponge.getServer()
5038

5139
override fun reload() {
52-
if (PAPIHook == null) {
53-
if (Sponge.getPluginManager().isLoaded("placeholderapi")) {
54-
PAPIHook = PlaceholderAPIHook(this)
55-
plugin.server.console.sendMessage(FormatHeader.HOOKED, "成功挂钩 §ePlaceholderAPI!")
56-
}
40+
if (PlaceholderAPIHook.initializePlaceholder()) {
41+
plugin.server.console.sendMessage(FormatHeader.HOOKED, "成功挂钩 §ePlaceholderAPI!")
5742
}
5843
}
59-
60-
companion object {
61-
private var PAPIHook: PlaceholderAPIHook? = null
62-
}
6344
}

0 commit comments

Comments
 (0)