Skip to content

Commit

Permalink
Add //del_saved and prevent //save from overwriting
Browse files Browse the repository at this point in the history
  • Loading branch information
luk3yx committed Apr 16, 2024
1 parent 1903c55 commit 006c560
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions worldedit_commands/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1454,6 +1454,13 @@ if not mch_exists then
minetest.mkdir(path)

local filename = path .. "/" .. param .. ".we"
local f_r = io.open(filename, "r")
if f_r then
f_r:close()
worldedit.player_notify(name, S("File \"@1\" already exists", param))
return
end

local file, err = io.open(filename, "wb")
if err ~= nil then
worldedit.player_notify(name, S("Could not save file to \"@1\"", filename))
Expand All @@ -1467,6 +1474,30 @@ if not mch_exists then
end,
})

worldedit.register_command("del_saved", {
params = "<file>",
description = S("Deletes the specified saved file"),
privs = {worldedit=true},
parse = function(param)
if param == "" then
return false
end
if not check_filename(param) then
return false, S("Disallowed file name: @1", param)
end
return true, param
end,
func = function(name, param)
local path = minetest.get_worldpath() .. "/schems"
local filename = path .. "/" .. param .. ".we"
if os.remove(filename) then
worldedit.player_notify(name, S("Removed file \"@1\"", param))
else
worldedit.player_notify(name, S("Could not remove file \"@1\"", param))
end
end,
})

worldedit.register_command("allocate", {
params = "<file>",
description = S("Set the region defined by nodes from \"(world folder)/schems/<file>.we\" as the current WorldEdit region"),
Expand Down

0 comments on commit 006c560

Please sign in to comment.