Skip to content

Commit aa37124

Browse files
committed
Fixed bugs.
1 parent bd97261 commit aa37124

File tree

18 files changed

+463
-137
lines changed

18 files changed

+463
-137
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ description = "FastScript is a Spigot plugin, which can run JavaScript-based scr
1414
defaultTasks = mutableListOf("ShadowJar", "publishToMavenLocal")
1515

1616
extra.apply {
17-
set("commonsVersion", "2.0.10-SNAPSHOT")
17+
set("commonsVersion", "2.0.11-SNAPSHOT")
1818
set("kotlinVersion", "1.4.30")
1919
}
2020

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ fun GlobalSender.sendMessage(text: String, placeholders: Map<String, String>) {
157157

158158
fun String.setPlaceholder(player: GlobalPlayer) = FastScript.instance.setPlaceholder(player, this)
159159

160+
161+
fun String.setPlaceholder(placeholder: Pair<String, String>, player: GlobalPlayer? = null) = this.setPlaceholder(mapOf(placeholder), player)
162+
160163
fun String.setPlaceholder(placeholders: Map<String, String>, player: GlobalPlayer? = null): String {
161164
var rawText = if (player == null) this else setPlaceholder(player)
162165
placeholders.forEach {

common/src/main/kotlin/me/scoretwo/fastscript/api/expansion/ExpansionManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class ExpansionManager {
8989
if (fail == 0)
9090
plugin.server.console.sendMessage(format, languages["LOADED-COUNTS-PROCESS-SUCCESS"].setPlaceholder(placeholders))
9191
else
92-
plugin.server.console.sendMessage(format, languages["LOADED-COUNTS-PROCESS-HAS-FAILED"].setPlaceholder(placeholders))
92+
plugin.server.console.sendMessage(format, languages["LOADED-COUNTS-PROCESS-SUCCESS-HAS-FAILED"].setPlaceholder(placeholders))
9393
}
9494

9595
private fun fromFileExpansion(file: File): Pair<ProcessResult, FastScriptExpansion?> {

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class Language(val version: String, val name: String = "en_US") {
3838
it["NOT-FOUND-COMMANDS"] = "&7No command data available."
3939
it["CLICK-INSERT-COMMAND"] = "&7Click insert command: &f/{command}"
4040
it["CLICK-TO-GO-URL"] = "&7Click to go to url: &f{url}"
41+
it["PLAYER-IS-OFFLINE"] = "&7Player &a{player_name} &7is not online"
4142
}
4243
it["COMMANDS"] = YamlConfiguration().also {
4344
it["EXPANSION"] = YamlConfiguration().also {
@@ -112,8 +113,23 @@ class Language(val version: String, val name: String = "en_US") {
112113
it["LOADED-SCRIPT"] = "Loaded script file successful."
113114
it["LOADED-PLUGIN"] = "Loaded plugin settings successful."
114115
}
115-
}
116+
it["TOOLS"] = YamlConfiguration().also {
117+
it["DESCRIPTION"] = "Some useful tool libraries."
118+
119+
it["COMMAND"] = YamlConfiguration().also {
120+
it["DESCRIPTION"] = "Send a command as sender('@CONSOLE' means console)."
121+
}
116122

123+
it["BUKKIT"] = YamlConfiguration().also {
124+
it["SOUNDS"] = YamlConfiguration().also {
125+
it["DESCRIPTION"] = "Play Sound to the player."
126+
}
127+
}
128+
}
129+
it["DEBUG"] = YamlConfiguration().also {
130+
it["DESCRIPTION"] = "Used to start debugging or view some debugging information."
131+
}
132+
}
117133
}
118134
it["EXPANSION"] = YamlConfiguration().also {
119135
it["TYPE-ENGINE"] = YamlConfiguration().also {

common/src/main/kotlin/me/scoretwo/fastscript/api/language/LanguageManager.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package me.scoretwo.fastscript.api.language
22

3+
import me.scoretwo.fastscript.plugin
34
import net.md_5.bungee.api.ChatColor
5+
import java.io.File
46

57
class LanguageManager {
68
val version = "1"
@@ -9,6 +11,13 @@ class LanguageManager {
911
it["en_US"] = defaultLanguage
1012
}
1113

14+
init {
15+
File(plugin.dataFolder, "language").listFiles()?.forEach {
16+
val name = it.name.substringBeforeLast(".")
17+
languages[name] = Language(version, name)
18+
}
19+
}
20+
1221
var current = defaultLanguage
1322

1423
operator fun set(node: String, any: Any?) = current.set(node, any)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ class ScriptManager {
190190
if (fail == 0)
191191
plugin.server.console.sendMessage(FormatHeader.INFO, languages["LOADED-COUNTS-PROCESS-SUCCESS"].setPlaceholder(placeholders))
192192
else
193-
plugin.server.console.sendMessage(FormatHeader.INFO, languages["LOADED-COUNTS-PROCESS-HAS-FAILED"].setPlaceholder(placeholders))
193+
plugin.server.console.sendMessage(FormatHeader.INFO, languages["LOADED-COUNTS-PROCESS-SUCCESS-HAS-FAILED"].setPlaceholder(placeholders))
194194
}
195195

196196
fun isConfigScriptOption(section: ConfigurationSection) =

common/src/main/kotlin/me/scoretwo/fastscript/api/utils/Utils.kt

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,55 @@ object Utils {
2828
}
2929

3030
}
31+
fun String.subStringWithEscape(from: Int, to: Int, escapes: List<Int>): String {
32+
val builder = StringBuilder()
33+
if (escapes.isEmpty())
34+
return substring(from, to)
35+
val it = escapes.iterator()
36+
var currentfrom = from
37+
var currentto = it.next()
38+
while (currentto != to) {
39+
builder.append(currentfrom, currentto)
40+
currentfrom = currentto + 1
41+
currentto = if (it.hasNext())
42+
it.next()
43+
else
44+
to
45+
}
46+
if (currentfrom != currentto)
47+
builder.append(currentfrom, currentto)
48+
return builder.toString()
49+
}
50+
51+
fun String.protectedSplit(index: Char, protector: Pair<Char, Char>): ArrayList<String> {
52+
val list = ArrayList<String>()
53+
var inner = false
54+
var startIndex = 0
55+
val len = this.length
56+
val escapes = ArrayList<Int>()
57+
for (endIndex in 0 until len) {
58+
val c = this[endIndex]
59+
if (inner) {
60+
if (c == protector.second) {
61+
inner = false
62+
escapes.add(endIndex)
63+
}
64+
}
65+
else {
66+
when (c) {
67+
index -> {
68+
list.add(subStringWithEscape(startIndex, endIndex, escapes))
69+
escapes.clear()
70+
startIndex = endIndex + 1
71+
}
72+
protector.first -> {
73+
inner = true
74+
escapes.add(endIndex)
75+
}
76+
}
77+
}
78+
}
79+
if (startIndex < len)
80+
list.add(subStringWithEscape(startIndex, len, escapes))
81+
return list
82+
}

common/src/main/kotlin/me/scoretwo/fastscript/command/FSCommandNexus.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package me.scoretwo.fastscript.command
22

33
import me.scoretwo.fastscript.FastScript
4-
import me.scoretwo.fastscript.command.commands.ExpansionCommand
5-
import me.scoretwo.fastscript.command.commands.ReloadCommand
6-
import me.scoretwo.fastscript.command.commands.ScriptCommand
4+
import me.scoretwo.fastscript.command.commands.*
75
import me.scoretwo.fastscript.languages
86
import me.scoretwo.fastscript.setPlaceholder
97
import me.scoretwo.utils.command.CommandBuilder
@@ -21,9 +19,11 @@ import net.md_5.bungee.api.chat.hover.content.Text
2119
class FSCommandNexus: CommandNexus(FastScript.instance.plugin, arrayOf("FastScript", "script", "fs")) {
2220

2321
init {
24-
register(ReloadCommand())
2522
register(ScriptCommand())
2623
register(ExpansionCommand())
24+
register(ToolsCommand())
25+
register(ReloadCommand())
26+
register(DebugCommand())
2727
}
2828

2929
override var language = object : CommandLanguage {
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package me.scoretwo.fastscript.command.commands
2+
3+
import me.scoretwo.fastscript.FastScript
4+
import me.scoretwo.fastscript.api.format.FormatHeader
5+
import me.scoretwo.fastscript.command.SimpleCommand
6+
import me.scoretwo.fastscript.debug
7+
import me.scoretwo.fastscript.languages
8+
import me.scoretwo.fastscript.sendMessage
9+
import me.scoretwo.utils.command.executor.CommandExecutor
10+
import me.scoretwo.utils.command.executor.Executors
11+
import me.scoretwo.utils.sender.GlobalSender
12+
13+
/**
14+
* @author Score2
15+
* @date 2021/2/22 17:34
16+
*
17+
* @project FastScript
18+
*/
19+
class DebugCommand: SimpleCommand(arrayOf("debug", "test")) {
20+
21+
override var description = languages["COMMAND-NEXUS.COMMANDS.DEBUG.DESCRIPTION"]
22+
23+
override var subCommands = mutableListOf(
24+
nextBuilder().alias("languages", "language")
25+
.description("Debugging related to language.")
26+
.subCommand(
27+
nextBuilder().alias("config")
28+
.description("Content related to configuration files.")
29+
.subCommand(
30+
nextBuilder().alias("sections")
31+
.description("Print config all sections.")
32+
.execute(object : CommandExecutor {
33+
override fun execute(sender: GlobalSender, parents: Array<String>, args: Array<String>): Boolean {
34+
val name = if (args.isEmpty()) { languages.current.name } else { args[0] }
35+
if (!languages.languages.containsKey(name)) {
36+
return false
37+
}
38+
languages.languages[name]?.config?.getKeys(true)?.forEach {
39+
sender.sendMessage("§7$it: §f${languages.languages[name]?.get(it)}")
40+
}
41+
return true
42+
}
43+
}).also { builder ->
44+
languages.languages.forEach {
45+
builder.customCommand(it.key, null, "Print ${it.key}'s sections")
46+
}
47+
}
48+
)
49+
.subCommand(
50+
nextBuilder().alias("get")
51+
.description("Get language content through nodes.")
52+
.executor(object : Executors {
53+
override fun execute(sender: GlobalSender, parents: Array<String>, args: Array<String>): Boolean {
54+
val path = args.joinToString(" ")
55+
if (!languages.current.config.contains(path)) {
56+
sender.sendMessage("Section $path not found")
57+
return true
58+
}
59+
if (languages.current.config.isList(path)) {
60+
sender.sendMessage("$path:")
61+
languages.current.config.getStringList(path).forEach {
62+
sender.sendMessage(it)
63+
}
64+
sender.sendMessage()
65+
} else {
66+
sender.sendMessage("$path: ${languages.current[path]}")
67+
}
68+
69+
return true
70+
}
71+
72+
override fun tabComplete(sender: GlobalSender, parents: Array<String>, args: Array<String>): MutableList<String>? {
73+
return languages.current.config.getKeys(true)?.toMutableList()
74+
}
75+
})
76+
)
77+
)
78+
.build(),
79+
nextBuilder().alias("enable")
80+
.description("Enable debug mode.")
81+
.execute(object : CommandExecutor {
82+
override fun execute(sender: GlobalSender, parents: Array<String>, args: Array<String>): Boolean {
83+
debug = true
84+
sender.sendMessage(FormatHeader.DEBUG, "Debug mode enabled. The server will start sending messages with debug.")
85+
return true
86+
}
87+
})
88+
.build(),
89+
nextBuilder().alias("disable")
90+
.description("Disable debug mode.")
91+
.execute(object : CommandExecutor {
92+
override fun execute(sender: GlobalSender, parents: Array<String>, args: Array<String>): Boolean {
93+
debug = false
94+
sender.sendMessage(FormatHeader.INFO, "Debug mode disabled.")
95+
return true
96+
}
97+
})
98+
.build()
99+
)
100+
101+
}

common/src/main/kotlin/me/scoretwo/fastscript/command/commands/ExpansionCommand.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class ExpansionCommand: SimpleCommand(arrayOf("expansion")) {
104104
)))
105105
it.clickEvent = ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/$displayParents help ")
106106
})
107-
sender.sendMessage("")
107+
sender.sendMessage()
108108

109109
return true
110110
}

0 commit comments

Comments
 (0)