run_command: prepend the name of the command in case of error.

This commit is contained in:
Starbeamrainbowlabs 2024-10-01 21:27:30 +01:00
parent f24ceffd2c
commit f3f0e8966d
No known key found for this signature in database
GPG Key ID: 1BE5172E637709C2
2 changed files with 8 additions and 2 deletions

@ -22,6 +22,7 @@ Note to self: See the bottom of this file for the release template text.
- Added `//uasparse` command to show the vectors produced by a given UAS expression. - Implementation by @VorTechnix
### Bugfixes and changes
- When commands produce an error, the name of the command that produced the error is now also printed. Useful when using e.g. [`//multi`](https://worldeditadditions.mooncarrot.space/Reference/#multi) etc.
- Don't warn on failed registration of `//flora` → [`//bonemeal`](https://worldeditadditions.mooncarrot.space/Reference/#bonemeal) if the `bonemeal` mod isn't installed (e.g. in MineClone2) - thanks @VorTechnix in #106
- Improve documentation of [`//noise2d`](https://worldeditadditions.mooncarrot.space/Reference/#noise2d). If it still doesn't make sense, please let me know. It's a complicated command that needs reworking a bit to be easier to use.
- Alias `//napply` to [`//nodeapply`](https://worldeditadditions.mooncarrot.space/Reference/#nodeapply)

@ -19,11 +19,16 @@ local human_size = wea_c.format.human_size
local function run_command_stage2(player_name, func, parse_result, tbl_event)
wea_c:emit("pre-execute", tbl_event)
local success, result_message = func(player_name, wea_c.table.unpack(parse_result))
print("DEBUG:run_command_stage2 SUCCESS", success, "RESULT_MESSAGE", result_message)
if not success then
result_message = "[//"..tostring(tbl_event.cmdname).."] "..result_message
end
if result_message then
-- TODO: If we were unsuccessful, then colour the message red
worldedit.player_notify(player_name, result_message)
end
tbl_event.success = success
tbl_event.result = result_message
wea_c:emit("post-execute", tbl_event)
@ -110,7 +115,7 @@ local function run_command(cmdname, options, player_name, paramtext)
local parse_result = { options.parse(paramtext) }
local success = table.remove(parse_result, 1)
if not success then
worldedit.player_notify(player_name, tostring(parse_result[1]) or "Invalid usage (no further error message was provided by the command. This is probably a bug.)")
worldedit.player_notify(player_name, ("[//"..tostring(cmdname).."] "..tostring(parse_result[1])) or "Invalid usage (no further error message was provided by the command. This is probably a bug.)")
return false
end