2017-06-15 14:16:11 +02:00
|
|
|
-- get current skin
|
2017-06-19 16:36:53 +02:00
|
|
|
function skins.get_player_skin(player)
|
|
|
|
local skin = player:get_attribute("skinsdb:skin_key")
|
2017-06-16 23:00:36 +02:00
|
|
|
return skins.get(skin) or skins.get(skins.default)
|
2014-03-17 06:26:58 +01:00
|
|
|
end
|
2014-07-23 13:46:42 +02:00
|
|
|
|
2017-06-19 16:36:53 +02:00
|
|
|
-- Assign skin to player
|
|
|
|
function skins.assign_player_skin(player, skin)
|
2017-06-16 23:00:36 +02:00
|
|
|
local skin_obj
|
|
|
|
if type(skin) == "string" then
|
2018-02-13 22:02:22 +01:00
|
|
|
skin_obj = skins.get(skin)
|
2017-06-16 23:00:36 +02:00
|
|
|
else
|
|
|
|
skin_obj = skin
|
|
|
|
end
|
|
|
|
|
2018-02-13 22:02:22 +01:00
|
|
|
if not skin_obj then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2018-01-07 14:50:22 +01:00
|
|
|
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)
|
2018-02-13 22:02:22 +01:00
|
|
|
else
|
|
|
|
return false
|
2014-07-23 13:46:42 +02:00
|
|
|
end
|
2018-02-13 22:02:22 +01:00
|
|
|
return true
|
2017-06-15 14:16:11 +02:00
|
|
|
end
|
2014-03-17 06:26:58 +01:00
|
|
|
|
2017-06-15 14:16:11 +02:00
|
|
|
-- update visuals
|
2017-06-19 16:36:53 +02:00
|
|
|
function skins.update_player_skin(player)
|
2017-06-15 14:16:11 +02:00
|
|
|
local skin = skins.get_player_skin(player)
|
2017-06-18 23:15:58 +02:00
|
|
|
skin:set_skin(player)
|
2014-03-17 06:26:58 +01:00
|
|
|
end
|
2017-06-19 16:36:53 +02:00
|
|
|
|
|
|
|
-- Assign and update
|
|
|
|
function skins.set_player_skin(player, skin)
|
2018-02-13 22:02:22 +01:00
|
|
|
local success = skins.assign_player_skin(player, skin)
|
|
|
|
if success then
|
|
|
|
skins.update_player_skin(player)
|
|
|
|
end
|
|
|
|
return success
|
2017-06-19 16:36:53 +02:00
|
|
|
end
|
2018-04-15 01:09:38 +02:00
|
|
|
|
|
|
|
-- Check Skin format (code stohlen from stu's multiskin)
|
|
|
|
function skins.get_skin_format(file)
|
|
|
|
file:seek("set", 1)
|
|
|
|
if file:read(3) == "PNG" then
|
|
|
|
file:seek("set", 16)
|
|
|
|
local ws = file:read(4)
|
|
|
|
local hs = file:read(4)
|
|
|
|
local w = ws:sub(3, 3):byte() * 256 + ws:sub(4, 4):byte()
|
|
|
|
local h = hs:sub(3, 3):byte() * 256 + hs:sub(4, 4):byte()
|
|
|
|
if w >= 64 then
|
|
|
|
if w == h then
|
|
|
|
return "1.8"
|
|
|
|
elseif w == h * 2 then
|
|
|
|
return "1.0"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|