mirror of
https://github.com/minetest-mods/mesecons.git
synced 2024-12-27 07:47:30 +01:00
Consistently use UNIX line endings (LF instead of CR LF)
This commit is contained in:
parent
80f72b2621
commit
7b84105512
@ -1,15 +1,15 @@
|
|||||||
-- SETTINGS
|
-- SETTINGS
|
||||||
function mesecon.setting(setting, default)
|
function mesecon.setting(setting, default)
|
||||||
if type(default) == "boolean" then
|
if type(default) == "boolean" then
|
||||||
local read = minetest.setting_getbool("mesecon."..setting)
|
local read = minetest.setting_getbool("mesecon."..setting)
|
||||||
if read == nil then
|
if read == nil then
|
||||||
return default
|
return default
|
||||||
else
|
else
|
||||||
return read
|
return read
|
||||||
end
|
end
|
||||||
elseif type(default) == "string" then
|
elseif type(default) == "string" then
|
||||||
return minetest.setting_get("mesecon."..setting) or default
|
return minetest.setting_get("mesecon."..setting) or default
|
||||||
elseif type(default) == "number" then
|
elseif type(default) == "number" then
|
||||||
return tonumber(minetest.setting_get("mesecon."..setting) or default)
|
return tonumber(minetest.setting_get("mesecon."..setting) or default)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,195 +1,195 @@
|
|||||||
minetest.register_chatcommand("say", {
|
minetest.register_chatcommand("say", {
|
||||||
params = "<text>",
|
params = "<text>",
|
||||||
description = "Say <text> as the server",
|
description = "Say <text> as the server",
|
||||||
privs = {server=true},
|
privs = {server=true},
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
minetest.chat_send_all(name .. ": " .. param)
|
minetest.chat_send_all(name .. ": " .. param)
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_chatcommand("tell", {
|
minetest.register_chatcommand("tell", {
|
||||||
params = "<name> <text>",
|
params = "<name> <text>",
|
||||||
description = "Say <text> to <name> privately",
|
description = "Say <text> to <name> privately",
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
local found, _, target, message = param:find("^([^%s]+)%s+(.*)$")
|
local found, _, target, message = param:find("^([^%s]+)%s+(.*)$")
|
||||||
if found == nil then
|
if found == nil then
|
||||||
minetest.chat_send_player(name, "Invalid usage: " .. param)
|
minetest.chat_send_player(name, "Invalid usage: " .. param)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if not minetest.get_player_by_name(target) then
|
if not minetest.get_player_by_name(target) then
|
||||||
minetest.chat_send_player(name, "Invalid target: " .. target)
|
minetest.chat_send_player(name, "Invalid target: " .. target)
|
||||||
end
|
end
|
||||||
minetest.chat_send_player(target, name .. " whispers: " .. message, false)
|
minetest.chat_send_player(target, name .. " whispers: " .. message, false)
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_chatcommand("hp", {
|
minetest.register_chatcommand("hp", {
|
||||||
params = "<name> <value>",
|
params = "<name> <value>",
|
||||||
description = "Set health of <name> to <value> hitpoints",
|
description = "Set health of <name> to <value> hitpoints",
|
||||||
privs = {ban=true},
|
privs = {ban=true},
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
local found, _, target, value = param:find("^([^%s]+)%s+(%d+)$")
|
local found, _, target, value = param:find("^([^%s]+)%s+(%d+)$")
|
||||||
if found == nil then
|
if found == nil then
|
||||||
minetest.chat_send_player(name, "Invalid usage: " .. param)
|
minetest.chat_send_player(name, "Invalid usage: " .. param)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local player = minetest.get_player_by_name(target)
|
local player = minetest.get_player_by_name(target)
|
||||||
if player then
|
if player then
|
||||||
player:set_hp(value)
|
player:set_hp(value)
|
||||||
else
|
else
|
||||||
minetest.chat_send_player(name, "Invalid target: " .. target)
|
minetest.chat_send_player(name, "Invalid target: " .. target)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
local function initialize_data(meta)
|
local function initialize_data(meta)
|
||||||
local commands = meta:get_string("commands")
|
local commands = meta:get_string("commands")
|
||||||
meta:set_string("formspec",
|
meta:set_string("formspec",
|
||||||
"invsize[9,5;]" ..
|
"invsize[9,5;]" ..
|
||||||
"textarea[0.5,0.5;8.5,4;commands;Commands;"..commands.."]" ..
|
"textarea[0.5,0.5;8.5,4;commands;Commands;"..commands.."]" ..
|
||||||
"label[1,3.8;@nearest, @farthest, and @random are replaced by the respective player names]" ..
|
"label[1,3.8;@nearest, @farthest, and @random are replaced by the respective player names]" ..
|
||||||
"button_exit[3.3,4.5;2,1;submit;Submit]")
|
"button_exit[3.3,4.5;2,1;submit;Submit]")
|
||||||
local owner = meta:get_string("owner")
|
local owner = meta:get_string("owner")
|
||||||
if owner == "" then
|
if owner == "" then
|
||||||
owner = "not owned"
|
owner = "not owned"
|
||||||
else
|
else
|
||||||
owner = "owned by " .. owner
|
owner = "owned by " .. owner
|
||||||
end
|
end
|
||||||
meta:set_string("infotext", "Command Block\n" ..
|
meta:set_string("infotext", "Command Block\n" ..
|
||||||
"(" .. owner .. ")\n" ..
|
"(" .. owner .. ")\n" ..
|
||||||
"Commands: "..commands)
|
"Commands: "..commands)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function construct(pos)
|
local function construct(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
|
|
||||||
meta:set_string("commands", "tell @nearest Commandblock unconfigured")
|
meta:set_string("commands", "tell @nearest Commandblock unconfigured")
|
||||||
|
|
||||||
meta:set_string("owner", "")
|
meta:set_string("owner", "")
|
||||||
|
|
||||||
initialize_data(meta)
|
initialize_data(meta)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function after_place(pos, placer)
|
local function after_place(pos, placer)
|
||||||
if placer then
|
if placer then
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
meta:set_string("owner", placer:get_player_name())
|
meta:set_string("owner", placer:get_player_name())
|
||||||
initialize_data(meta)
|
initialize_data(meta)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function receive_fields(pos, formname, fields, sender)
|
local function receive_fields(pos, formname, fields, sender)
|
||||||
if not fields.submit then
|
if not fields.submit then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local owner = meta:get_string("owner")
|
local owner = meta:get_string("owner")
|
||||||
if owner ~= "" and sender:get_player_name() ~= owner then
|
if owner ~= "" and sender:get_player_name() ~= owner then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
meta:set_string("commands", fields.commands)
|
meta:set_string("commands", fields.commands)
|
||||||
|
|
||||||
initialize_data(meta)
|
initialize_data(meta)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function resolve_commands(commands, pos)
|
local function resolve_commands(commands, pos)
|
||||||
local nearest, farthest = nil, nil
|
local nearest, farthest = nil, nil
|
||||||
local min_distance, max_distance = math.huge, -1
|
local min_distance, max_distance = math.huge, -1
|
||||||
local players = minetest.get_connected_players()
|
local players = minetest.get_connected_players()
|
||||||
for index, player in pairs(players) do
|
for index, player in pairs(players) do
|
||||||
local distance = vector.distance(pos, player:getpos())
|
local distance = vector.distance(pos, player:getpos())
|
||||||
if distance < min_distance then
|
if distance < min_distance then
|
||||||
min_distance = distance
|
min_distance = distance
|
||||||
nearest = player:get_player_name()
|
nearest = player:get_player_name()
|
||||||
end
|
end
|
||||||
if distance > max_distance then
|
if distance > max_distance then
|
||||||
max_distance = distance
|
max_distance = distance
|
||||||
farthest = player:get_player_name()
|
farthest = player:get_player_name()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local random = players[math.random(#players)]:get_player_name()
|
local random = players[math.random(#players)]:get_player_name()
|
||||||
commands = commands:gsub("@nearest", nearest)
|
commands = commands:gsub("@nearest", nearest)
|
||||||
commands = commands:gsub("@farthest", farthest)
|
commands = commands:gsub("@farthest", farthest)
|
||||||
commands = commands:gsub("@random", random)
|
commands = commands:gsub("@random", random)
|
||||||
return commands
|
return commands
|
||||||
end
|
end
|
||||||
|
|
||||||
local function commandblock_action_on(pos, node)
|
local function commandblock_action_on(pos, node)
|
||||||
if node.name ~= "mesecons_commandblock:commandblock_off" then
|
if node.name ~= "mesecons_commandblock:commandblock_off" then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.swap_node(pos, {name = "mesecons_commandblock:commandblock_on"})
|
minetest.swap_node(pos, {name = "mesecons_commandblock:commandblock_on"})
|
||||||
|
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local owner = meta:get_string("owner")
|
local owner = meta:get_string("owner")
|
||||||
if owner == "" then
|
if owner == "" then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local commands = resolve_commands(meta:get_string("commands"), pos)
|
local commands = resolve_commands(meta:get_string("commands"), pos)
|
||||||
for _, command in pairs(commands:split("\n")) do
|
for _, command in pairs(commands:split("\n")) do
|
||||||
local pos = command:find(" ")
|
local pos = command:find(" ")
|
||||||
local cmd, param = command, ""
|
local cmd, param = command, ""
|
||||||
if pos then
|
if pos then
|
||||||
cmd = command:sub(1, pos - 1)
|
cmd = command:sub(1, pos - 1)
|
||||||
param = command:sub(pos + 1)
|
param = command:sub(pos + 1)
|
||||||
end
|
end
|
||||||
local cmddef = minetest.chatcommands[cmd]
|
local cmddef = minetest.chatcommands[cmd]
|
||||||
if not cmddef then
|
if not cmddef then
|
||||||
minetest.chat_send_player(owner, "The command "..cmd.." does not exist")
|
minetest.chat_send_player(owner, "The command "..cmd.." does not exist")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local has_privs, missing_privs = minetest.check_player_privs(owner, cmddef.privs)
|
local has_privs, missing_privs = minetest.check_player_privs(owner, cmddef.privs)
|
||||||
if not has_privs then
|
if not has_privs then
|
||||||
minetest.chat_send_player(owner, "You don't have permission "
|
minetest.chat_send_player(owner, "You don't have permission "
|
||||||
.."to run "..cmd
|
.."to run "..cmd
|
||||||
.." (missing privileges: "
|
.." (missing privileges: "
|
||||||
..table.concat(missing_privs, ", ")..")")
|
..table.concat(missing_privs, ", ")..")")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
cmddef.func(owner, param)
|
cmddef.func(owner, param)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function commandblock_action_off(pos, node)
|
local function commandblock_action_off(pos, node)
|
||||||
if node.name == "mesecons_commandblock:commandblock_on" then
|
if node.name == "mesecons_commandblock:commandblock_on" then
|
||||||
minetest.swap_node(pos, {name = "mesecons_commandblock:commandblock_off"})
|
minetest.swap_node(pos, {name = "mesecons_commandblock:commandblock_off"})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function can_dig(pos, player)
|
local function can_dig(pos, player)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local owner = meta:get_string("owner")
|
local owner = meta:get_string("owner")
|
||||||
return owner == "" or owner == player:get_player_name()
|
return owner == "" or owner == player:get_player_name()
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_node("mesecons_commandblock:commandblock_off", {
|
minetest.register_node("mesecons_commandblock:commandblock_off", {
|
||||||
description = "Command Block",
|
description = "Command Block",
|
||||||
tiles = {"jeija_commandblock_off.png"},
|
tiles = {"jeija_commandblock_off.png"},
|
||||||
inventory_image = minetest.inventorycube("jeija_commandblock_off.png"),
|
inventory_image = minetest.inventorycube("jeija_commandblock_off.png"),
|
||||||
groups = {cracky=2, mesecon_effector_off=1},
|
groups = {cracky=2, mesecon_effector_off=1},
|
||||||
on_construct = construct,
|
on_construct = construct,
|
||||||
after_place_node = after_place,
|
after_place_node = after_place,
|
||||||
on_receive_fields = receive_fields,
|
on_receive_fields = receive_fields,
|
||||||
can_dig = can_dig,
|
can_dig = can_dig,
|
||||||
sounds = default.node_sound_stone_defaults(),
|
sounds = default.node_sound_stone_defaults(),
|
||||||
mesecons = {effector = {
|
mesecons = {effector = {
|
||||||
action_on = commandblock_action_on
|
action_on = commandblock_action_on
|
||||||
}}
|
}}
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_node("mesecons_commandblock:commandblock_on", {
|
minetest.register_node("mesecons_commandblock:commandblock_on", {
|
||||||
tiles = {"jeija_commandblock_on.png"},
|
tiles = {"jeija_commandblock_on.png"},
|
||||||
groups = {cracky=2, mesecon_effector_on=1, not_in_creative_inventory=1},
|
groups = {cracky=2, mesecon_effector_on=1, not_in_creative_inventory=1},
|
||||||
light_source = 10,
|
light_source = 10,
|
||||||
drop = "mesecons_commandblock:commandblock_off",
|
drop = "mesecons_commandblock:commandblock_off",
|
||||||
on_construct = construct,
|
on_construct = construct,
|
||||||
after_place_node = after_place,
|
after_place_node = after_place,
|
||||||
on_receive_fields = receive_fields,
|
on_receive_fields = receive_fields,
|
||||||
can_dig = can_dig,
|
can_dig = can_dig,
|
||||||
sounds = default.node_sound_stone_defaults(),
|
sounds = default.node_sound_stone_defaults(),
|
||||||
mesecons = {effector = {
|
mesecons = {effector = {
|
||||||
action_off = commandblock_action_off
|
action_off = commandblock_action_off
|
||||||
}}
|
}}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user