Skip to content

Commit 2dc7945

Browse files
committed
Fixed a lot of bugs.
The plugin can now be loaded normally!(Limited to Bukkit and Bungeecord)
1 parent 692194a commit 2dc7945

File tree

13 files changed

+127
-59
lines changed

13 files changed

+127
-59
lines changed

build.gradle

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ defaultTasks 'clean', 'build', 'test', 'shadowJar'
2424
repositories {
2525
jcenter()
2626
mavenCentral()
27+
maven {url 'https://hub.spigotmc.org/nexus/content/groups/public/'}
2728
maven {url 'https://jitpack.io'}
2829
maven {url 'http://repo.drnaylor.co.uk/artifactory/list/minecraft'}
2930
maven {url 'https://repo.velocitypowered.com/snapshots/'}
@@ -43,6 +44,7 @@ dependencies {
4344
compile 'org.jetbrains.kotlin:kotlin-stdlib'
4445
implementation 'org.yaml:snakeyaml:1.27'
4546
implementation 'org.apache.commons:commons-lang3:3.10'
47+
implementation 'com.google.code.gson:gson:2.8.6'
4648
implementation fileTree(dir: 'libs', includes: ['*.jar'])
4749

4850
// Sponge
@@ -56,6 +58,7 @@ dependencies {
5658

5759
// Bungee
5860
implementation 'net.md-5:bungeecord-api:1.16-R0.3'
61+
implementation 'net.md-5:bungeecord-chat:1.16-R0.4'
5962

6063
// Velocity
6164
implementation 'com.velocitypowered:velocity-api:1.0.11-SNAPSHOT'
@@ -65,17 +68,18 @@ shadowJar {
6568
dependencies {
6669
include(dependency('org.bstats:bstats-bukkit:1.7'))
6770
include(dependency('commons-io:commons-io:2.7'))
71+
include(dependency('net.md-5:bungeecord-chat:1.16-R0.4'))
6872
include(dependency('org.jetbrains.kotlin:kotlin-stdlib'))
6973
include(dependency(fileTree(dir: 'libs', includes: ['*.jar'])))
7074
}
71-
relocate("org.bstats", "me.scoretwo.utils.bstats")
72-
relocate("org.apache.commons.io", "me.scoretwo.utils.apache.commons.io")
75+
relocate("org.bstats", "me.scoretwo.utils.libs.bstats")
76+
relocate("org.apache.commons.io", "me.scoretwo.utils.libs.apache.commons.io")
7377
archiveFileName = "${project.name}-${project.version}.jar"
7478
}
7579

76-
artifacts {
80+
/*artifacts {
7781
archives shadowJar
78-
}
82+
}*/
7983

8084
processResources {
8185
from(sourceSets.main.resources.srcDirs) {
@@ -110,7 +114,7 @@ processResources {
110114
expand(
111115
'modid': "fastscript",
112116
'name': project.name,
113-
'main': project.group + "." + project.name.toLowerCase() + ".veloity.VeloityPlugin",
117+
'main': project.group + "." + project.name.toLowerCase() + ".velocity.VelocityPlugin",
114118
'version': project.version,
115119
'description': project.description,
116120
)
-479 Bytes
Binary file not shown.

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

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ package me.scoretwo.fastscript
33
import me.scoretwo.fastscript.api.plugin.FastScriptMain
44
import me.scoretwo.fastscript.api.script.ScriptManager
55
import me.scoretwo.fastscript.commands.CommandManager
6-
import me.scoretwo.fastscript.config.MessageConfig
76
import me.scoretwo.fastscript.config.SettingConfig
7+
import me.scoretwo.fastscript.utils.Utils
88
import me.scoretwo.utils.configuration.patchs.getLowerCaseNode
99
import java.io.File
10+
import java.io.IOException
11+
import java.io.InputStream
12+
import java.net.URL
1013

1114
class FastScript(main: FastScriptMain) {
1215

@@ -27,6 +30,7 @@ class FastScript(main: FastScriptMain) {
2730
instance = this
2831
CONSOLE = main.CONSOLE
2932
printLogo()
33+
println("FastScript 正在初始化...")
3034

3135
dataFolder = main.getDataFolder()
3236
classLoader = main.getPluginClassLoader()
@@ -40,48 +44,64 @@ class FastScript(main: FastScriptMain) {
4044
SettingConfig.init()
4145
}
4246

43-
/**
47+
fun getResource(filename: String): InputStream? {
48+
return try {
49+
val url: URL = classLoader.getResource(filename) ?: return null
50+
val connection = url.openConnection()
51+
connection.useCaches = false
52+
connection.getInputStream()
53+
} catch (ex: IOException) {
54+
null
55+
}
56+
}
57+
58+
/**
4459
* 初始化内置脚本
4560
* 暂时弃坑
4661
*/
4762
fun initInternalScripts() {
4863

4964
}
5065

66+
fun initLanguageFiles() {
67+
Utils.saveDefaultResource(File("${dataFolder}/languages", "en_US.yml"), getResource("lang/en_US.yml")!!)
68+
Utils.saveDefaultResource(File("${dataFolder}/languages", "zh_CN.yml"), getResource("lang/zh_CN.yml")!!)
69+
}
70+
5171
fun onReload() {
5272
if (!dataFolder.exists()) {
5373
dataFolder.mkdirs()
5474
}
5575
main.onReload()
76+
initLanguageFiles()
5677
initInternalScripts()
5778
scriptManager.loadScripts()
5879
commandManager.initCommands()
5980
}
6081

61-
/**
82+
/**
6283
* 用于随机点亮 FastScript 的 Logo.
6384
* 该创意来源于 TrMenu
6485
* @author Arasple
6586
*/
66-
6787
fun printLogo() = arrayOf(
68-
"___________ __ _________ .__ __ ",
69-
"\\_ _____/____ _______/ |_/ _____/ ___________|__|______/ |_ ",
70-
" | __) \\__ \\ / ___/\\ __\\_____ \\_/ ___\\_ __ \\ \\____ \\ __\\",
71-
" | \\ / __ \\_\\___ \\ | | / \\ \\___| | \\/ | |_> > | ",
72-
" \\___ / (____ /____ > |__|/_______ /\\___ >__| |__| __/|__| ",
73-
" \\/ \\/ \\/ \\/ \\/ |__| "
74-
).let {
88+
"___________ __ _________ .__ __ ",
89+
"\\_ _____/____ _______/ |_/ _____/ ___________|__|______/ |_ ",
90+
" | __) \\__ \\ / ___/\\ __\\_____ \\_/ ___\\_ __ \\ \\____ \\ __\\",
91+
" | \\ / __ \\_\\___ \\ | | / \\ \\___| | \\/ | |_> > | ",
92+
" \\___ / (____ /____ > |__|/_______ /\\___ >__| |__| __/|__| ",
93+
" \\/ \\/ \\/ \\/ \\/ |__| "
94+
).let {
7595
it.forEachIndexed { index, raw ->
7696
if (raw.isNotBlank()) {
7797
val line = raw.toCharArray()
78-
val width = (2..6).random()
98+
val width = (2..8).random()
7999
var randomIndex: Int
80100
do {
81101
randomIndex = (2..line.size - width).random()
82102
} while (String(line.copyOfRange(randomIndex, randomIndex + width)).isBlank())
83103
val replace = String(line.copyOfRange(randomIndex, randomIndex + width))
84-
it[index] = String(line).replaceFirst(replace, "§${arrayOf('9', 'b', '3').random()}$replace§8")
104+
it[index] = String(line).replaceFirst(replace, "§${arrayOf('a', 'b', '2').random()}$replace§8")
85105
}
86106
}
87107
CONSOLE.sendMessage(it)
@@ -172,23 +192,23 @@ fun Any.hasPermission(string: String): Boolean {
172192
}
173193

174194

175-
fun Any.sendMessage(formatHeader: FormatHeader, strings: Array<String>, colorIndex: Boolean = false) {
195+
fun Any.sendMessage(formatHeader: FormatHeader, strings: Array<String>, colorIndex: Boolean = true) {
176196
strings.forEach {
177197
this.sendMessage(formatHeader, it, colorIndex)
178198
}
179199
}
180200

181-
fun Any.sendMessage(formatHeader: FormatHeader, string: String, colorIndex: Boolean = false) {
182-
this.sendMessage("${
183-
SettingConfig.instance.defaultLanguage.getString(SettingConfig.instance.defaultLanguage.getLowerCaseNode("format-header.${formatHeader.name.toLowerCase()}"))
184-
}${string}", colorIndex)
201+
fun Any.sendMessage(formatHeader: FormatHeader, string: String, colorIndex: Boolean = true) {
202+
this.sendMessage(
203+
"${SettingConfig.instance.defaultLanguage.getString(SettingConfig.instance.defaultLanguage.getLowerCaseNode("format-header.${formatHeader.name.toLowerCase()}"))}${string}", colorIndex
204+
)
185205
}
186206

187-
fun Any.sendMessage(string: String, colorIndex: Boolean = false) {
207+
fun Any.sendMessage(string: String, colorIndex: Boolean = true) {
188208
FastScript.instance.sendMessage(this, string, colorIndex)
189209
}
190210

191-
fun Any.sendMessage(strings: Array<String>, colorIndex: Boolean = false) {
211+
fun Any.sendMessage(strings: Array<String>, colorIndex: Boolean = true) {
192212
strings.forEach {
193213
this.sendMessage(it, colorIndex)
194214
}

src/main/kotlin/me/scoretwo/fastscript/api/script/Script.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ abstract class Script {
2626

2727
lateinit var scriptEngine: ScriptEngine
2828

29-
constructor(file: File): this(file.name.substring(0, file.name.indexOf(".") - 1), FileInputStream(file)) {
29+
constructor(file: File): this(file.name.substring(0, file.name.indexOf(".") + 1), FileInputStream(file)) {
3030
this.scriptFile = file
3131
}
3232

src/main/kotlin/me/scoretwo/fastscript/api/script/ScriptManager.kt

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package me.scoretwo.fastscript.api.script
22

33
import me.scoretwo.fastscript.FastScript
4+
import me.scoretwo.fastscript.FormatHeader
45
import me.scoretwo.fastscript.config.SettingConfig
6+
import me.scoretwo.fastscript.sendMessage
7+
import me.scoretwo.utils.configuration.patchs.getLowerCaseNode
58
import java.io.File
69

710
class ScriptManager {
@@ -21,23 +24,38 @@ class ScriptManager {
2124
scripts.add(CustomScript(file))
2225
}
2326

24-
/**
27+
/**
2528
* 暂时同步, 异步以后写
2629
*/
2730
@Synchronized
2831
fun loadScripts() {
2932
scripts.clear()
33+
defaultScriptPath.mkdirs()
3034
defaultScriptPath.listFiles()?.forEach { loadScript(it) }
3135

32-
for (file in SettingConfig.instance.scriptPaths) {
33-
if (file.isDirectory) {
34-
file.listFiles()?.forEach { loadScript(it) }
35-
} else {
36-
loadScript(file)
37-
}
38-
}
36+
SettingConfig.instance.getStringList(SettingConfig.instance.getLowerCaseNode("load-script-files")).forEach {
37+
val file = File(it)
3938

39+
if (file.exists()) selectScriptFiles(file).forEach { loadScript(it) }
4040

41+
}
4142
}
4243

44+
/**
45+
* 选取脚本文件
46+
* 该创意来源于 TrMenu
47+
* @author Arasple
48+
*/
49+
fun selectScriptFiles(file: File): MutableList<File> =
50+
mutableListOf<File>().let { files ->
51+
if (file.isDirectory) {
52+
file.listFiles()?.forEach {
53+
files.addAll(selectScriptFiles(it))
54+
}
55+
} else if (!file.name.startsWith("#") && file.name.endsWith(".js", true)) {
56+
files.add(file)
57+
}
58+
return@let files
59+
}
60+
4361
}

src/main/kotlin/me/scoretwo/fastscript/api/script/options/ScriptOption.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class ScriptOption(val engine: String, val import: MutableList<ScriptImport>, va
1717
val importSection = section.getConfigurationSection(section.getLowerCaseNode("import"))!!
1818

1919
for (name in importSection.getKeys(false)) {
20-
import.add(ScriptImport.fromConfig(name, section.getConfigurationSection(name)!!))
20+
import.add(ScriptImport.fromConfig(name, importSection.getConfigurationSection(name)!!))
2121
}
2222

2323
return ScriptOption(engine, import, main)

src/main/kotlin/me/scoretwo/fastscript/api/script/options/imports/ScriptImport.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ class ScriptImport(val name: String, val type: ScriptImportType, val obj: Object
1313

1414
fun fromConfig(name: String, section: ConfigurationSection): ScriptImport {
1515
val stringType = section.getString(section.getLowerCaseNode("type"))!!.toUpperCase()
16-
val type = if (ScriptImportType.values().contains(ScriptImportType.valueOf(stringType)))
17-
ScriptImportType.valueOf(stringType)
18-
else
19-
ScriptImportType.UNKNOWN
16+
val type = ScriptImportType.fromString(stringType)
2017
val objectSection = section.getConfigurationSection(section.getLowerCaseNode("object"))!!
2118
val obj = Object(objectSection.getString(objectSection.getLowerCaseNode("class"))!!,
2219
if (objectSection.contains(objectSection.getLowerCaseNode("args")))
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
package me.scoretwo.fastscript.api.script.options.imports
22

33
enum class ScriptImportType {
4-
OBJECT_INIT, OBJECT, STATIC, UNKNOWN
4+
OBJECT_INIT, OBJECT, STATIC, UNKNOWN;
5+
6+
companion object {
7+
fun fromString(string: String): ScriptImportType {
8+
for (value in ScriptImportType.values()) {
9+
if (value.name == string) {
10+
return valueOf(string)
11+
}
12+
}
13+
return UNKNOWN
14+
}
15+
}
516
}

src/main/kotlin/me/scoretwo/fastscript/config/SettingConfig.kt

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package me.scoretwo.fastscript.config
22

33
import me.scoretwo.fastscript.FastScript
44
import me.scoretwo.fastscript.api.script.options.ScriptOption
5+
import me.scoretwo.fastscript.utils.Utils
56
import me.scoretwo.utils.configuration.patchs.getLowerCaseNode
67
import me.scoretwo.utils.language.save
78
import java.io.File
@@ -12,19 +13,15 @@ class SettingConfig(file: File): Config(file) {
1213

1314
lateinit var defaultLanguage: MessageConfig
1415

15-
val scriptPaths = mutableListOf<File>()
16-
1716
init {
1817
instance = this
1918
onReload()
2019
}
2120

2221
override fun onReload() {
2322
load(file)
24-
for (s in getStringList(getLowerCaseNode("load-script-files"))) {
25-
scriptPaths.add(File(s))
26-
}
2723

24+
FastScript.instance.initLanguageFiles()
2825
defaultScriptOption = ScriptOption.fromConfig(getConfigurationSection(getLowerCaseNode("default-script-options"))!!)
2926
defaultLanguage = MessageConfig(File(
3027
"${FastScript.instance.dataFolder}/languages",
@@ -37,9 +34,7 @@ class SettingConfig(file: File): Config(file) {
3734
fun init() {
3835
val file = File(FastScript.instance.dataFolder, "settings.yml")
3936

40-
if (!file.exists()) {
41-
file.save(FastScript.instance.classLoader.getResourceAsStream("/settings.yml")!!)
42-
}
37+
Utils.saveDefaultResource(file, FastScript.instance.getResource("settings.yml")!!)
4338

4439
SettingConfig(file)
4540
}

src/main/kotlin/me/scoretwo/fastscript/sponge/SpongePlugin.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import me.scoretwo.fastscript.FormatHeader
66
import me.scoretwo.fastscript.api.plugin.FastScriptMain
77
import me.scoretwo.fastscript.sendMessage
88
import me.scoretwo.fastscript.sponge.hook.PlaceholderAPIHook
9+
import net.md_5.bungee.api.ChatColor
910
import org.spongepowered.api.Sponge
1011
import org.spongepowered.api.command.CommandResult
1112
import org.spongepowered.api.command.CommandSource
@@ -87,7 +88,7 @@ class SpongePlugin: FastScriptMain {
8788
}
8889

8990
override fun translateStringColors(string: String): String {
90-
return string.replace("§", "&")
91+
return ChatColor.translateAlternateColorCodes('&', string)
9192
}
9293

9394
fun asSender(sender: Any): CommandSource? {

0 commit comments

Comments
 (0)