/skinsdb chat command implemented

This commit is contained in:
Alexander Weber 2018-02-13 22:02:22 +01:00
parent c6ee5c2d5b
commit 97105d7f42
4 changed files with 80 additions and 4 deletions

1
API.md
View File

@ -5,6 +5,7 @@ Return the skin object assigned to the player. Returns defaout if nothins assign
## skins.assign_player_skin(player, skin) ## skins.assign_player_skin(player, skin)
Select the skin for the player. The "skin" parameter could be the skin key or the skin object Select the skin for the player. The "skin" parameter could be the skin key or the skin object
Returns false if skin is not valid or applicable to player
## skins.update_player_skin(player) ## skins.update_player_skin(player)
Update selected skin visuals on player Update selected skin visuals on player

16
api.lua
View File

@ -8,18 +8,25 @@ end
function skins.assign_player_skin(player, skin) function skins.assign_player_skin(player, skin)
local skin_obj local skin_obj
if type(skin) == "string" then if type(skin) == "string" then
skin_obj = skins.get(skin) or skins.get(skins.default) skin_obj = skins.get(skin)
else else
skin_obj = skin skin_obj = skin
end end
if not skin_obj then
return false
end
if skin_obj:is_applicable_for_player(player:get_player_name()) then if skin_obj:is_applicable_for_player(player:get_player_name()) then
local skin_key = skin_obj:get_key() local skin_key = skin_obj:get_key()
if skin_key == skins.default then if skin_key == skins.default then
skin_key = "" skin_key = ""
end end
player:set_attribute("skinsdb:skin_key", skin_key) player:set_attribute("skinsdb:skin_key", skin_key)
else
return false
end end
return true
end end
-- update visuals -- update visuals
@ -30,6 +37,9 @@ end
-- Assign and update -- Assign and update
function skins.set_player_skin(player, skin) function skins.set_player_skin(player, skin)
skins.assign_player_skin(player, skin) local success = skins.assign_player_skin(player, skin)
skins.update_player_skin(player) if success then
skins.update_player_skin(player)
end
return success
end end

65
chatcommands.lua Normal file
View File

@ -0,0 +1,65 @@
minetest.register_chatcommand("skinsdb", {
params = "[set] <skinname> | list | list private | list public",
description = "Set, show or list player's skin",
func = function(name, param)
local player = minetest.get_player_by_name(name)
if not player then
return false, "Player not found"
end
-- parse command line
local command, parameter
for word in param:gmatch("([^ ]+)") do
if not command then
-- first word
if word == 'set' or word == 'list' then
command = word
elseif skins.get(word) then
command = 'set'
parameter = word
break
else
return false, "unknown command "..word.." see /help skinsdb for supported parameters"
end
else
-- second word
parameter = word
break
end
end
if not command then
return false, "see /help skinsdb for supported parameters"
end
if command == "set" then
local success = skins.set_player_skin(player, parameter)
if success then
return true, "skin set to "..parameter
else
return false, "invalid skin "..parameter
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
return false, "unknown parameter", parameter
end
local current_skin_key = skins.get_player_skin(player):get_key()
for _, skin in ipairs(list) do
local info = skin:get_key()..": name="..skin:get_meta("name").." author="..skin:get_meta("author").." license="..skin:get_meta("license")
if skin:get_key() == current_skin_key then
info = minetest.colorize("#00FFFF", info)
end
minetest.chat_send_player(name, info)
end
end
end,
})

View File

@ -12,7 +12,7 @@ skins.default = "character"
dofile(skins.modpath.."/skin_meta_api.lua") dofile(skins.modpath.."/skin_meta_api.lua")
dofile(skins.modpath.."/api.lua") dofile(skins.modpath.."/api.lua")
dofile(skins.modpath.."/skinlist.lua") dofile(skins.modpath.."/skinlist.lua")
dofile(skins.modpath.."/chatcommands.lua")
-- Unified inventory page/integration -- Unified inventory page/integration
if minetest.get_modpath("unified_inventory") then if minetest.get_modpath("unified_inventory") then
dofile(skins.modpath.."/unified_inventory_page.lua") dofile(skins.modpath.."/unified_inventory_page.lua")