mirror of
https://github.com/minetest-mods/skinsdb.git
synced 2024-12-23 16:00:18 +01:00
/skinsdb chat command implemented
This commit is contained in:
parent
c6ee5c2d5b
commit
97105d7f42
1
API.md
1
API.md
@ -5,6 +5,7 @@ Return the skin object assigned to the player. Returns defaout if nothins assign
|
||||
|
||||
## skins.assign_player_skin(player, skin)
|
||||
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)
|
||||
Update selected skin visuals on player
|
||||
|
16
api.lua
16
api.lua
@ -8,18 +8,25 @@ end
|
||||
function skins.assign_player_skin(player, skin)
|
||||
local skin_obj
|
||||
if type(skin) == "string" then
|
||||
skin_obj = skins.get(skin) or skins.get(skins.default)
|
||||
skin_obj = skins.get(skin)
|
||||
else
|
||||
skin_obj = skin
|
||||
end
|
||||
|
||||
if not skin_obj then
|
||||
return false
|
||||
end
|
||||
|
||||
if skin_obj:is_applicable_for_player(player:get_player_name()) then
|
||||
local skin_key = skin_obj:get_key()
|
||||
if skin_key == skins.default then
|
||||
skin_key = ""
|
||||
end
|
||||
player:set_attribute("skinsdb:skin_key", skin_key)
|
||||
else
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
-- update visuals
|
||||
@ -30,6 +37,9 @@ end
|
||||
|
||||
-- Assign and update
|
||||
function skins.set_player_skin(player, skin)
|
||||
skins.assign_player_skin(player, skin)
|
||||
skins.update_player_skin(player)
|
||||
local success = skins.assign_player_skin(player, skin)
|
||||
if success then
|
||||
skins.update_player_skin(player)
|
||||
end
|
||||
return success
|
||||
end
|
||||
|
65
chatcommands.lua
Normal file
65
chatcommands.lua
Normal 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,
|
||||
})
|
2
init.lua
2
init.lua
@ -12,7 +12,7 @@ skins.default = "character"
|
||||
dofile(skins.modpath.."/skin_meta_api.lua")
|
||||
dofile(skins.modpath.."/api.lua")
|
||||
dofile(skins.modpath.."/skinlist.lua")
|
||||
|
||||
dofile(skins.modpath.."/chatcommands.lua")
|
||||
-- Unified inventory page/integration
|
||||
if minetest.get_modpath("unified_inventory") then
|
||||
dofile(skins.modpath.."/unified_inventory_page.lua")
|
||||
|
Loading…
Reference in New Issue
Block a user