From 3f0bfa0aa876c75436eb6431973ab023eae83798 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Wed, 13 Dec 2017 00:30:23 +0100 Subject: [PATCH] Add maphack privilege for advanced blocks like command blocks --- README.md | 4 +- .../REDSTONE/mesecons_commandblock/init.lua | 37 ++++++++++++++++++- mods/ITEMS/mcl_core/nodes_misc.lua | 22 +++++++++++ mods/ITEMS/mcl_mobspawners/init.lua | 20 +++++++++- mods/MISC/mcl_privs/description.txt | 1 + mods/MISC/mcl_privs/init.lua | 3 ++ 6 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 mods/MISC/mcl_privs/description.txt create mode 100644 mods/MISC/mcl_privs/init.lua diff --git a/README.md b/README.md index 858d0195cd..a6d05c5e40 100644 --- a/README.md +++ b/README.md @@ -60,9 +60,7 @@ The following items are interesting for Creative Mode and for adventure map builders. They can not be obtained in-game or in the creative inventory. * Barrier: `mcl_core:barrier` -* Command Block: `mesecons_commandblock:commandblock_off` -* Monster Spawner: `mcl_mobspawners:spawner` -* Minecart with Command Block: `mcl_minecarts:command_block_minecart` +* Minecart with Command Block (does not work yet): `mcl_minecarts:command_block_minecart` Use the `/giveme` chat command to obtain them. See the in-game help for an explanation. diff --git a/mods/ITEMS/REDSTONE/mesecons_commandblock/init.lua b/mods/ITEMS/REDSTONE/mesecons_commandblock/init.lua index 9da011fd2b..42921f6259 100644 --- a/mods/ITEMS/REDSTONE/mesecons_commandblock/init.lua +++ b/mods/ITEMS/REDSTONE/mesecons_commandblock/init.lua @@ -106,6 +106,11 @@ local on_rightclick = function(pos, node, player, itemstack, pointed_thing) if not minetest.settings:get_bool("creative_mode") then return end + local privs = minetest.get_player_privs(player:get_player_name()) + if not privs.maphack then + minetest.chat_send_player(player:get_player_name(), "Access denied. You need the “maphack” privilege to edit command blocks.") + return + end local meta = minetest.get_meta(pos) local commands = meta:get_string("commands") @@ -118,6 +123,28 @@ local on_rightclick = function(pos, node, player, itemstack, pointed_thing) minetest.show_formspec(player:get_player_name(), "commandblock_"..pos.x.."_"..pos.y.."_"..pos.z, formspec) end +local on_place = function(itemstack, placer, pointed_thing) + if pointed_thing.type ~= "node" then + return itemstack + end + + -- Use pointed node's on_rightclick function first, if present + local node = minetest.get_node(pointed_thing.under) + if placer and not placer:get_player_control().sneak then + if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then + return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, placer, itemstack) or itemstack + end + end + + local privs = minetest.get_player_privs(placer:get_player_name()) + if not privs.maphack then + minetest.chat_send_player(placer:get_player_name(), "Placement denied. You need the “maphack” privilege to place command blocks.") + return itemstack + end + + return minetest.item_place_node(itemstack, placer, pointed_thing) +end + minetest.register_node("mesecons_commandblock:commandblock_off", { description = "Command Block", @@ -134,11 +161,12 @@ You can optionally use the following placeholders in your commands: • “@random” is replaced by the name of a random player currently connected]], tiles = {{name="jeija_commandblock_off.png", animation={type="vertical_frames", aspect_w=32, aspect_h=32, length=2}}}, - groups = {creative_breakable=1, mesecon_effector_off=1, not_in_creative_inventory=1}, + groups = {creative_breakable=1, mesecon_effector_off=1}, drop = "", on_blast = function() end, on_construct = construct, is_ground_content = false, + on_place = on_place, after_place_node = after_place, on_rightclick = on_rightclick, sounds = mcl_sounds.node_sound_stone_defaults(), @@ -157,6 +185,7 @@ minetest.register_node("mesecons_commandblock:commandblock_on", { on_blast = function() end, on_construct = construct, is_ground_content = false, + on_place = on_place, after_place_node = after_place, on_rightclick = on_rightclick, sounds = mcl_sounds.node_sound_stone_defaults(), @@ -173,6 +202,12 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) if not fields.submit and not fields.doc then return end + local privs = minetest.get_player_privs(player:get_player_name()) + if not privs.maphack then + minetest.chat_send_player(player:get_player_name(), "Access denied. You need the “maphack” privilege to edit command blocks.") + return + end + if fields.doc and minetest.get_modpath("doc") then doc.show_entry(player:get_player_name(), "nodes", "mesecons_commandblock:commandblock_off", true) return diff --git a/mods/ITEMS/mcl_core/nodes_misc.lua b/mods/ITEMS/mcl_core/nodes_misc.lua index 07f30743fe..65685f6972 100644 --- a/mods/ITEMS/mcl_core/nodes_misc.lua +++ b/mods/ITEMS/mcl_core/nodes_misc.lua @@ -142,6 +142,28 @@ minetest.register_node("mcl_core:barrier", { playername = placer:get_player_name() }) end, + on_place = function(itemstack, placer, pointed_thing) + if pointed_thing.type ~= "node" then + return itemstack + end + + -- Use pointed node's on_rightclick function first, if present + local node = minetest.get_node(pointed_thing.under) + if placer and not placer:get_player_control().sneak then + if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then + return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, placer, itemstack) or itemstack + end + end + + local name = placer:get_player_name() + local privs = minetest.get_player_privs(name) + if not privs.maphack then + minetest.chat_send_player(name, "Placement denied. You need the “maphack” privilege to place barriers.") + return itemstack + end + local new_itemstack = minetest.item_place(itemstack, placer, pointed_thing) + return new_itemstack + end, }) -- Same as barrier, but non-pointable. This node is only to be used internally to separate realms. diff --git a/mods/ITEMS/mcl_mobspawners/init.lua b/mods/ITEMS/mcl_mobspawners/init.lua index f6e9fc07cb..81ecaaebd8 100644 --- a/mods/ITEMS/mcl_mobspawners/init.lua +++ b/mods/ITEMS/mcl_mobspawners/init.lua @@ -216,12 +216,30 @@ minetest.register_node("mcl_mobspawners:spawner", { walkable = true, description = S("Monster Spawner"), _doc_items_longdesc = S("A monster spawner is a block which regularily causes monsters and animals to appear around it."), - groups = {pickaxey=1, not_in_creative_inventory = 1, material_stone=1}, + groups = {pickaxey=1, material_stone=1, deco_block=1}, is_ground_content = false, drop = "", -- If placed by player, setup spawner with default settings on_place = function(itemstack, placer, pointed_thing) + if pointed_thing.type ~= "node" then + return itemstack + end + + -- Use pointed node's on_rightclick function first, if present + local node = minetest.get_node(pointed_thing.under) + if placer and not placer:get_player_control().sneak then + if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then + return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, placer, itemstack) or itemstack + end + end + + local name = placer:get_player_name() + local privs = minetest.get_player_privs(name) + if not privs.maphack then + minetest.chat_send_player(name, "Placement denied. You need the “maphack” privilege to place monster spawners.") + return itemstack + end local node_under = minetest.get_node(pointed_thing.under) local new_itemstack, success = minetest.item_place(itemstack, placer, pointed_thing) if success then diff --git a/mods/MISC/mcl_privs/description.txt b/mods/MISC/mcl_privs/description.txt new file mode 100644 index 0000000000..23beb168ba --- /dev/null +++ b/mods/MISC/mcl_privs/description.txt @@ -0,0 +1 @@ +Shared privileges in MineClone 2 diff --git a/mods/MISC/mcl_privs/init.lua b/mods/MISC/mcl_privs/init.lua new file mode 100644 index 0000000000..ef308aba85 --- /dev/null +++ b/mods/MISC/mcl_privs/init.lua @@ -0,0 +1,3 @@ +minetest.register_privilege("maphack", { + description = "Can place and use advanced blocks like monster spawners, command blocks and barriers.", +})