From 68d8eb4c9cdf18a72292800075650ce3b51917f3 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Fri, 5 Mar 2021 09:08:46 +0100 Subject: [PATCH 1/5] make /seed like mc --- mods/MISC/mcl_commands/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/MISC/mcl_commands/init.lua b/mods/MISC/mcl_commands/init.lua index 8b931d0b8b..7ca00f7568 100644 --- a/mods/MISC/mcl_commands/init.lua +++ b/mods/MISC/mcl_commands/init.lua @@ -117,7 +117,7 @@ minetest.register_chatcommand("seed", { params = "", privs = {}, func = function(name) - minetest.chat_send_player(name, minetest.get_mapgen_setting("seed")) + minetest.chat_send_player(name, "Seed: "..minetest.get_mapgen_setting("seed")) end }) From 0e8b5c403a1a3ad413935725bf9d80032fdc53aa Mon Sep 17 00:00:00 2001 From: AFCMS Date: Fri, 5 Mar 2021 09:47:48 +0100 Subject: [PATCH 2/5] give a lua file for each command --- mods/MISC/mcl_commands/alias.lua | 25 +++++ mods/MISC/mcl_commands/init.lua | 146 ++-------------------------- mods/MISC/mcl_commands/kill.lua | 59 +++++++++++ mods/MISC/mcl_commands/say.lua | 18 ++++ mods/MISC/mcl_commands/seed.lua | 10 ++ mods/MISC/mcl_commands/setblock.lua | 22 +++++ mods/MISC/mcl_commands/summon.lua | 15 +++ 7 files changed, 156 insertions(+), 139 deletions(-) create mode 100644 mods/MISC/mcl_commands/alias.lua create mode 100644 mods/MISC/mcl_commands/kill.lua create mode 100644 mods/MISC/mcl_commands/say.lua create mode 100644 mods/MISC/mcl_commands/seed.lua create mode 100644 mods/MISC/mcl_commands/setblock.lua create mode 100644 mods/MISC/mcl_commands/summon.lua diff --git a/mods/MISC/mcl_commands/alias.lua b/mods/MISC/mcl_commands/alias.lua new file mode 100644 index 0000000000..b8273c42e0 --- /dev/null +++ b/mods/MISC/mcl_commands/alias.lua @@ -0,0 +1,25 @@ +local minecraftaliases = true + +local function register_chatcommand_alias(alias, cmd) + local def = minetest.chatcommands[cmd] + minetest.register_chatcommand(alias, def) +end + +if minecraftaliases then + register_chatcommand_alias("?", "help") + register_chatcommand_alias("who", "list") + register_chatcommand_alias("pardon", "unban") + register_chatcommand_alias("stop", "shutdown") + register_chatcommand_alias("tell", "msg") + register_chatcommand_alias("w", "msg") + register_chatcommand_alias("tp", "teleport") + register_chatcommand_alias("clear", "clearinv") + + minetest.register_chatcommand("banlist", { + description = S("List bans"), + privs = minetest.chatcommands["ban"].privs, + func = function(name) + return true, S("Ban list: @1", minetest.get_ban_list()) + end, + }) +end \ No newline at end of file diff --git a/mods/MISC/mcl_commands/init.lua b/mods/MISC/mcl_commands/init.lua index 7ca00f7568..354d555941 100644 --- a/mods/MISC/mcl_commands/init.lua +++ b/mods/MISC/mcl_commands/init.lua @@ -1,103 +1,17 @@ -local minecraftaliases = true - local S = minetest.get_translator("mcl_commands") local mod_death_messages = minetest.get_modpath("mcl_death_messages") -local function handle_kill_command(suspect, victim) - if minetest.settings:get_bool("enable_damage") == false then - return false, S("Players can't be killed right now, damage has been disabled.") - end - local victimref = minetest.get_player_by_name(victim) - if victimref == nil then - return false, S("Player @1 does not exist.", victim) - elseif victimref:get_hp() <= 0 then - if suspect == victim then - return false, S("You are already dead") - else - return false, S("@1 is already dead", victim) - end - end - -- If player holds a totem of undying, destroy it before killing, - -- so it doesn't rescue the player. - local wield = victimref:get_wielded_item() - if wield:get_name() == "mobs_mc:totem" then - victimref:set_wielded_item("") - end - if mod_death_messages then - local msg - if suspect == victim then - msg = S("@1 committed suicide.", victim) - else - msg = S("@1 was killed by @2.", victim, suspect) - end - mcl_death_messages.player_damage(victimref, msg) - end - -- DIE! - victimref:set_hp(0) - -- Log - if not suspect == victim then - minetest.log("action", string.format("%s killed %s using /kill", suspect, victim)) - else - minetest.log("action", string.format("%s committed suicide using /kill", victim)) - end - return true -end +local modpath = minetest.get_modpath(minetest.get_current_modname()) -if minetest.registered_chatcommands["kill"] then - minetest.unregister_chatcommand("kill") -end -minetest.register_chatcommand("kill", { - params = S("[]"), - description = S("Kill player or yourself"), - privs = {server=true}, - func = function(name, param) - if(param == "") then - -- Selfkill - return handle_kill_command(name, name) - else - return handle_kill_command(name, param) - end - end, -}) +dofile(modpath.."/kill.lua") +dofile(modpath.."/setblock.lua") +dofile(modpath.."/seed.lua") +dofile(modpath.."/summon.lua") +dofile(modpath.."/say.lua") -minetest.register_privilege("announce", { - description = S("Can use /say"), - give_to_singleplayer = false, -}) -minetest.register_chatcommand("say", { - params = S(""), - description = S("Send a message to every player"), - privs = {announce=true}, - func = function(name, param) - if not param then - return false, S("Invalid usage, see /help say.") - end - minetest.chat_send_all(("["..name.."] "..param)) - return true - end, -}) +dofile(modpath.."/alias.lua") -minetest.register_chatcommand("setblock", { - params = S(",, "), - description = S("Set node at given position"), - privs = {give=true, interact=true}, - func = function(name, param) - local p = {} - local nodestring = nil - p.x, p.y, p.z, nodestring = param:match("^([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+) +(.+)$") - p.x, p.y, p.z = tonumber(p.x), tonumber(p.y), tonumber(p.z) - if p.x and p.y and p.z and nodestring then - local itemstack = ItemStack(nodestring) - if itemstack:is_empty() or not minetest.registered_nodes[itemstack:get_name()] then - return false, S("Invalid node") - end - minetest.set_node(p, {name=nodestring}) - return true, S("@1 spawned.", nodestring) - end - return false, S("Invalid parameters (see /help setblock)") - end, -}) minetest.register_chatcommand("list", { description = S("Show who is logged on"), @@ -112,52 +26,6 @@ minetest.register_chatcommand("list", { end }) -minetest.register_chatcommand("seed", { - description = S("Displays the world seed"), - params = "", - privs = {}, - func = function(name) - minetest.chat_send_player(name, "Seed: "..minetest.get_mapgen_setting("seed")) - end -}) -local function register_chatcommand_alias(alias, cmd) - local def = minetest.chatcommands[cmd] - minetest.register_chatcommand(alias, def) -end --- Replace spawnentity cmd to disallow spawning of hostile mobs if disabled -local orig_func = minetest.registered_chatcommands["spawnentity"].func -local cmd = table.copy(minetest.registered_chatcommands["spawnentity"]) -cmd.func = function(name, param) - local ent = minetest.registered_entities[param] - if minetest.settings:get_bool("only_peaceful_mobs", false) and ent and ent._cmi_is_mob and ent.type == "monster" then - return false, S("Only peaceful mobs allowed!") - else - local bool, msg = orig_func(name, param) - return bool, msg - end -end -minetest.unregister_chatcommand("spawnentity") -minetest.register_chatcommand("spawnentity", cmd) - -if minecraftaliases then - register_chatcommand_alias("?", "help") - register_chatcommand_alias("who", "list") - register_chatcommand_alias("pardon", "unban") - register_chatcommand_alias("stop", "shutdown") - register_chatcommand_alias("summon", "spawnentity") - register_chatcommand_alias("tell", "msg") - register_chatcommand_alias("w", "msg") - register_chatcommand_alias("tp", "teleport") - register_chatcommand_alias("clear", "clearinv") - - minetest.register_chatcommand("banlist", { - description = S("List bans"), - privs = minetest.chatcommands["ban"].privs, - func = function(name) - return true, S("Ban list: @1", minetest.get_ban_list()) - end, - }) -end diff --git a/mods/MISC/mcl_commands/kill.lua b/mods/MISC/mcl_commands/kill.lua new file mode 100644 index 0000000000..2de69e6a0b --- /dev/null +++ b/mods/MISC/mcl_commands/kill.lua @@ -0,0 +1,59 @@ +local S = minetest.get_translator("mcl_commands") +local mod_death_messages = minetest.get_modpath("mcl_death_messages") + +local function handle_kill_command(suspect, victim) + if minetest.settings:get_bool("enable_damage") == false then + return false, S("Players can't be killed right now, damage has been disabled.") + end + local victimref = minetest.get_player_by_name(victim) + if victimref == nil then + return false, S("Player @1 does not exist.", victim) + elseif victimref:get_hp() <= 0 then + if suspect == victim then + return false, S("You are already dead") + else + return false, S("@1 is already dead", victim) + end + end + -- If player holds a totem of undying, destroy it before killing, + -- so it doesn't rescue the player. + local wield = victimref:get_wielded_item() + if wield:get_name() == "mobs_mc:totem" then + victimref:set_wielded_item("") + end + if mod_death_messages then + local msg + if suspect == victim then + msg = S("@1 committed suicide.", victim) + else + msg = S("@1 was killed by @2.", victim, suspect) + end + mcl_death_messages.player_damage(victimref, msg) + end + -- DIE! + victimref:set_hp(0) + -- Log + if not suspect == victim then + minetest.log("action", string.format("%s killed %s using /kill", suspect, victim)) + else + minetest.log("action", string.format("%s committed suicide using /kill", victim)) + end + return true +end + +if minetest.registered_chatcommands["kill"] then + minetest.unregister_chatcommand("kill") +end +minetest.register_chatcommand("kill", { + params = S("[]"), + description = S("Kill player or yourself"), + privs = {server=true}, + func = function(name, param) + if(param == "") then + -- Selfkill + return handle_kill_command(name, name) + else + return handle_kill_command(name, param) + end + end, +}) \ No newline at end of file diff --git a/mods/MISC/mcl_commands/say.lua b/mods/MISC/mcl_commands/say.lua new file mode 100644 index 0000000000..2b01a7e935 --- /dev/null +++ b/mods/MISC/mcl_commands/say.lua @@ -0,0 +1,18 @@ +local S = minetest.get_translator("mcl_commands") + +minetest.register_privilege("announce", { + description = S("Can use /say"), + give_to_singleplayer = false, +}) +minetest.register_chatcommand("say", { + params = S(""), + description = S("Send a message to every player"), + privs = {announce=true}, + func = function(name, param) + if not param then + return false, S("Invalid usage, see /help say.") + end + minetest.chat_send_all(("["..name.."] "..param)) + return true + end, +}) \ No newline at end of file diff --git a/mods/MISC/mcl_commands/seed.lua b/mods/MISC/mcl_commands/seed.lua new file mode 100644 index 0000000000..da5f6a3039 --- /dev/null +++ b/mods/MISC/mcl_commands/seed.lua @@ -0,0 +1,10 @@ +local S = minetest.get_translator("mcl_commands") + +minetest.register_chatcommand("seed", { + description = S("Displays the world seed"), + params = "", + privs = {}, + func = function(name) + minetest.chat_send_player(name, "Seed: "..minetest.get_mapgen_setting("seed")) + end +}) \ No newline at end of file diff --git a/mods/MISC/mcl_commands/setblock.lua b/mods/MISC/mcl_commands/setblock.lua new file mode 100644 index 0000000000..30d68b74fa --- /dev/null +++ b/mods/MISC/mcl_commands/setblock.lua @@ -0,0 +1,22 @@ +local S = minetest.get_translator("mcl_commands") + +minetest.register_chatcommand("setblock", { + params = S(",, "), + description = S("Set node at given position"), + privs = {give=true, interact=true}, + func = function(name, param) + local p = {} + local nodestring = nil + p.x, p.y, p.z, nodestring = param:match("^([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+) +(.+)$") + p.x, p.y, p.z = tonumber(p.x), tonumber(p.y), tonumber(p.z) + if p.x and p.y and p.z and nodestring then + local itemstack = ItemStack(nodestring) + if itemstack:is_empty() or not minetest.registered_nodes[itemstack:get_name()] then + return false, S("Invalid node") + end + minetest.set_node(p, {name=nodestring}) + return true, S("@1 spawned.", nodestring) + end + return false, S("Invalid parameters (see /help setblock)") + end, +}) \ No newline at end of file diff --git a/mods/MISC/mcl_commands/summon.lua b/mods/MISC/mcl_commands/summon.lua new file mode 100644 index 0000000000..eb6066ff87 --- /dev/null +++ b/mods/MISC/mcl_commands/summon.lua @@ -0,0 +1,15 @@ +local S = minetest.get_translator("mcl_commands") + +local orig_func = minetest.registered_chatcommands["spawnentity"].func +local cmd = table.copy(minetest.registered_chatcommands["spawnentity"]) +cmd.func = function(name, param) + local ent = minetest.registered_entities[param] + if minetest.settings:get_bool("only_peaceful_mobs", false) and ent and ent._cmi_is_mob and ent.type == "monster" then + return false, S("Only peaceful mobs allowed!") + else + local bool, msg = orig_func(name, param) + return bool, msg + end +end +minetest.unregister_chatcommand("spawnentity") +minetest.register_chatcommand("summon", cmd) \ No newline at end of file From d71e296602c08f550c767181ec99ee28a09e5130 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Fri, 5 Mar 2021 09:58:47 +0100 Subject: [PATCH 3/5] fix crash --- mods/MISC/mcl_commands/alias.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mods/MISC/mcl_commands/alias.lua b/mods/MISC/mcl_commands/alias.lua index b8273c42e0..41d583d899 100644 --- a/mods/MISC/mcl_commands/alias.lua +++ b/mods/MISC/mcl_commands/alias.lua @@ -1,3 +1,5 @@ +local S = minetest.get_translator("mcl_commands") + local minecraftaliases = true local function register_chatcommand_alias(alias, cmd) From b1ab79b857a4d83eae2752c01518c73f99dadca2 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Fri, 5 Mar 2021 10:22:52 +0100 Subject: [PATCH 4/5] fix last command --- mods/MISC/mcl_commands/init.lua | 21 ++------------------- mods/MISC/mcl_commands/list.lua | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 19 deletions(-) create mode 100644 mods/MISC/mcl_commands/list.lua diff --git a/mods/MISC/mcl_commands/init.lua b/mods/MISC/mcl_commands/init.lua index 354d555941..c078e5872e 100644 --- a/mods/MISC/mcl_commands/init.lua +++ b/mods/MISC/mcl_commands/init.lua @@ -9,23 +9,6 @@ dofile(modpath.."/setblock.lua") dofile(modpath.."/seed.lua") dofile(modpath.."/summon.lua") dofile(modpath.."/say.lua") +dofile(modpath.."/list.lua") -dofile(modpath.."/alias.lua") - - -minetest.register_chatcommand("list", { - description = S("Show who is logged on"), - params = "", - privs = {}, - func = function(name) - local players = "" - for _, player in ipairs(minetest.get_connected_players()) do - players = players..player:get_player_name().."\n" - end - minetest.chat_send_player(name, players) - end -}) - - - - +dofile(modpath.."/alias.lua") \ No newline at end of file diff --git a/mods/MISC/mcl_commands/list.lua b/mods/MISC/mcl_commands/list.lua new file mode 100644 index 0000000000..0257e2837c --- /dev/null +++ b/mods/MISC/mcl_commands/list.lua @@ -0,0 +1,14 @@ +local S = minetest.get_translator("mcl_commands") + +minetest.register_chatcommand("list", { + description = S("Show who is logged on"), + params = "", + privs = {}, + func = function(name) + local players = "" + for _, player in ipairs(minetest.get_connected_players()) do + players = players..player:get_player_name().."\n" + end + minetest.chat_send_player(name, players) + end +}) \ No newline at end of file From e3eb8c7ac81714e5d7fad9804ea7854f528e2593 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Fri, 5 Mar 2021 16:37:56 +0100 Subject: [PATCH 5/5] add /playsound command --- mods/MISC/mcl_commands/init.lua | 1 + mods/MISC/mcl_commands/sound.lua | 48 ++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 mods/MISC/mcl_commands/sound.lua diff --git a/mods/MISC/mcl_commands/init.lua b/mods/MISC/mcl_commands/init.lua index c078e5872e..7a9fe4868b 100644 --- a/mods/MISC/mcl_commands/init.lua +++ b/mods/MISC/mcl_commands/init.lua @@ -10,5 +10,6 @@ dofile(modpath.."/seed.lua") dofile(modpath.."/summon.lua") dofile(modpath.."/say.lua") dofile(modpath.."/list.lua") +dofile(modpath.."/sound.lua") dofile(modpath.."/alias.lua") \ No newline at end of file diff --git a/mods/MISC/mcl_commands/sound.lua b/mods/MISC/mcl_commands/sound.lua new file mode 100644 index 0000000000..934abb80eb --- /dev/null +++ b/mods/MISC/mcl_commands/sound.lua @@ -0,0 +1,48 @@ +local S = minetest.get_translator("mcl_commands") + +minetest.register_chatcommand("playsound",{ + params = S(" "), --TODO:add source + description = S("Play a sound. Arguments: : name of the sound. : Target."), + privs = {server = true}, + func = function(name, params) + local P = {} + local i = 0 + for str in string.gmatch(params, "([^ ]+)") do + i = i + 1 + P[i] = str + end + + local params = {} + if P[1] == tostring(P[1]) then + params.name = P[1] + else + return false, S("Sound name is invalid!") --TODO: add mc chat message + end + + if P[2] == tostring(P[2]) and minetest.player_exists(P[2]) then + params.target = P[2] + else + return false, S("Target is invalid!!") + end + + -- if P[3] then + -- params.pos = nil --TODO:position + -- else + -- params.pos = nil + -- end + + -- if P[4] == tonumber(P[4]) then + -- params.gain = P[4] + -- else + -- params.gain = 1.0 + -- end + + -- if P[5] == tonumber(P[5]) then + -- params.pitch = P[5] + -- else + -- params.pitch = 1.0 + -- end + minetest.sound_play({name = params.name}, {to_player = params.target}, true) --TODO: /stopsound + return true + end, +}) \ No newline at end of file