2020-01-08 08:00:44 +01:00
|
|
|
local S = minetest.get_translator("skinsdb")
|
2018-02-15 08:17:54 +01:00
|
|
|
|
2018-02-14 02:19:15 +01:00
|
|
|
local function show_selection_formspec(player)
|
2018-03-01 21:15:04 +01:00
|
|
|
local context = skins.get_formspec_context(player)
|
2018-02-14 01:39:05 +01:00
|
|
|
local name = player:get_player_name()
|
|
|
|
local skin = skins.get_player_skin(player)
|
|
|
|
local formspec = "size[8,8]"..skins.get_skin_info_formspec(skin)
|
2018-02-14 02:19:15 +01:00
|
|
|
formspec = formspec..skins.get_skin_selection_formspec(player, context, 3.5)
|
2018-02-14 01:39:05 +01:00
|
|
|
minetest.show_formspec(name, 'skinsdb_show_ui', formspec)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2018-02-13 22:02:22 +01:00
|
|
|
minetest.register_chatcommand("skinsdb", {
|
2024-01-03 04:29:18 +01:00
|
|
|
params = S("[set] <skin key> | show [<skin key>] | list | list private | list public | [ui]"),
|
2018-02-15 08:17:54 +01:00
|
|
|
description = S("Show, list or set player's skin"),
|
2018-02-13 22:02:22 +01:00
|
|
|
func = function(name, param)
|
|
|
|
local player = minetest.get_player_by_name(name)
|
|
|
|
if not player then
|
2018-02-15 08:17:54 +01:00
|
|
|
return false, S("Player not found")
|
2018-02-13 22:02:22 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- parse command line
|
|
|
|
local command, parameter
|
2018-02-15 06:54:12 +01:00
|
|
|
local words = param:split(" ")
|
|
|
|
local word = words[1]
|
|
|
|
if word == 'set' or word == 'list' or word == 'show' or word == 'ui' then
|
|
|
|
command = word
|
|
|
|
parameter = words[2]
|
|
|
|
elseif skins.get(word) then
|
|
|
|
command = 'set'
|
|
|
|
parameter = word
|
|
|
|
elseif not word then
|
|
|
|
command = 'ui'
|
|
|
|
else
|
2018-02-15 08:17:54 +01:00
|
|
|
return false, S("unknown command").." "..word..", "..S("see /help skinsdb for supported parameters")
|
2018-02-13 22:02:22 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
if command == "set" then
|
2020-05-25 11:34:52 +02:00
|
|
|
if parameter then
|
|
|
|
local success = skins.set_player_skin(player, parameter)
|
|
|
|
if success then
|
|
|
|
return true, S("skin set to").." "..parameter
|
|
|
|
else
|
|
|
|
return false, S("invalid skin").." "..parameter
|
|
|
|
end
|
|
|
|
else return false, S("Requires skin key")
|
2018-02-13 22:02:22 +01:00
|
|
|
end
|
|
|
|
elseif command == "list" then
|
|
|
|
local list
|
|
|
|
if parameter == "private" then
|
|
|
|
list = skins.get_skinlist_with_meta("playername", name)
|
|
|
|
elseif parameter == "public" then
|
|
|
|
list = skins.get_skinlist_for_player()
|
|
|
|
elseif not parameter then
|
|
|
|
list = skins.get_skinlist_for_player(name)
|
|
|
|
else
|
2018-02-15 08:17:54 +01:00
|
|
|
return false, S("unknown parameter"), parameter
|
2018-02-13 22:02:22 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
local current_skin_key = skins.get_player_skin(player):get_key()
|
|
|
|
for _, skin in ipairs(list) do
|
2018-02-15 08:17:54 +01:00
|
|
|
local info = skin:get_key().." - "
|
|
|
|
..S("Name").."="..skin:get_meta_string("name").." "
|
|
|
|
..S("Author").."="..skin:get_meta_string("author").." "
|
|
|
|
..S("License").."="..skin:get_meta_string("license")
|
2018-02-13 22:02:22 +01:00
|
|
|
if skin:get_key() == current_skin_key then
|
|
|
|
info = minetest.colorize("#00FFFF", info)
|
|
|
|
end
|
|
|
|
minetest.chat_send_player(name, info)
|
|
|
|
end
|
2018-02-13 22:40:07 +01:00
|
|
|
elseif command == "show" then
|
2018-02-14 01:39:05 +01:00
|
|
|
local skin
|
2018-02-13 22:40:07 +01:00
|
|
|
if parameter then
|
|
|
|
skin = skins.get(parameter)
|
|
|
|
else
|
|
|
|
skin = skins.get_player_skin(player)
|
|
|
|
end
|
|
|
|
if not skin then
|
2018-02-15 08:17:54 +01:00
|
|
|
return false, S("invalid skin")
|
2018-02-13 22:40:07 +01:00
|
|
|
end
|
|
|
|
local formspec = "size[8,3]"..skins.get_skin_info_formspec(skin)
|
|
|
|
minetest.show_formspec(name, 'skinsdb_show_skin', formspec)
|
2018-02-14 01:39:05 +01:00
|
|
|
elseif command == "ui" then
|
2018-02-14 02:19:15 +01:00
|
|
|
show_selection_formspec(player)
|
2018-02-13 22:02:22 +01:00
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|
2018-02-14 01:39:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|
|
|
if formname ~= "skinsdb_show_ui" then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2018-03-01 21:15:04 +01:00
|
|
|
local context = skins.get_formspec_context(player)
|
2018-02-14 01:39:05 +01:00
|
|
|
|
|
|
|
local action = skins.on_skin_selection_receive_fields(player, context, fields)
|
|
|
|
if action == 'set' then
|
|
|
|
minetest.close_formspec(player:get_player_name(), formname)
|
|
|
|
elseif action == 'page' then
|
2018-02-14 02:19:15 +01:00
|
|
|
show_selection_formspec(player)
|
2018-02-14 01:39:05 +01:00
|
|
|
end
|
|
|
|
end)
|