summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--API.md1
-rw-r--r--api.lua16
-rw-r--r--chatcommands.lua65
-rw-r--r--init.lua2
4 files changed, 80 insertions, 4 deletions
diff --git a/API.md b/API.md
index 193f824..5d23186 100644
--- a/API.md
+++ b/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
diff --git a/api.lua b/api.lua
index d822005..a0259cd 100644
--- a/api.lua
+++ b/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
diff --git a/chatcommands.lua b/chatcommands.lua
new file mode 100644
index 0000000..f8df4ff
--- /dev/null
+++ b/chatcommands.lua
@@ -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,
+})
diff --git a/init.lua b/init.lua
index 325aa94..37331e0 100644
--- a/init.lua
+++ b/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")