Miroir du dépôt skinsdb.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
3.1KB

  1. local S = minetest.get_translator("skinsdb")
  2. local function show_selection_formspec(player)
  3. local context = skins.get_formspec_context(player)
  4. local name = player:get_player_name()
  5. local skin = skins.get_player_skin(player)
  6. local formspec = "size[8,8]"..skins.get_skin_info_formspec(skin)
  7. formspec = formspec..skins.get_skin_selection_formspec(player, context, 3.5)
  8. minetest.show_formspec(name, 'skinsdb_show_ui', formspec)
  9. end
  10. minetest.register_chatcommand("skinsdb", {
  11. params = "[set] <skin key> | show [<skin key>] | list | list private | list public | [ui]",
  12. description = S("Show, list or set player's skin"),
  13. func = function(name, param)
  14. local player = minetest.get_player_by_name(name)
  15. if not player then
  16. return false, S("Player not found")
  17. end
  18. -- parse command line
  19. local command, parameter
  20. local words = param:split(" ")
  21. local word = words[1]
  22. if word == 'set' or word == 'list' or word == 'show' or word == 'ui' then
  23. command = word
  24. parameter = words[2]
  25. elseif skins.get(word) then
  26. command = 'set'
  27. parameter = word
  28. elseif not word then
  29. command = 'ui'
  30. else
  31. return false, S("unknown command").." "..word..", "..S("see /help skinsdb for supported parameters")
  32. end
  33. if command == "set" then
  34. local success = skins.set_player_skin(player, parameter)
  35. if success then
  36. return true, S("skin set to").." "..parameter
  37. else
  38. return false, S("invalid skin").." "..parameter
  39. end
  40. elseif command == "list" then
  41. local list
  42. if parameter == "private" then
  43. list = skins.get_skinlist_with_meta("playername", name)
  44. elseif parameter == "public" then
  45. list = skins.get_skinlist_for_player()
  46. elseif not parameter then
  47. list = skins.get_skinlist_for_player(name)
  48. else
  49. return false, S("unknown parameter"), parameter
  50. end
  51. local current_skin_key = skins.get_player_skin(player):get_key()
  52. for _, skin in ipairs(list) do
  53. local info = skin:get_key().." - "
  54. ..S("Name").."="..skin:get_meta_string("name").." "
  55. ..S("Author").."="..skin:get_meta_string("author").." "
  56. ..S("License").."="..skin:get_meta_string("license")
  57. if skin:get_key() == current_skin_key then
  58. info = minetest.colorize("#00FFFF", info)
  59. end
  60. minetest.chat_send_player(name, info)
  61. end
  62. elseif command == "show" then
  63. local skin
  64. if parameter then
  65. skin = skins.get(parameter)
  66. else
  67. skin = skins.get_player_skin(player)
  68. end
  69. if not skin then
  70. return false, S("invalid skin")
  71. end
  72. local formspec = "size[8,3]"..skins.get_skin_info_formspec(skin)
  73. minetest.show_formspec(name, 'skinsdb_show_skin', formspec)
  74. elseif command == "ui" then
  75. show_selection_formspec(player)
  76. end
  77. end,
  78. })
  79. minetest.register_on_player_receive_fields(function(player, formname, fields)
  80. if formname ~= "skinsdb_show_ui" then
  81. return
  82. end
  83. local context = skins.get_formspec_context(player)
  84. local action = skins.on_skin_selection_receive_fields(player, context, fields)
  85. if action == 'set' then
  86. minetest.close_formspec(player:get_player_name(), formname)
  87. elseif action == 'page' then
  88. show_selection_formspec(player)
  89. end
  90. end)