diff --git a/worldeditadditions/lib/metaballs/playerdata.lua b/worldeditadditions/lib/metaballs/playerdata.lua index 18fe1a8..e9535ce 100644 --- a/worldeditadditions/lib/metaballs/playerdata.lua +++ b/worldeditadditions/lib/metaballs/playerdata.lua @@ -55,6 +55,9 @@ end local function list_pretty(player_name) local success, metaball_list = list(player_name) if not success then return success, metaball_list end + if not metaball_list or type(metaball_list) ~= "table" then + return false, "Invalid metaball list returned" + end local rows = { { "Index", "Position", "Radius" } } for i,metaball in ipairs(metaball_list) do @@ -75,6 +78,9 @@ end local function remove(player_name, index) local success, metaball_list = list(player_name) if not success then return success, metaball_list end + if not metaball_list or type(metaball_list) ~= "table" then + return false, "Invalid metaball list returned" + end if index > #metaball_list then return false, "Error: Requested the removal of metaball "..tostring(index)..", but there are "..tostring(#metaball_list).." metaballs defined." @@ -82,7 +88,7 @@ local function remove(player_name, index) table.remove(metaball_list, index) - return #metaball_list + return true, #metaball_list end --- Removes all the currently defined metaballs for the given player. @@ -104,8 +110,11 @@ local function volume(player_name) local success, metaball_list = list(player_name) if not success then return success, metaball_list end + if not metaball_list or not metaball_list[1] or type(metaball_list) ~= "table" then return false, "Error: Invalid metaball list returned" end + if #metaball_list == 0 then return 0 end + local pos1 = metaball_list[1].pos local pos2 = pos1 @@ -114,7 +123,7 @@ local function volume(player_name) pos2 = Vector3.max(pos2, metaball.pos + metaball.radius) end - return (pos2 - pos1):area() + return true, (pos2 - pos1):area() end return { diff --git a/worldeditadditions_commands/commands/metaball.lua b/worldeditadditions_commands/commands/metaball.lua index e275457..9bc142b 100644 --- a/worldeditadditions_commands/commands/metaball.lua +++ b/worldeditadditions_commands/commands/metaball.lua @@ -18,7 +18,7 @@ worldeditadditions_core.register_command("metaball", { local parts = wea_c.split_shell(params_text) if #parts < 1 then - return false, "Error: Not enough arguments (see /help /dome for usage information)." + return false, "Error: Not enough arguments (see /help /metaball for usage information)." end local subcommand = parts[1] @@ -83,7 +83,14 @@ worldeditadditions_core.register_command("metaball", { end, nodes_needed = function(name, subcommand) if subcommand == "render" then - return wea.metaballs.volume(name) + local success, value = wea.metaballs.volume(name) + + if not success then + worldedit.player_notify(name, value) + return -1 + end + + return value else return 0 end @@ -103,21 +110,19 @@ worldeditadditions_core.register_command("metaball", { local success2, volume = wea.metaballs.volume(name) if not success2 then return success2, volume end - message = #metaballs_list.." will take up to "..tostring(volume).." nodes of space" + message = #metaballs_list.." metaballs will take up to "..tostring(volume).." nodes of space" elseif subcommand == "clear" then - local success, metaballs_cleared = wea.metaballs.clear(name) - if not success then return success, metaballs_cleared end - - message = tostring(metaballs_cleared).." cleared" + local metaballs_cleared = wea.metaballs.clear(name) + message = tostring(metaballs_cleared).." metaball cleared" elseif subcommand == "remove" then local index = subargs[1] local success, metaballs_count = wea.metaballs.remove(name, index) if not success then return success, metaballs_count end - message = "metaball at index "..tostring(index).." removed - "..metaballs_count.." metaballs remain" + message = "metaball at index "..tostring(index).." removed - "..tostring(metaballs_count).." metaballs remain" elseif subcommand == "add" then - local pos = Vector3.clone(worldedit.pos1[name]) + local pos = Vector3.clone(worldedit.pos1[name]):round() local radius = subargs[1] local success, metaballs_count = wea.metaballs.add(name, pos, radius)