]> git.lizzy.rs Git - elidragon.git/blob - commands.lua
Create LICENSE
[elidragon.git] / commands.lua
1 minetest.register_chatcommand("setnews", {
2         params = "<news>",
3         description = "Set news",
4         privs = {server = true},
5         func = function(player, param)
6                 elidragon.savedata.news = param
7         end,
8 })
9 minetest.register_chatcommand("exec", {
10         params = "<player> <cmd>",
11         description = "Force a player to execute an command.",
12         privs = {server = true},
13         func = function(player, param)
14                 minetest.chat_send_player(player, "/exec is deprecated. Use /sudo instead")
15                 if param:split(' ') and minetest.chatcommands[param:split(' ')[2]] then
16                         minetest.chatcommands[param:split(' ')[2]].func(param:split(' ')[1])
17                 end
18         end,
19 })
20 minetest.register_chatcommand("execparam", {
21         params = "<player>-<cmd>-<param>",
22         description = "Force a player to execute an command with parameters.",
23         privs = {server = true},
24         func = function(player, param)
25                 minetest.chat_send_player(player, "/execparam is deprecated. Use /sudo instead")
26                 minetest.chatcommands[param:split('-')[2]].func(param:split('-')[1],param:split('-')[3])
27         end,
28 })
29 minetest.register_chatcommand("message", {
30         params = "[[<player>-]color>-]<message>",
31         description = "Send a message as the server.",
32         privs = {server = true},
33         func = function(player, param)
34         elidragon.message(param)
35         end,
36 })
37 minetest.register_chatcommand("colormsg", {
38         params = "[[<player>-]color>-]<message>",
39         description = "Send a message as the server. [deprecated, replaced my the message command]",
40         privs = {server = true},
41         func = function(name, param)
42         elidragon.message(param)
43         minetest.chat_send_player(name, "/colormsg is deprecated. Use /message instead")
44         end,
45 })
46 minetest.register_chatcommand("colormsgone", {
47         params = "[[<player>-]color>-]<message>",
48         description = "Send a message as the server. [deprecated, replaced my the message command]",
49         privs = {server = true},
50         func = function(name, param)
51         elidragon.message(param)
52          minetest.chat_send_player(name, "/colormsgone is deprecated. Use /message instead")
53         end,
54 })
55
56 minetest.register_chatcommand("wielded", {
57         params = "",
58         description = "Print Itemstring of wielded Item",
59         func = function(name, param)
60                 local player = minetest.get_player_by_name(name)
61         if player then
62             local item = player:get_wielded_item()
63             if item then 
64                 minetest.chat_send_player(name, item:get_name())
65             end
66         end
67         end,
68 })
69
70 minetest.register_chatcommand("sudo", {
71         description = "Force other players to run commands",
72         params = "<player> <command> <arguments...>",
73         privs = {server = true},
74         func = function(name, param)
75                 local target = param:split(" ")[1]
76                 local command = param:split(" ")[2]
77                 local arguments
78                 local argumentsdisp
79                 local cmddef = minetest.chatcommands
80                 _, _, arguments = string.match(param, "([^ ]+) ([^ ]+) (.+)")
81                 if not arguments then arguments = "" end
82                 if target and command then
83                         if cmddef[command] then
84                                 if minetest.get_player_by_name(target) then
85                                         if arguments == "" then argumentsdisp = arguments else argumentsdisp = " " .. arguments end
86                                         cmddef[command].func(target, arguments)
87                                 else
88                                         minetest.chat_send_player(name, minetest.colorize("#FF0000", "Invalid Player."))
89                                 end
90                         else
91                                 minetest.chat_send_player(name, minetest.colorize("#FF0000", "Nonexistant Command."))
92                         end
93                 else
94                         minetest.chat_send_player(name, minetest.colorize("#FF0000", "Invalid Usage."))
95                 end
96         end
97 })