Skip to content
This repository was archived by the owner on Mar 11, 2026. It is now read-only.

Commit 09dede5

Browse files
committed
Fixed formatting of Brigadier syntax error reports.
1 parent 888aa76 commit 09dede5

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

src/main/kotlin/lirand/api/dsl/command/implementation/dispatcher/DispatcherCommand.kt

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import com.mojang.brigadier.Message
55
import com.mojang.brigadier.StringReader
66
import com.mojang.brigadier.exceptions.CommandSyntaxException
77
import lirand.api.dsl.command.types.exceptions.ChatCommandSyntaxException
8+
import lirand.api.extensions.chat.SuggestCommandClickEvent
89
import lirand.api.extensions.chat.sendMessage
910
import lirand.api.extensions.chat.toComponent
1011
import lirand.api.utilities.isOverridden
1112
import net.md_5.bungee.api.ChatColor
1213
import net.md_5.bungee.api.chat.BaseComponent
13-
import net.md_5.bungee.api.chat.ClickEvent
1414
import net.md_5.bungee.api.chat.TextComponent
1515
import net.md_5.bungee.api.chat.TranslatableComponent
1616
import org.bukkit.command.Command
@@ -33,9 +33,7 @@ class DispatcherCommand(
3333
val dispatcher: CommandDispatcher<CommandSender>,
3434
usage: String,
3535
aliases: List<String>
36-
) : Command(
37-
name, "", usage, aliases
38-
), PluginIdentifiableCommand {
36+
) : Command(name, "", usage, aliases), PluginIdentifiableCommand {
3937

4038
/**
4139
* Forwards execution with the rejoined label and arguments to the underlying
@@ -44,7 +42,7 @@ class DispatcherCommand(
4442
* @param sender the sender
4543
* @param label the label
4644
* @param arguments the arguments
47-
* @return `true`
45+
* @return true
4846
*/
4947
override fun execute(sender: CommandSender, label: String, vararg arguments: String): Boolean {
5048
if (!testPermission(sender)) {
@@ -81,34 +79,39 @@ class DispatcherCommand(
8179
return plugin
8280
}
8381

82+
83+
8484
private fun report(sender: CommandSender, input: String?, cursor: Int) {
8585
if (input == null || cursor < 0) return
8686

8787
val index = min(input.length, cursor)
88-
val failedCommandMessage = TextComponent("").apply {
88+
val errorStart = input.lastIndexOf(' ', index - 1) + 1
89+
90+
val failedCommandMessage = TextComponent().apply {
8991
color = ChatColor.GRAY
90-
clickEvent = ClickEvent(
91-
ClickEvent.Action.SUGGEST_COMMAND,
92-
input
93-
)
92+
clickEvent = SuggestCommandClickEvent(input)
9493
}
95-
if (index > 10) {
94+
95+
if (errorStart > 10) {
9696
failedCommandMessage.addExtra("...")
9797
}
98-
failedCommandMessage.addExtra(input.substring(max(0, index - 10), index))
98+
failedCommandMessage.addExtra(input.substring(max(0, errorStart - 10), errorStart))
99+
99100
if (index < input.length) {
100-
val error = TextComponent(input.substring(index)).apply {
101+
val error = TextComponent(input.substring(errorStart)).apply {
101102
color = ChatColor.RED
102103
isUnderlined = true
103104
}
104105
failedCommandMessage.addExtra(error)
105106
}
107+
106108
val context = TranslatableComponent("command.context.here").apply {
107109
color = ChatColor.RED
108-
isUnderlined = true
110+
isItalic = true
109111
}
110112
failedCommandMessage.addExtra(context)
111113

114+
112115
sender.sendMessage(failedCommandMessage)
113116
}
114117

0 commit comments

Comments
 (0)