From 1d8d9a704fc91e86a7a5204208342bbb48f6e386 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Mon, 22 Apr 2024 17:33:16 +0200 Subject: [PATCH] Introduce type parameter for worldedit.player_notify --- worldedit_brush/init.lua | 35 +++-- worldedit_commands/code.lua | 10 +- worldedit_commands/cuboid.lua | 4 +- worldedit_commands/init.lua | 200 +++++++++++++++------------ worldedit_commands/manipulations.lua | 30 ++-- worldedit_commands/primitives.lua | 22 +-- worldedit_commands/region.lua | 73 +++++----- worldedit_commands/safe.lua | 6 +- worldedit_commands/schematics.lua | 45 +++--- worldedit_commands/transform.lua | 18 +-- worldedit_gui/functionality.lua | 2 +- worldedit_gui/init.lua | 2 +- 12 files changed, 235 insertions(+), 212 deletions(-) diff --git a/worldedit_brush/init.lua b/worldedit_brush/init.lua index 38de7ca..1a5c3e2 100644 --- a/worldedit_brush/init.lua +++ b/worldedit_brush/init.lua @@ -9,7 +9,7 @@ local brush_on_use = function(itemstack, placer) if cmd == "" then worldedit.player_notify(name, S("This brush is not bound, use @1 to bind a command to it.", - minetest.colorize("#00ffff", "//brush"))) + minetest.colorize("#00ffff", "//brush")), "info") return false end @@ -19,7 +19,7 @@ local brush_on_use = function(itemstack, placer) local has_privs, missing_privs = minetest.check_player_privs(name, cmddef.privs) if not has_privs then worldedit.player_notify(name, - S("Missing privileges: @1", table.concat(missing_privs, ", "))) + S("Missing privileges: @1", table.concat(missing_privs, ", ")), "error") return false end @@ -29,7 +29,7 @@ local brush_on_use = function(itemstack, placer) local ray = minetest.raycast(raybegin, rayend, false, true) local pointed_thing = ray:next() if pointed_thing == nil then - worldedit.player_notify(name, S("Too far away.")) + worldedit.player_notify(name, S("Too far away."), "error") return false end @@ -38,17 +38,17 @@ local brush_on_use = function(itemstack, placer) worldedit.pos2[name] = nil worldedit.marker_update(name) - -- this isn't really clean... - local player_notify_old = worldedit.player_notify - worldedit.player_notify = function(name, msg) - if string.match(msg, "^%d") then return end -- discard "1234 nodes added." - return player_notify_old(name, msg) - end - assert(cmddef.require_pos < 2) local parsed = {cmddef.parse(meta:get_string("params"))} if not table.remove(parsed, 1) then return false end -- shouldn't happen + -- discard success messages + local player_notify_old = worldedit.player_notify + worldedit.player_notify = function(name, msg, typ) + if typ == "ok" then return end + return player_notify_old(name, msg, typ) + end + minetest.log("action", string.format("%s uses WorldEdit brush (//%s) at %s", name, cmd, minetest.pos_to_string(pointed_thing.under))) cmddef.func(name, unpack(parsed)) @@ -86,29 +86,26 @@ worldedit.register_command("brush", { func = function(name, cmd, params) local itemstack = minetest.get_player_by_name(name):get_wielded_item() if itemstack == nil or itemstack:get_name() ~= "worldedit:brush" then - worldedit.player_notify(name, S("Not holding brush item.")) - return + return false, S("Not holding brush item.") end cmd = cmd:lower() local meta = itemstack:get_meta() if cmd == "none" then meta:from_table(nil) - worldedit.player_notify(name, S("Brush assignment cleared.")) + worldedit.player_notify(name, S("Brush assignment cleared."), "ok") else local cmddef = worldedit.registered_commands[cmd] if cmddef == nil or cmddef.require_pos ~= 1 then - worldedit.player_notify(name, S("@1 cannot be used with brushes", - minetest.colorize("#00ffff", "//"..cmd))) - return + return false, S("@1 cannot be used with brushes", + minetest.colorize("#00ffff", "//"..cmd)) end -- Try parsing command params so we can give the user feedback local ok, err = cmddef.parse(params) if not ok then err = err or S("invalid usage") - worldedit.player_notify(name, S("Error with command: @1", err)) - return + return false, S("Error with command: @1", err) end meta:set_string("command", cmd) @@ -116,7 +113,7 @@ worldedit.register_command("brush", { local fullcmd = minetest.colorize("#00ffff", "//"..cmd) .. " " .. params meta:set_string("description", minetest.registered_tools["worldedit:brush"].description .. ": " .. fullcmd) - worldedit.player_notify(name, S("Brush assigned to command: @1", fullcmd)) + worldedit.player_notify(name, S("Brush assigned to command: @1", fullcmd), "ok") end minetest.get_player_by_name(name):set_wielded_item(itemstack) end, diff --git a/worldedit_commands/code.lua b/worldedit_commands/code.lua index 8cd9097..96661b7 100644 --- a/worldedit_commands/code.lua +++ b/worldedit_commands/code.lua @@ -25,13 +25,13 @@ worldedit.register_command("lua", { if err == nil then minetest.log("action", name .. " executed " .. param) if ret ~= "nil" then - worldedit.player_notify(name, "code successfully executed, returned " .. ret) + worldedit.player_notify(name, "code successfully executed, returned " .. ret, "info") else - worldedit.player_notify(name, "code successfully executed") + worldedit.player_notify(name, "code successfully executed", "ok") end else minetest.log("action", name .. " tried to execute " .. param) - worldedit.player_notify(name, "code error: " .. err) + worldedit.player_notify(name, "code error: " .. err, "error") end end, }) @@ -49,10 +49,10 @@ worldedit.register_command("luatransform", { func = function(name, param) local err = worldedit.luatransform(worldedit.pos1[name], worldedit.pos2[name], param) if err then - worldedit.player_notify(name, "code error: " .. err, false) + worldedit.player_notify(name, "code error: " .. err, "error") minetest.log("action", name.." tried to execute luatransform "..param) else - worldedit.player_notify(name, "code successfully executed", false) + worldedit.player_notify(name, "code successfully executed", "ok") minetest.log("action", name.." executed luatransform "..param) end end, diff --git a/worldedit_commands/cuboid.lua b/worldedit_commands/cuboid.lua index 4a0fc6f..b269112 100644 --- a/worldedit_commands/cuboid.lua +++ b/worldedit_commands/cuboid.lua @@ -249,14 +249,14 @@ worldedit.register_command("cubeapply", { end, nodes_needed = function(name, sidex, sidey, sidez, cmd, parsed) -- its not possible to defer to the target command at this point + -- FIXME: why not? return sidex * sidey * sidez end, func = function(name, sidex, sidey, sidez, cmd, parsed) local cmddef = assert(worldedit.registered_commands[cmd]) local success, missing_privs = minetest.check_player_privs(name, cmddef.privs) if not success then - worldedit.player_notify(name, S("Missing privileges: @1", table.concat(missing_privs, ", "))) - return + return false, S("Missing privileges: @1", table.concat(missing_privs, ", ")) end -- update region to be the cuboid the user wanted diff --git a/worldedit_commands/init.lua b/worldedit_commands/init.lua index 691f35f..ebed467 100644 --- a/worldedit_commands/init.lua +++ b/worldedit_commands/init.lua @@ -31,13 +31,13 @@ local function chatcommand_handler(cmd_name, name, param) if def.require_pos == 2 then local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] if pos1 == nil or pos2 == nil then - worldedit.player_notify(name, S("no region selected")) + worldedit.player_notify(name, S("no region selected"), "error") return end elseif def.require_pos == 1 then local pos1 = worldedit.pos1[name] if pos1 == nil then - worldedit.player_notify(name, S("no position 1 selected")) + worldedit.player_notify(name, S("no position 1 selected"), "error") return end end @@ -45,14 +45,14 @@ local function chatcommand_handler(cmd_name, name, param) local parsed = {def.parse(param)} local success = table.remove(parsed, 1) if not success then - worldedit.player_notify(name, parsed[1] or S("invalid usage")) + worldedit.player_notify(name, parsed[1] or S("invalid usage"), "error") return end local run = function() - local _, msg = def.func(name, unpack(parsed)) + local ok, msg = def.func(name, unpack(parsed)) if msg then - minetest.chat_send_player(name, msg) + worldedit.player_notify(name, msg, ok and "ok" or "error") end end @@ -71,7 +71,7 @@ local function chatcommand_handler(cmd_name, name, param) ok = ok and ( (v == nil and old_state[i] == nil) or vector.equals(v, old_state[i]) ) end if not ok then - worldedit.player_notify(name, S("ERROR: the operation was cancelled because the region has changed.")) + worldedit.player_notify(name, S("ERROR: the operation was cancelled because the region has changed."), "error") return end @@ -149,8 +149,27 @@ do end -function worldedit.player_notify(name, message) - minetest.chat_send_player(name, "WorldEdit -!- " .. message) +-- Notifies a player of something related to WorldEdit. +-- Message types: +-- "error" = An operation did not work as expected. +-- "ok" = An operation completed successfully. Because notifications of this type +-- can be filtered, use this ONLY for generic messages like "1234 nodes set". +-- "info" = Other informational messages +-- @param name Name of player +-- @param message Message text +-- @param typ Type of message (optional but strongly recommend) +function worldedit.player_notify(name, message, typ) + local t = { + "WorldEdit", + "-!-", + tostring(message) + } + if typ == "error" then + t[2] = minetest.colorize("#f22", t[2]) + elseif typ == "ok" then + t[2] = minetest.colorize("#2f2", t[2]) + end + minetest.chat_send_player(name, table.concat(t, " ")) end -- Determines the axis in which a player is facing, returning an axis ("x", "y", or "z") and the sign (1 or -1) @@ -178,11 +197,92 @@ worldedit.register_command("about", { "commands, or find more information at @3", worldedit.version_string, minetest.colorize("#00ffff", "//help"), "https://github.com/Uberi/Minetest-WorldEdit" - )) + ), "info") end, }) -- initially copied from builtin/chatcommands.lua +local function help_command(name, param) + local function format_help_line(cmd, def, follow_alias) + local msg = minetest.colorize("#00ffff", "//"..cmd) + if def.name ~= cmd then + msg = msg .. ": " .. S("alias to @1", + minetest.colorize("#00ffff", "//"..def.name)) + if follow_alias then + msg = msg .. "\n" .. format_help_line(def.name, def) + end + else + if def.params and def.params ~= "" then + msg = msg .. " " .. def.params + end + if def.description and def.description ~= "" then + msg = msg .. ": " .. def.description + end + end + return msg + end + -- @param cmds list of {cmd, def} + local function sort_cmds(cmds) + table.sort(cmds, function(c1, c2) + local cmd1, cmd2 = c1[1], c2[1] + local def1, def2 = c1[2], c2[2] + -- by category (this puts the empty category first) + if def1.category ~= def2.category then + return def1.category < def2.category + end + -- put aliases last + if (cmd1 ~= def1.name) ~= (cmd2 ~= def2.name) then + return cmd2 ~= def2.name + end + -- then by name + return c1[1] < c2[1] + end) + end + + if not minetest.check_player_privs(name, "worldedit") then + return false, S("You are not allowed to use any WorldEdit commands.") + end + if param == "" then + local list = {} + for cmd, def in pairs(worldedit.registered_commands) do + if minetest.check_player_privs(name, def.privs) then + list[#list + 1] = cmd + end + end + table.sort(list) + local help = minetest.colorize("#00ffff", "//help") + return true, S("Available commands: @1@n" + .. "Use '@2' to get more information," + .. " or '@3' to list everything.", + table.concat(list, " "), help .. " ", help .. " all") + elseif param == "all" then + local cmds = {} + for cmd, def in pairs(worldedit.registered_commands) do + if minetest.check_player_privs(name, def.privs) then + cmds[#cmds + 1] = {cmd, def} + end + end + sort_cmds(cmds) + local list = {} + local last_cat = "" + for _, e in ipairs(cmds) do + if e[2].category ~= last_cat then + last_cat = e[2].category + list[#list + 1] = "---- " .. last_cat + end + list[#list + 1] = format_help_line(e[1], e[2]) + end + return true, S("Available commands:@n") .. table.concat(list, "\n") + else + local def = worldedit.registered_commands[param] + if not def then + return false, S("Command not available: ") .. param + else + return true, format_help_line(param, def, true) + end + end +end + worldedit.register_command("help", { privs = {}, params = "[all/]", @@ -191,83 +291,9 @@ worldedit.register_command("help", { return true, param end, func = function(name, param) - local function format_help_line(cmd, def, follow_alias) - local msg = minetest.colorize("#00ffff", "//"..cmd) - if def.name ~= cmd then - msg = msg .. ": " .. S("alias to @1", - minetest.colorize("#00ffff", "//"..def.name)) - if follow_alias then - msg = msg .. "\n" .. format_help_line(def.name, def) - end - else - if def.params and def.params ~= "" then - msg = msg .. " " .. def.params - end - if def.description and def.description ~= "" then - msg = msg .. ": " .. def.description - end - end - return msg - end - -- @param cmds list of {cmd, def} - local function sort_cmds(cmds) - table.sort(cmds, function(c1, c2) - local cmd1, cmd2 = c1[1], c2[1] - local def1, def2 = c1[2], c2[2] - -- by category (this puts the empty category first) - if def1.category ~= def2.category then - return def1.category < def2.category - end - -- put aliases last - if (cmd1 ~= def1.name) ~= (cmd2 ~= def2.name) then - return cmd2 ~= def2.name - end - -- then by name - return c1[1] < c2[1] - end) - end - - if not minetest.check_player_privs(name, "worldedit") then - return false, S("You are not allowed to use any WorldEdit commands.") - end - if param == "" then - local list = {} - for cmd, def in pairs(worldedit.registered_commands) do - if minetest.check_player_privs(name, def.privs) then - list[#list + 1] = cmd - end - end - table.sort(list) - local help = minetest.colorize("#00ffff", "//help") - return true, S("Available commands: @1@n" - .. "Use '@2' to get more information," - .. " or '@3' to list everything.", - table.concat(list, " "), help .. " ", help .. " all") - elseif param == "all" then - local cmds = {} - for cmd, def in pairs(worldedit.registered_commands) do - if minetest.check_player_privs(name, def.privs) then - cmds[#cmds + 1] = {cmd, def} - end - end - sort_cmds(cmds) - local list = {} - local last_cat = "" - for _, e in ipairs(cmds) do - if e[2].category ~= last_cat then - last_cat = e[2].category - list[#list + 1] = "---- " .. last_cat - end - list[#list + 1] = format_help_line(e[1], e[2]) - end - return true, S("Available commands:@n") .. table.concat(list, "\n") - else - local def = worldedit.registered_commands[param] - if not def then - return false, S("Command not available: ") .. param - else - return true, format_help_line(param, def, true) - end + local ok, msg = help_command(name, param) + if msg then + worldedit.player_notify(name, msg, ok and "info" or "error") end end, }) @@ -285,7 +311,7 @@ worldedit.register_command("reset", { worldedit.set_pos[name] = nil --make sure the user does not try to confirm an operation after resetting pos: reset_pending(name) - worldedit.player_notify(name, S("region reset")) + return true, S("region reset") end, }) diff --git a/worldedit_commands/manipulations.lua b/worldedit_commands/manipulations.lua index 7705628..7f510b8 100644 --- a/worldedit_commands/manipulations.lua +++ b/worldedit_commands/manipulations.lua @@ -16,9 +16,9 @@ worldedit.register_command("deleteblocks", { local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] local success = minetest.delete_area(pos1, pos2) if success then - worldedit.player_notify(name, S("Area deleted.")) + return true, S("Area deleted.") else - worldedit.player_notify(name, S("There was an error during deletion of the area.")) + return false, S("There was an error during deletion of the area.") end end, }) @@ -32,7 +32,7 @@ worldedit.register_command("clearobjects", { nodes_needed = check_region, func = function(name) local count = worldedit.clear_objects(worldedit.pos1[name], worldedit.pos2[name]) - worldedit.player_notify(name, S("@1 objects cleared", count)) + return true, S("@1 objects cleared", count) end, }) @@ -52,7 +52,7 @@ worldedit.register_command("set", { nodes_needed = check_region, func = function(name, node) local count = worldedit.set(worldedit.pos1[name], worldedit.pos2[name], node) - worldedit.player_notify(name, S("@1 nodes set", count)) + return true, S("@1 nodes set", count) end, }) @@ -74,7 +74,7 @@ worldedit.register_command("param2", { nodes_needed = check_region, func = function(name, param2) local count = worldedit.set_param2(worldedit.pos1[name], worldedit.pos2[name], param2) - worldedit.player_notify(name, S("@1 nodes altered", count)) + return true, S("@1 nodes altered", count) end, }) @@ -109,7 +109,7 @@ worldedit.register_command("mix", { func = function(name, nodes) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] local count = worldedit.set(pos1, pos2, nodes) - worldedit.player_notify(name, S("@1 nodes set", count)) + return true, S("@1 nodes set", count) end, }) @@ -140,7 +140,7 @@ worldedit.register_command("replace", { func = function(name, search_node, replace_node) local count = worldedit.replace(worldedit.pos1[name], worldedit.pos2[name], search_node, replace_node) - worldedit.player_notify(name, S("@1 nodes replaced", count)) + return true, S("@1 nodes replaced", count) end, }) @@ -155,7 +155,7 @@ worldedit.register_command("replaceinverse", { func = function(name, search_node, replace_node) local count = worldedit.replace(worldedit.pos1[name], worldedit.pos2[name], search_node, replace_node, true) - worldedit.player_notify(name, S("@1 nodes replaced", count)) + return true, S("@1 nodes replaced", count) end, }) @@ -168,7 +168,7 @@ worldedit.register_command("fixlight", { nodes_needed = check_region, func = function(name) local count = worldedit.fixlight(worldedit.pos1[name], worldedit.pos2[name]) - worldedit.player_notify(name, S("@1 nodes updated", count)) + return true, S("@1 nodes updated", count) end, }) @@ -198,7 +198,7 @@ worldedit.register_command("drain", { end end end - worldedit.player_notify(name, S("@1 nodes updated", count)) + return true, S("@1 nodes updated", count) end, }) @@ -281,7 +281,7 @@ worldedit.register_command("clearcut", { func = function(name) local pos1, pos2 = worldedit.sort_pos(worldedit.pos1[name], worldedit.pos2[name]) local count = clearcut(pos1, pos2) - worldedit.player_notify(name, S("@1 nodes removed", count)) + return true, S("@1 nodes removed", count) end, }) @@ -294,7 +294,7 @@ worldedit.register_command("hide", { nodes_needed = check_region, func = function(name) local count = worldedit.hide(worldedit.pos1[name], worldedit.pos2[name]) - worldedit.player_notify(name, S("@1 nodes hidden", count)) + return true, S("@1 nodes hidden", count) end, }) @@ -314,7 +314,7 @@ worldedit.register_command("suppress", { nodes_needed = check_region, func = function(name, node) local count = worldedit.suppress(worldedit.pos1[name], worldedit.pos2[name], node) - worldedit.player_notify(name, S("@1 nodes suppressed", count)) + return true, S("@1 nodes suppressed", count) end, }) @@ -334,7 +334,7 @@ worldedit.register_command("highlight", { nodes_needed = check_region, func = function(name, node) local count = worldedit.highlight(worldedit.pos1[name], worldedit.pos2[name], node) - worldedit.player_notify(name, S("@1 nodes highlighted", count)) + return true, S("@1 nodes highlighted", count) end, }) @@ -347,6 +347,6 @@ worldedit.register_command("restore", { nodes_needed = check_region, func = function(name) local count = worldedit.restore(worldedit.pos1[name], worldedit.pos2[name]) - worldedit.player_notify(name, S("@1 nodes restored", count)) + return true, S("@1 nodes restored", count) end, }) diff --git a/worldedit_commands/primitives.lua b/worldedit_commands/primitives.lua index 73c6ddf..d36a403 100644 --- a/worldedit_commands/primitives.lua +++ b/worldedit_commands/primitives.lua @@ -25,7 +25,7 @@ worldedit.register_command("hollowcube", { end, func = function(name, w, h, l, node) local count = worldedit.cube(worldedit.pos1[name], w, h, l, node, true) - worldedit.player_notify(name, S("@1 nodes added", count)) + return true, S("@1 nodes added", count) end, }) @@ -41,7 +41,7 @@ worldedit.register_command("cube", { end, func = function(name, w, h, l, node) local count = worldedit.cube(worldedit.pos1[name], w, h, l, node) - worldedit.player_notify(name, S("@1 nodes added", count)) + return true, S("@1 nodes added", count) end, }) @@ -69,7 +69,7 @@ worldedit.register_command("hollowsphere", { end, func = function(name, radius, node) local count = worldedit.sphere(worldedit.pos1[name], radius, node, true) - worldedit.player_notify(name, S("@1 nodes added", count)) + return true, S("@1 nodes added", count) end, }) @@ -85,7 +85,7 @@ worldedit.register_command("sphere", { end, func = function(name, radius, node) local count = worldedit.sphere(worldedit.pos1[name], radius, node) - worldedit.player_notify(name, S("@1 nodes added", count)) + return true, S("@1 nodes added", count) end, }) @@ -113,7 +113,7 @@ worldedit.register_command("hollowdome", { end, func = function(name, radius, node) local count = worldedit.dome(worldedit.pos1[name], radius, node, true) - worldedit.player_notify(name, S("@1 nodes added", count)) + return true, S("@1 nodes added", count) end, }) @@ -129,7 +129,7 @@ worldedit.register_command("dome", { end, func = function(name, radius, node) local count = worldedit.dome(worldedit.pos1[name], radius, node) - worldedit.player_notify(name, S("@1 nodes added", count)) + return true, S("@1 nodes added", count) end, }) @@ -169,7 +169,7 @@ worldedit.register_command("hollowcylinder", { length = length * sign end local count = worldedit.cylinder(worldedit.pos1[name], axis, length, radius1, radius2, node, true) - worldedit.player_notify(name, S("@1 nodes added", count)) + return true, S("@1 nodes added", count) end, }) @@ -191,7 +191,7 @@ worldedit.register_command("cylinder", { length = length * sign end local count = worldedit.cylinder(worldedit.pos1[name], axis, length, radius1, radius2, node) - worldedit.player_notify(name, S("@1 nodes added", count)) + return true, S("@1 nodes added", count) end, }) @@ -224,7 +224,7 @@ worldedit.register_command("hollowpyramid", { height = height * sign end local count = worldedit.pyramid(worldedit.pos1[name], axis, height, node, true) - worldedit.player_notify(name, S("@1 nodes added", count)) + return true, S("@1 nodes added", count) end, }) @@ -245,7 +245,7 @@ worldedit.register_command("pyramid", { height = height * sign end local count = worldedit.pyramid(worldedit.pos1[name], axis, height, node) - worldedit.player_notify(name, S("@1 nodes added", count)) + return true, S("@1 nodes added", count) end, }) @@ -271,6 +271,6 @@ worldedit.register_command("spiral", { end, func = function(name, length, height, space, node) local count = worldedit.spiral(worldedit.pos1[name], length, height, space, node) - worldedit.player_notify(name, S("@1 nodes added", count)) + return true, S("@1 nodes added", count) end, }) diff --git a/worldedit_commands/region.lua b/worldedit_commands/region.lua index 3a2660d..27293f0 100644 --- a/worldedit_commands/region.lua +++ b/worldedit_commands/region.lua @@ -24,10 +24,10 @@ worldedit.register_command("inspect", { "inspector: inspection enabled for @1, currently facing the @2 axis", name, axis .. (sign > 0 and "+" or "-") - )) + ), "info") else worldedit.inspect[name] = nil - worldedit.player_notify(name, S("inspector: inspection disabled")) + worldedit.player_notify(name, S("inspector: inspection disabled"), "info") end end, }) @@ -61,7 +61,7 @@ minetest.register_on_punchnode(function(pos, node, puncher) get_node_rlight(pos), axis .. (sign > 0 and "+" or "-") ) - worldedit.player_notify(name, message) + worldedit.player_notify(name, message, "info") end end) @@ -73,7 +73,7 @@ worldedit.register_command("mark", { privs = {worldedit=true}, func = function(name) worldedit.marker_update(name) - worldedit.player_notify(name, S("region marked")) + return true, S("region marked") end, }) @@ -89,10 +89,24 @@ worldedit.register_command("unmark", { worldedit.marker_update(name) worldedit.pos1[name] = pos1 worldedit.pos2[name] = pos2 - worldedit.player_notify(name, S("region unmarked")) + return true, S("region unmarked") end, }) +local function set_pos1(name, pos) + assert(pos) + worldedit.pos1[name] = pos + worldedit.mark_pos1(name) + worldedit.player_notify(name, S("position @1 set to @2", 1, minetest.pos_to_string(pos)), "ok") +end + +local function set_pos2(name, pos) + assert(pos) + worldedit.pos2[name] = pos + worldedit.mark_pos2(name) + worldedit.player_notify(name, S("position @1 set to @2", 2, minetest.pos_to_string(pos)), "ok") +end + worldedit.register_command("pos1", { params = "", description = S("Set WorldEdit region position @1 to the player's location", 1), @@ -101,9 +115,7 @@ worldedit.register_command("pos1", { func = function(name) local pos = minetest.get_player_by_name(name):get_pos() pos.x, pos.y, pos.z = math.floor(pos.x + 0.5), math.floor(pos.y + 0.5), math.floor(pos.z + 0.5) - worldedit.pos1[name] = pos - worldedit.mark_pos1(name) - worldedit.player_notify(name, S("position @1 set to @2", 1, minetest.pos_to_string(pos))) + set_pos1(name, pos) end, }) @@ -115,9 +127,7 @@ worldedit.register_command("pos2", { func = function(name) local pos = minetest.get_player_by_name(name):get_pos() pos.x, pos.y, pos.z = math.floor(pos.x + 0.5), math.floor(pos.y + 0.5), math.floor(pos.z + 0.5) - worldedit.pos2[name] = pos - worldedit.mark_pos2(name) - worldedit.player_notify(name, S("position @1 set to @2", 2, minetest.pos_to_string(pos))) + set_pos2(name, pos) end, }) @@ -133,27 +143,32 @@ worldedit.register_command("p", { return false, S("unknown subcommand: @1", param) end, func = function(name, param) + local msg if param == "set" then --set both WorldEdit positions worldedit.set_pos[name] = "pos1" - worldedit.player_notify(name, S("select positions by punching two nodes")) + msg = S("select positions by punching two nodes") elseif param == "set1" then --set WorldEdit position 1 worldedit.set_pos[name] = "pos1only" - worldedit.player_notify(name, S("select position @1 by punching a node", 1)) + msg = S("select position @1 by punching a node", 1) elseif param == "set2" then --set WorldEdit position 2 worldedit.set_pos[name] = "pos2" - worldedit.player_notify(name, S("select position @1 by punching a node", 2)) + msg = S("select position @1 by punching a node", 2) elseif param == "get" then --display current WorldEdit positions if worldedit.pos1[name] ~= nil then - worldedit.player_notify(name, S("position @1: @2", 1, minetest.pos_to_string(worldedit.pos1[name]))) + msg = S("position @1: @2", 1, minetest.pos_to_string(worldedit.pos1[name])) else - worldedit.player_notify(name, S("position @1 not set", 1)) + msg = S("position @1 not set", 1) end + msg = msg .. "\n" if worldedit.pos2[name] ~= nil then - worldedit.player_notify(name, S("position @1: @2", 2, minetest.pos_to_string(worldedit.pos2[name]))) + msg = msg .. S("position @1: @2", 2, minetest.pos_to_string(worldedit.pos2[name])) else - worldedit.player_notify(name, S("position @1 not set", 2)) + msg = msg .. S("position @1 not set", 2) end end + if msg then + worldedit.player_notify(name, msg, "info") + end end, }) @@ -171,13 +186,9 @@ worldedit.register_command("fixedpos", { end, func = function(name, flag, pos) if flag == "set1" then - worldedit.pos1[name] = pos - worldedit.mark_pos1(name) - worldedit.player_notify(name, S("position @1 set to @2", 1, minetest.pos_to_string(pos))) + set_pos1(name, pos) else --flag == "set2" - worldedit.pos2[name] = pos - worldedit.mark_pos2(name) - worldedit.player_notify(name, S("position @1 set to @2", 2, minetest.pos_to_string(pos))) + set_pos2(name, pos) end end, }) @@ -186,20 +197,14 @@ minetest.register_on_punchnode(function(pos, node, puncher) local name = puncher:get_player_name() if name ~= "" and worldedit.set_pos[name] ~= nil then --currently setting position if worldedit.set_pos[name] == "pos1" then --setting position 1 - worldedit.pos1[name] = pos - worldedit.mark_pos1(name) + set_pos1(name, pos) worldedit.set_pos[name] = "pos2" --set position 2 on the next invocation - worldedit.player_notify(name, S("position @1 set to @2", 1, minetest.pos_to_string(pos))) elseif worldedit.set_pos[name] == "pos1only" then --setting position 1 only - worldedit.pos1[name] = pos - worldedit.mark_pos1(name) + set_pos1(name, pos) worldedit.set_pos[name] = nil --finished setting positions - worldedit.player_notify(name, S("position @1 set to @2", 1, minetest.pos_to_string(pos))) elseif worldedit.set_pos[name] == "pos2" then --setting position 2 - worldedit.pos2[name] = pos - worldedit.mark_pos2(name) + set_pos2(name, pos) worldedit.set_pos[name] = nil --finished setting positions - worldedit.player_notify(name, S("position @1 set to @2", 2, minetest.pos_to_string(pos))) elseif worldedit.set_pos[name] == "prob" then --setting Minetest schematic node probabilities worldedit.prob_pos[name] = pos minetest.show_formspec(name, "prob_val_enter", "field[text;;]") @@ -224,6 +229,6 @@ worldedit.register_command("volume", { abs(pos2.x - pos1.x) + 1, abs(pos2.y - pos1.y) + 1, abs(pos2.z - pos1.z) + 1 - )) + ), "info") end, }) diff --git a/worldedit_commands/safe.lua b/worldedit_commands/safe.lua index 6456746..20ed9cf 100644 --- a/worldedit_commands/safe.lua +++ b/worldedit_commands/safe.lua @@ -12,7 +12,7 @@ local function safe_region(name, count, callback) --save callback to call later safe_region_callback[name] = callback worldedit.player_notify(name, S("WARNING: this operation could affect up to @1 nodes; type @2 to continue or @3 to cancel", - count, minetest.colorize("#00ffff", "//y"), minetest.colorize("#00ffff", "//n"))) + count, minetest.colorize("#00ffff", "//y"), minetest.colorize("#00ffff", "//n")), "info") end local function reset_pending(name) @@ -25,7 +25,7 @@ minetest.register_chatcommand("/y", { func = function(name) local callback = safe_region_callback[name] if not callback then - worldedit.player_notify(name, S("no operation pending")) + worldedit.player_notify(name, S("no operation pending"), "error") return end @@ -39,7 +39,7 @@ minetest.register_chatcommand("/n", { description = S("Abort a pending operation"), func = function(name) if not safe_region_callback[name] then - worldedit.player_notify(name, S("no operation pending")) + worldedit.player_notify(name, S("no operation pending"), "error") return end diff --git a/worldedit_commands/schematics.lua b/worldedit_commands/schematics.lua index 1db7b5a..dbf8b2f 100644 --- a/worldedit_commands/schematics.lua +++ b/worldedit_commands/schematics.lua @@ -26,7 +26,7 @@ local function open_schematic(name, param) end end if err then - worldedit.player_notify(name, S("Could not open file \"@1\"", param)) + worldedit.player_notify(name, S("Could not open file \"@1\"", param), "error") return end local value = file:read("*a") @@ -34,10 +34,10 @@ local function open_schematic(name, param) local version = worldedit.read_header(value) if version == nil or version == 0 then - worldedit.player_notify(name, S("Invalid file format!")) + worldedit.player_notify(name, S("Invalid file format!"), "error") return elseif version > worldedit.LATEST_SERIALIZATION_VERSION then - worldedit.player_notify(name, S("Schematic was created with a newer version of WorldEdit.")) + worldedit.player_notify(name, S("Schematic was created with a newer version of WorldEdit."), "error") return end @@ -90,14 +90,13 @@ worldedit.register_command("save", { local filename = path .. "/" .. param .. ".we" local file, err = io.open(filename, "wb") if err ~= nil then - worldedit.player_notify(name, S("Could not save file to \"@1\"", filename)) - return + return false, S("Could not save file to \"@1\"", filename) end file:write(result) file:flush() file:close() - worldedit.player_notify(name, S("@1 nodes saved", count)) + return true, S("@1 nodes saved", count) end, }) @@ -126,15 +125,14 @@ worldedit.register_command("allocate", { local nodepos1, nodepos2, count = worldedit.allocate(pos, value) if not nodepos1 then - worldedit.player_notify(name, S("Schematic empty, nothing allocated")) - return false + return false, S("Schematic empty, nothing allocated") end worldedit.pos1[name] = nodepos1 worldedit.pos2[name] = nodepos2 worldedit.marker_update(name) - worldedit.player_notify(name, S("@1 nodes allocated", count)) + return true, S("@1 nodes allocated", count) end, }) @@ -163,10 +161,9 @@ worldedit.register_command("load", { local count = worldedit.deserialize(pos, value) if count == nil then - worldedit.player_notify(name, S("Loading failed!")) - return false + return false, S("Loading failed!") end - worldedit.player_notify(name, S("@1 nodes loaded", count)) + return true, S("@1 nodes loaded", count) end, }) @@ -197,12 +194,11 @@ worldedit.register_command("mtschemcreate", { local ret = minetest.create_schematic(worldedit.pos1[name], worldedit.pos2[name], worldedit.prob_list[name], filename) - if ret == nil then - worldedit.player_notify(name, S("Failed to create Minetest schematic")) - else - worldedit.player_notify(name, S("Saved Minetest schematic to @1", param)) - end worldedit.prob_list[name] = {} + if ret == nil then + return false, S("Failed to create Minetest schematic") + end + return true, S("Saved Minetest schematic to @1", param) end, }) @@ -226,10 +222,10 @@ worldedit.register_command("mtschemplace", { local path = minetest.get_worldpath() .. "/schems/" .. param .. ".mts" if minetest.place_schematic(pos, path) == nil then - worldedit.player_notify(name, S("failed to place Minetest schematic")) - else - worldedit.player_notify(name, S("placed Minetest schematic @1 at @2", param, minetest.pos_to_string(pos))) + return false, S("failed to place Minetest schematic") end + return true, S("placed Minetest schematic @1 at @2", + param, minetest.pos_to_string(pos)) end, }) @@ -248,10 +244,10 @@ worldedit.register_command("mtschemprob", { if param == "start" then --start probability setting worldedit.set_pos[name] = "prob" worldedit.prob_list[name] = {} - worldedit.player_notify(name, S("select Minetest schematic probability values by punching nodes")) + worldedit.player_notify(name, S("select Minetest schematic probability values by punching nodes"), "info") elseif param == "finish" then --finish probability setting worldedit.set_pos[name] = nil - worldedit.player_notify(name, S("finished Minetest schematic probability selection")) + worldedit.player_notify(name, S("finished Minetest schematic probability selection"), "info") elseif param == "get" then --get all nodes that had probabilities set on them local text = "" local problist = worldedit.prob_list[name] @@ -262,8 +258,7 @@ worldedit.register_command("mtschemprob", { local prob = math.floor(((v.prob / 256) * 100) * 100 + 0.5) / 100 text = text .. minetest.pos_to_string(v.pos) .. ": " .. prob .. "% | " end - worldedit.player_notify(name, S("currently set node probabilities:")) - worldedit.player_notify(name, text) + worldedit.player_notify(name, S("currently set node probabilities:") .. "\n" .. text, "info") end end, }) @@ -277,7 +272,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end local e = {pos=worldedit.prob_pos[name], prob=tonumber(fields.text)} if e.pos == nil or e.prob == nil or e.prob < 0 or e.prob > 256 then - worldedit.player_notify(name, S("invalid node probability given, not saved")) + worldedit.player_notify(name, S("invalid node probability given, not saved"), "error") return end problist[#problist+1] = e diff --git a/worldedit_commands/transform.lua b/worldedit_commands/transform.lua index 0752670..ce3d085 100644 --- a/worldedit_commands/transform.lua +++ b/worldedit_commands/transform.lua @@ -29,7 +29,7 @@ worldedit.register_command("copy", { end local count = worldedit.copy(worldedit.pos1[name], worldedit.pos2[name], axis, amount) - worldedit.player_notify(name, S("@1 nodes copied", count)) + return true, S("@1 nodes copied", count) end, }) @@ -62,7 +62,7 @@ worldedit.register_command("move", { pos1[axis] = pos1[axis] + amount pos2[axis] = pos2[axis] + amount worldedit.marker_update(name) - worldedit.player_notify(name, S("@1 nodes moved", count)) + return true, S("@1 nodes moved", count) end, }) @@ -92,7 +92,7 @@ worldedit.register_command("stack", { local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] local count = worldedit.volume(pos1, pos2) * math.abs(repetitions) worldedit.stack(pos1, pos2, axis, repetitions, function() - worldedit.player_notify(name, S("@1 nodes stacked", count)) + worldedit.player_notify(name, S("@1 nodes stacked", count), "ok") end) end, }) @@ -122,7 +122,7 @@ worldedit.register_command("stack2", { local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] local count = worldedit.volume(pos1, pos2) * repetitions worldedit.stack2(pos1, pos2, offset, repetitions, function() - worldedit.player_notify(name, S("@1 nodes stacked", count)) + worldedit.player_notify(name, S("@1 nodes stacked", count), "ok") end) end, }) @@ -156,7 +156,7 @@ worldedit.register_command("stretch", { worldedit.pos2[name] = pos2 worldedit.marker_update(name) - worldedit.player_notify(name, S("@1 nodes stretched", count)) + return true, S("@1 nodes stretched", count) end, }) @@ -187,7 +187,7 @@ worldedit.register_command("transpose", { worldedit.pos2[name] = pos2 worldedit.marker_update(name) - worldedit.player_notify(name, S("@1 nodes transposed", count)) + return true, S("@1 nodes transposed", count) end, }) @@ -207,7 +207,7 @@ worldedit.register_command("flip", { func = function(name, param) if param == "?" then param = worldedit.player_axis(name) end local count = worldedit.flip(worldedit.pos1[name], worldedit.pos2[name], param) - worldedit.player_notify(name, S("@1 nodes flipped", count)) + return true, S("@1 nodes flipped", count) end, }) @@ -239,7 +239,7 @@ worldedit.register_command("rotate", { worldedit.pos2[name] = pos2 worldedit.marker_update(name) - worldedit.player_notify(name, S("@1 nodes rotated", count)) + return true, S("@1 nodes rotated", count) end, }) @@ -263,7 +263,7 @@ worldedit.register_command("orient", { nodes_needed = check_region, func = function(name, angle) local count = worldedit.orient(worldedit.pos1[name], worldedit.pos2[name], angle) - worldedit.player_notify(name, S("@1 nodes oriented", count)) + return true, S("@1 nodes oriented", count) end, }) diff --git a/worldedit_gui/functionality.lua b/worldedit_gui/functionality.lua index 982081b..75c205a 100644 --- a/worldedit_gui/functionality.lua +++ b/worldedit_gui/functionality.lua @@ -140,7 +140,7 @@ local function execute_worldedit_command(command_name, player_name, params) assert(chatcmd, "unknown command: " .. command_name) local _, msg = chatcmd.func(player_name, params) if msg then - worldedit.player_notify(player_name, msg) + minetest.chat_send_player(player_name, msg) end end diff --git a/worldedit_gui/init.lua b/worldedit_gui/init.lua index 95f81ce..bb85df8 100644 --- a/worldedit_gui/init.lua +++ b/worldedit_gui/init.lua @@ -264,7 +264,7 @@ worldedit.register_gui_handler("worldedit_gui", function(name, fields) --ensure player has permission to perform action local has_privs, missing_privs = minetest.check_player_privs(name, entry.privs) if not has_privs then - worldedit.player_notify(name, "you are not allowed to use this function (missing privileges: " .. table.concat(missing_privs, ", ") .. ")") + worldedit.player_notify(name, "you are not allowed to use this function (missing privileges: " .. table.concat(missing_privs, ", ") .. ")", "error") return false end if entry.on_select then