File tree Expand file tree Collapse file tree
minecraft/minecraft-chat/src/main/kotlin/taboolib/module/chat/impl
script/script-javascript/src/main/kotlin/taboolib/common5 Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package taboolib.module.chat.impl
22
3+ import com.google.gson.JsonParseException
34import net.kyori.adventure.text.Component
45import net.md_5.bungee.api.ChatColor
56import net.md_5.bungee.api.chat.*
@@ -59,9 +60,19 @@ class DefaultComponent() : ComponentText {
5960
6061 override fun sendTo (sender : ProxyCommandSender ) {
6162 if (sender is ProxyPlayer ) {
62- sender.sendRawMessage(toRawMessage())
63+ val message = toRawMessage()
64+ try {
65+ sender.sendRawMessage(message)
66+ } catch (_: JsonParseException ) {
67+ sender.sendRawMessage(message.replace(' §' , ' &' ))
68+ }
6369 } else {
64- sender.sendMessage(toLegacyText())
70+ val message = toLegacyText()
71+ try {
72+ sender.sendMessage(message)
73+ } catch (_: JsonParseException ) {
74+ sender.sendMessage(message.replace(' §' , ' &' ))
75+ }
6576 }
6677 }
6778
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import org.openjdk.nashorn.api.scripting.NashornScriptEngineFactory
1212import taboolib.common.Inject
1313import taboolib.common.env.RuntimeDependencies
1414import taboolib.common.env.RuntimeDependency
15+ import java.io.Reader
1516import javax.script.Compilable
1617import javax.script.CompiledScript
1718import javax.script.ScriptEngine
@@ -31,4 +32,8 @@ val scriptEngine: ScriptEngine by lazy {
3132
3233fun String.compileJS (): CompiledScript ? {
3334 return (scriptEngine as ? Compilable )?.compile(this )
35+ }
36+
37+ fun Reader.compileJS (): CompiledScript ? {
38+ return (scriptEngine as ? Compilable )?.compile(this )
3439}
You can’t perform that action at this time.
0 commit comments