WorldEdit 0.4.5

This commit is contained in:
sfan5 2012-05-18 22:19:00 +02:00
parent 496f5b515c
commit bc4a056044
2 changed files with 58 additions and 5 deletions

@ -1 +1 @@
0.4.2.1 0.4.5

@ -3,6 +3,7 @@ print("[WorldEdit] Loading Table-Save/Load Library...")
dofile(minetest.get_modpath("worldedit").."/table_save-load.lua") dofile(minetest.get_modpath("worldedit").."/table_save-load.lua")
assert(table.save ~= nil) assert(table.save ~= nil)
assert(table.load ~= nil) assert(table.load ~= nil)
minetest.register_privilege("worldedit", "Ability to use WorldEdit")
worldedit = {} worldedit = {}
-- Functions -- Functions
function get_tmp(name) function get_tmp(name)
@ -23,6 +24,23 @@ function set_tmp(name,text)
return true return true
end end
end end
function check_if_dir(path)
f = io.open(path, "r")
if f == nil then
return false -- Doesn't exists
end
local ok, err, code = f:read("*a")
f:close()
if code == 21 then
return true
end
return false
end
function check_schematic_dir(worldpath)
if not check_if_dir(worldpath .. "/schems") then
os.execute("mkdir " .. worldpath .. "/schems") --Dirty hack
end
end
function to_pos(s) function to_pos(s)
local pos = {0,0,0} local pos = {0,0,0}
i = 1 i = 1
@ -51,6 +69,9 @@ function string:split(delimiter)
return result return result
end end
function check_player_we_perms(pname) function check_player_we_perms(pname)
if minetest.get_player_privs(pname).worldedit then
return true
end
local fi = "" local fi = ""
local f = io.open(minetest.get_worldpath().."/weperms.txt", "r") local f = io.open(minetest.get_worldpath().."/weperms.txt", "r")
if f ~= nil then if f ~= nil then
@ -372,7 +393,9 @@ minetest.register_on_chat_message(function(name, message)
minetest.chat_send_player(name, 'usage: '..cmd..' [filename]') minetest.chat_send_player(name, 'usage: '..cmd..' [filename]')
return true return true
end end
fn = fn .. ".we" fn = minetest.get_worldpath().."/schems/"..fn..".we"
check_schematic_dir(minetest.get_worldpath()) -- Make sure WORLDDIR/schems exists
data = {} data = {}
datai = 1 datai = 1
---------- ----------
@ -400,7 +423,7 @@ minetest.register_on_chat_message(function(name, message)
end end
---------- ----------
--print(dump(data)) --print(dump(data))
table.save(data, minetest.get_modpath("worldedit").."/"..fn) table.save(data, fn)
minetest.chat_send_player(name, bs..' Blocks saved to '..fn) minetest.chat_send_player(name, bs..' Blocks saved to '..fn)
return true return true
end end
@ -415,10 +438,13 @@ minetest.register_on_chat_message(function(name, message)
minetest.chat_send_player(name, 'usage: '..cmd..' [filename]') minetest.chat_send_player(name, 'usage: '..cmd..' [filename]')
return true return true
end end
fn = minetest.get_worldpath().."/schems/"..fn
check_schematic_dir(minetest.get_worldpath()) -- Make sure WORLDDIR/schems exists
data = {} data = {}
data,err = table.load(minetest.get_modpath("worldedit").."/"..fn) data,err = table.load(fn)
if not err == nil then if data == nil then
minetest.chat_send_player(name, "Cound not load '"..fn.."'") minetest.chat_send_player(name, "Cound not load '"..fn.."'")
return true
end end
--print(dump(data)) --print(dump(data))
---------- ----------
@ -434,6 +460,33 @@ minetest.register_on_chat_message(function(name, message)
minetest.chat_send_player(name, bp..' Blocks pasted at '..to_pos_userstr(pos1)) minetest.chat_send_player(name, bp..' Blocks pasted at '..to_pos_userstr(pos1))
return true return true
end end
local cmd = "//light"
if message:sub(0, #cmd) == cmd then
if check_player_we_perms(name) then
pos1,pos2 = get_we_pos(name)
local temp = sort_pos(pos1,pos2)
pos1 = temp[1]
pos2 = temp[2]
temp = nil
local bl = 0
for x = pos1[1], pos2[1], 1 do
for y = pos1[2], pos2[2], 1 do
for z = pos1[3], pos2[3], 1 do
local np = {x=x, y=y, z=z}
local no = minetest.env:get_node(np)
no.param1 = 13
minetest.env:add_node(np, no)
bl = bl + 1
end
end
end
minetest.chat_send_player(name, bl..' Blocks lighted')
return true
else
minetest.chat_send_player(name, 'You havent got the Permission for that')
end
return true
end
end) end)
minetest.register_on_punchnode(function(p, node, puncher) minetest.register_on_punchnode(function(p, node, puncher)
if puncher:get_player_name() ~= nil then if puncher:get_player_name() ~= nil then