aboutsummaryrefslogtreecommitdiff
path: root/ch_core/localize_chatcommands.lua
blob: 1962deaedf3bc55b16240c33736e8b89110e8563 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
ch_core.open_submod("localize_chatcommands", {data = true, lib = true, privs = true})

local defs = {
	admin = {
		description = "Vypíše jméno postavy správce/kyně serveru.",
	},
	ban = {
		description = "Vyhostí hráče/ky na IP adrese daného klienta nebo zobrazí seznam vyhoštění.",
	},
	clearinv = {
		description = "Vyprázdní váš inventář, případně inventář jiné postavy.",
	},
	clearobjects = {
		description = "Smaže ze světa všechny objekty.",
	},
	clearpassword = {
		description = "Nastaví postavě prázdné heslo.",
	},
	days = {
		description = "Vypíše počet dní od založení světa.",
	},
	deleteblocks = {
		description = "Smaže z databáze mapové bloky v oblasti pos1 až pos2 (<pos1> a <pos2> musejí být v závorkách).",
	},
	help = {
		czech_command = "pomoc",
		description = "Vypíše nápovědu pro příkazy nebo seznam práv (-t: výstup do četu)",
	},
}

local function extract_fields(t, ...)
	local result = {}
	for _, k in ipairs({...}) do
		if t[k] ~= nil then
			result[k] = t[k]
		end
	end
	return result
end

local p_d_p = {"params", "description", "privs"}

for command, def in pairs(defs) do
	if minetest.registered_chatcommands[command] then
		local override = {}
		local valid = false
		for _, k in ipairs(p_d_p) do
			if def[k] ~= nil then
				override[k] = def[k]
				valid = true
			end
		end
		if def.func == nil and def.override_func ~= nil and minetest.registered_chatcommands[command].func ~= nil then
			override.func = def.func(minetest.registered_chatcommands[command].func)
			valid = true
		end

		if valid then
			minetest.override_chatcommand(command, override)
		end
		if def.czech_command then
			minetest.register_chatcommand(def.czech_command,
				extract_fields(minetest.registered_chatcommands[command], "params", "description", "privs", "func"))
		end
	else
		minetest.log("warning", "Chat command /"..command.." not exists to be localized!")
	end
end

if minetest.get_modpath("builtin_overrides") then
	builtin_overrides.login_to_viewname = ch_core.prihlasovaci_na_zobrazovaci
end

local def = {
	params = "[jméno postavy]",
	description = "Vypíše vaše práva nebo práva jiné postavy.",
	func = function(player_name, param)
		local privs_def = minetest.registered_chatcommands.privs
		return privs_def.func(player_name, ch_core.jmeno_na_prihlasovaci(param))
	end,
}

minetest.register_chatcommand("prava", def)
minetest.register_chatcommand("práva", def)

ch_core.close_submod("localize_chatcommands")