summaryrefslogtreecommitdiff
path: root/mesecons_commandblock
diff options
context:
space:
mode:
Diffstat (limited to 'mesecons_commandblock')
-rw-r--r--mesecons_commandblock/init.lua82
1 files changed, 39 insertions, 43 deletions
diff --git a/mesecons_commandblock/init.lua b/mesecons_commandblock/init.lua
index 345ca7c..b61c85b 100644
--- a/mesecons_commandblock/init.lua
+++ b/mesecons_commandblock/init.lua
@@ -87,11 +87,42 @@ local resolve_player = function(name, pos)
return name
end
+local commandblock_action_on = function(pos, node)
+ if node.name ~= "mesecons_commandblock:commandblock_off" then
+ return
+ end
+
+ mesecon:swap_node(pos, "mesecons_commandblock:commandblock_on")
+
+ local meta = minetest.env:get_meta(pos)
+ local command = minetest.chatcommands[meta:get_string("command")]
+ if command == nil then
+ return
+ end
+ local owner = meta:get_string("owner")
+ if owner == "" then
+ return
+ end
+ local has_privs, missing_privs = minetest.check_player_privs(owner, command.privs)
+ if not has_privs then
+ minetest.chat_send_player(owner, "You don't have permission to run this command (missing privileges: "..table.concat(missing_privs, ", ")..")")
+ return
+ end
+ local player = resolve_player(meta:get_string("player"), pos)
+ command.func(player, meta:get_string("param"))
+end
+
+local commandblock_action_off = function(pos, node)
+ if node.name == "mesecons_commandblock:commandblock_on" then
+ mesecon:swap_node(pos, "mesecons_commandblock:commandblock_off")
+ end
+end
+
minetest.register_node("mesecons_commandblock:commandblock_off", {
description = "Command Block",
tiles = {"jeija_commandblock_off.png"},
inventory_image = minetest.inventorycube("jeija_commandblock_off.png"),
- groups = {cracky=2, mesecon_effector_off=1, mesecon=2},
+ groups = {cracky=2, mesecon_effector_off=1},
on_construct = construct,
after_place_node = after_place,
on_receive_fields = receive_fields,
@@ -99,11 +130,14 @@ minetest.register_node("mesecons_commandblock:commandblock_off", {
local owner = minetest.env:get_meta(pos):get_string("owner")
return owner == "" or owner == player:get_player_name()
end,
+ mesecons = {effector = {
+ action_on = commandblock_action_on
+ }}
})
minetest.register_node("mesecons_commandblock:commandblock_on", {
tiles = {"jeija_commandblock_on.png"},
- groups = {cracky=2, mesecon_effector_on=1, mesecon=2, not_in_creative_inventory=1},
+ groups = {cracky=2, mesecon_effector_on=1, not_in_creative_inventory=1},
light_source = 10,
drop = "mesecons_commandblock:commandblock_off",
on_construct = construct,
@@ -113,45 +147,7 @@ minetest.register_node("mesecons_commandblock:commandblock_on", {
local owner = minetest.env:get_meta(pos):get_string("owner")
return owner == "" or owner == player:get_player_name()
end,
+ mesecons = {effector = {
+ action_off = commandblock_action_off
+ }}
})
-
-mesecon:register_effector("mesecons_commandblock:commandblock_on", "mesecons_commandblock:commandblock_off")
-
-local swap_node = function(pos, name)
- local node = minetest.env:get_node(pos)
- local data = minetest.env:get_meta(pos):to_table()
- node.name = name
- minetest.env:add_node(pos, node)
- minetest.env:get_meta(pos):from_table(data)
-end
-
-mesecon:register_on_signal_on(function(pos, node)
- if node.name ~= "mesecons_commandblock:commandblock_off" then
- return
- end
-
- swap_node(pos, "mesecons_commandblock:commandblock_on")
-
- local meta = minetest.env:get_meta(pos)
- local command = minetest.chatcommands[meta:get_string("command")]
- if command == nil then
- return
- end
- local owner = meta:get_string("owner")
- if owner == "" then
- return
- end
- local has_privs, missing_privs = minetest.check_player_privs(owner, command.privs)
- if not has_privs then
- minetest.chat_send_player(owner, "You don't have permission to run this command (missing privileges: "..table.concat(missing_privs, ", ")..")")
- return
- end
- local player = resolve_player(meta:get_string("player"), pos)
- command.func(player, meta:get_string("param"))
-end)
-
-mesecon:register_on_signal_off(function(pos, node)
- if node.name == "mesecons_commandblock:commandblock_on" then
- swap_node(pos, "mesecons_commandblock:commandblock_off")
- end
-end) \ No newline at end of file