Remove player privilege
[MineClone/MineClone2.git] / mods / MISC / mcl_commands / init.lua
blobb7ce1e1cd8fd6bc9711b953dd587ce97e9168f6b
1 local minecraftaliases = true
3 local S
4 if minetest.get_modpath("intllib") then
5 S = intllib.Getter()
6 else
7 S = function(s,a,...)a={a,...}return s:gsub("@(%d+)",function(n)return a[tonumber(n)]end)end
8 end
10 local function handle_kill_command(suspect, victim)
11 if minetest.settings:get_bool("enable_damage") == false then
12 return false, S("Players can't be killed right now, damage has been disabled.")
13 end
14 local victimref = minetest.get_player_by_name(victim)
15 if victimref == nil then
16 return false, S("Player @1 does not exist.", victim)
17 elseif victimref:get_hp() <= 0 then
18 if suspect == victim then
19 return false, S("You are already dead")
20 else
21 return false, S("@1 is already dead", victim)
22 end
23 end
24 if not suspect == victim then
25 minetest.log("action", S("@1 killed @2", suspect, victim))
26 end
27 -- If player holds a totem of undying, destroy it before killing,
28 -- so it doesn't rescue the player.
29 local wield = victimref:get_wielded_item()
30 if wield:get_name() == "mobs_mc:totem" then
31 victimref:set_wielded_item("")
32 end
33 -- DIE!
34 victimref:set_hp(0)
35 return true
36 end
38 if minetest.registered_chatcommands["kill"] then
39 minetest.unregister_chatcommand("kill")
40 end
41 minetest.register_chatcommand("kill", {
42 params = S("[<name>]"),
43 description = S("Kill player or yourself"),
44 privs = {server=true},
45 func = function(name, param)
46 if(param == "") then
47 -- Selfkill
48 return handle_kill_command(name, name)
49 else
50 return handle_kill_command(name, param)
51 end
52 end,
55 minetest.register_privilege("announce", {
56 description = S("Can use /say"),
57 give_to_singleplayer = false,
59 minetest.register_chatcommand("say", {
60 params = S("<message>"),
61 description = S("Send a message to every player"),
62 privs = {announce=true},
63 func = function(name, param)
64 if not param then
65 return false, S("Invalid usage, see /help say.")
66 end
67 minetest.chat_send_all(("["..name.."] "..param))
68 return true
69 end,
72 minetest.register_chatcommand("setblock", {
73 params = S("<X>,<Y>,<Z> <NodeString>"),
74 description = S("Set node at given position"),
75 privs = {give=true, interact=true},
76 func = function(name, param)
77 local p = {}
78 local nodestring = nil
79 p.x, p.y, p.z, nodestring = param:match("^([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+) +(.+)$")
80 p.x, p.y, p.z = tonumber(p.x), tonumber(p.y), tonumber(p.z)
81 if p.x and p.y and p.z and nodestring then
82 local itemstack = ItemStack(nodestring)
83 if itemstack:is_empty() or not minetest.registered_nodes[itemstack:get_name()] then
84 return false, S("Invalid node")
85 end
86 minetest.set_node(p, {name=nodestring})
87 return true, S("@1 spawned.", nodestring)
88 end
89 return false, S("Invalid parameters (see /help setblock)")
90 end,
93 minetest.register_chatcommand("list", {
94 description = "Show who is logged on",
95 params = "",
96 privs = {},
97 func = function(name)
98 local players = ""
99 for _, player in ipairs(minetest.get_connected_players()) do
100 players = players..player:get_player_name().."\n"
102 minetest.chat_send_player(name, players)
106 minetest.register_chatcommand("seed", {
107 description = "Displays the world seed",
108 params = "",
109 privs = {},
110 func = function(name)
111 minetest.chat_send_player(name, minetest.get_mapgen_setting("seed"))
115 local function register_chatcommand_alias(alias, cmd)
116 local def = minetest.chatcommands[cmd]
117 minetest.register_chatcommand(alias, def)
120 if minecraftaliases then
121 register_chatcommand_alias("?", "help")
122 register_chatcommand_alias("who", "list")
123 register_chatcommand_alias("pardon", "unban")
124 register_chatcommand_alias("stop", "shutdown")
125 register_chatcommand_alias("summon", "spawnentity")
126 register_chatcommand_alias("tell", "msg")
127 register_chatcommand_alias("w", "msg")
128 register_chatcommand_alias("tp", "teleport")
129 register_chatcommand_alias("clear", "clearinv")
131 minetest.register_chatcommand("banlist", {
132 description = S("List bans"),
133 privs = minetest.chatcommands["ban"].privs,
134 func = function(name)
135 return true, S("Ban list: @1", core.get_ban_list())
136 end,