From b18c42625ff02568e8a20fe4c764e96aed39ccfe Mon Sep 17 00:00:00 2001 From: cheapie Date: Tue, 31 May 2016 19:21:12 -0500 Subject: Fall back to non-colored text if an old server version is in use --- init.lua | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/init.lua b/init.lua index 68a6a77..341cdac 100644 --- a/init.lua +++ b/init.lua @@ -1,5 +1,13 @@ newplayer = {} +if type(minetest.colorize) == "function" then + newplayer.colorize = minetest.colorize +else + newplayer.colorize = function(color,text) + return text + end +end + local f = io.open(minetest.get_worldpath()..DIR_DELIM.."newplayer-keywords.txt","r") if f then local d = f:read("*all") @@ -105,7 +113,7 @@ minetest.register_on_player_receive_fields(function(player,formname,fields) minetest.chat_send_player(name,"Teleporting to spawn...") player:setpos(spawn) else - minetest.chat_send_player(name,minetest.colorize("#FF0000","ERROR: ").."The spawn point is not set!") + minetest.chat_send_player(name,newplayer.colorize("#FF0000","ERROR: ").."The spawn point is not set!") end local form = "size[5,3]".. "label[1,0;Thank you for agreeing]".. @@ -139,7 +147,7 @@ minetest.register_on_player_receive_fields(function(player,formname,fields) f:write(fields.rules) f:close() newplayer.rules = fields.rules - minetest.chat_send_player(name,minetest.colorize("#55FF55","Success: ").."Rules/keyword updated.") + minetest.chat_send_player(name,newplayer.colorize("#55FF55","Success: ").."Rules/keyword updated.") end else minetest.chat_send_player(name,"You hacker you... nice try!") @@ -190,7 +198,7 @@ minetest.register_chatcommand("set_no_interact_spawn",{ local pos = minetest.get_player_by_name(name):getpos() minetest.setting_set("spawnpoint_no_interact",string.format("%s,%s,%s",pos.x,pos.y,pos.z)) minetest.setting_save() - return true, minetest.colorize("#55FF55","Success: ").."Spawn point for players without interact set to: "..minetest.colorize("#00FFFF",minetest.pos_to_string(pos)) + return true, newplayer.colorize("#55FF55","Success: ").."Spawn point for players without interact set to: "..newplayer.colorize("#00FFFF",minetest.pos_to_string(pos)) end} ) @@ -202,7 +210,7 @@ minetest.register_chatcommand("set_interact_spawn",{ local pos = minetest.get_player_by_name(name):getpos() minetest.setting_set("spawnpoint_interact",string.format("%s,%s,%s",pos.x,pos.y,pos.z)) minetest.setting_save() - return true, minetest.colorize("#55FF55","Success: ").."Spawn point for players with interact set to: "..minetest.colorize("#00FFFF",minetest.pos_to_string(pos)) + return true, newplayer.colorize("#55FF55","Success: ").."Spawn point for players with interact set to: "..newplayer.colorize("#00FFFF",minetest.pos_to_string(pos)) end} ) @@ -215,7 +223,7 @@ minetest.register_chatcommand("getkeywords",{ if #newplayer.keywords > 0 then out = "Currently configured keywords:" for _,kw in pairs(newplayer.keywords) do - out = out.."\n"..minetest.colorize("#00FFFF",kw) + out = out.."\n"..newplayer.colorize("#00FFFF",kw) end else out = "No keywords are currently set." @@ -230,7 +238,7 @@ minetest.register_chatcommand("addkeyword",{ privs = {server=true}, func = function(name,param) if (not param) or param == "" then - return true, minetest.colorize("#FF0000","ERROR: ").."No keyword supplied" + return true, newplayer.colorize("#FF0000","ERROR: ").."No keyword supplied" end table.insert(newplayer.keywords,param) newplayer.savekeywords() @@ -244,16 +252,16 @@ minetest.register_chatcommand("delkeyword",{ privs = {server=true}, func = function(name,param) if (not param) or param == "" then - return true, minetest.colorize("#FF0000","ERROR: ").."No keyword supplied" + return true, newplayer.colorize("#FF0000","ERROR: ").."No keyword supplied" end for k,v in pairs(newplayer.keywords) do if v == param then newplayer.keywords[k] = nil newplayer.savekeywords() - return true, "Keyword "..minetest.colorize("#00FFFF",param).." removed" + return true, "Keyword "..newplayer.colorize("#00FFFF",param).." removed" end end - return true, minetest.colorize("#FF0000","ERROR: ").."Keyword "..minetest.colorize("#00FFFF",param).." not found" + return true, newplayer.colorize("#FF0000","ERROR: ").."Keyword "..newplayer.colorize("#00FFFF",param).." not found" end} ) @@ -269,7 +277,7 @@ minetest.register_chatcommand("spawn",{ player:setpos(pos) return true, "Teleporting to spawn..." else - return true, minetest.colorize("#FF0000","ERROR: ").."The spawn point is not set!" + return true, newplayer.colorize("#FF0000","ERROR: ").."The spawn point is not set!" end else local pos = minetest.setting_get_pos("spawnpoint_no_interact") @@ -277,7 +285,7 @@ minetest.register_chatcommand("spawn",{ player:setpos(pos) return true, "Teleporting to spawn..." else - return true, minetest.colorize("#FF0000","ERROR: ").."The spawn point is not set!" + return true, newplayer.colorize("#FF0000","ERROR: ").."The spawn point is not set!" end end end} -- cgit v1.2.3