From fb0f9660338c89506ae6c7f772b816bd9f799da8 Mon Sep 17 00:00:00 2001 From: mathiascode Date: Mon, 16 Mar 2020 07:37:06 +0200 Subject: [PATCH 1/2] Clean up MOTD code --- functions.lua | 56 -------------------------------------------------- main.lua | 3 +-- motd.lua | 41 ++++++++++++------------------------ onjoin.lua | 13 ------------ playerjoin.lua | 7 +++++++ 5 files changed, 21 insertions(+), 99 deletions(-) delete mode 100644 onjoin.lua create mode 100644 playerjoin.lua diff --git a/functions.lua b/functions.lua index c51ded1..8a050c1 100644 --- a/functions.lua +++ b/functions.lua @@ -32,62 +32,6 @@ function KickPlayer( PlayerName, Reason ) end - -function ReturnColorFromChar(char) - - -- Check if the char represents a color. Else return nil. - if char == "0" then - return cChatColor.Black - elseif char == "1" then - return cChatColor.Navy - elseif char == "2" then - return cChatColor.Green - elseif char == "3" then - return cChatColor.Blue - elseif char == "4" then - return cChatColor.Red - elseif char == "5" then - return cChatColor.Purple - elseif char == "6" then - return cChatColor.Gold - elseif char == "7" then - return cChatColor.LightGray - elseif char == "8" then - return cChatColor.Gray - elseif char == "9" then - return cChatColor.DarkPurple - elseif char == "a" then - return cChatColor.LightGreen - elseif char == "b" then - return cChatColor.LightBlue - elseif char == "c" then - return cChatColor.Rose - elseif char == "d" then - return cChatColor.LightPurple - elseif char == "e" then - return cChatColor.Yellow - elseif char == "f" then - return cChatColor.White - elseif char == "k" then - return cChatColor.Random - elseif char == "l" then - return cChatColor.Bold - elseif char == "m" then - return cChatColor.Strikethrough - elseif char == "n" then - return cChatColor.Underlined - elseif char == "o" then - return cChatColor.Italic - elseif char == "r" then - return cChatColor.Plain - end - -end - - - - - -- Teleports a_SrcPlayer to a player named a_DstPlayerName; if a_TellDst is true, will send a notice to the destination player function TeleportToPlayer( a_SrcPlayer, a_DstPlayerName, a_TellDst ) diff --git a/main.lua b/main.lua index ddadd0b..3d87612 100644 --- a/main.lua +++ b/main.lua @@ -16,7 +16,6 @@ g_UsePrefixes = true -- Global variables -Messages = {} WorldsSpawnProtect = {} WorldsWorldLimit = {} WorldsWorldDifficulty = {} @@ -83,7 +82,7 @@ function Initialize(Plugin) Plugin:AddWebTab("Ranks", HandleRequest_Ranks) Plugin:AddWebTab("Player Ranks", HandleRequest_PlayerRanks) - LoadMotd() + LoadMOTD() WEBLOGINFO("Core is initialized") LOG("Initialised " .. Plugin:GetName() .. " v." .. Plugin:GetVersion()) diff --git a/motd.lua b/motd.lua index e431a06..ade366a 100644 --- a/motd.lua +++ b/motd.lua @@ -1,40 +1,25 @@ -function HandleMOTDCommand( Split, Player ) - ShowMOTDTo( Player ) - return true -end - -function LoadMotd() +local MOTD = {} +function LoadMOTD() -- Check if the file 'motd.txt' exists, if not, create it with default content: - if (not cFile:IsFile("motd.txt")) then - CreateFile = io.open( "motd.txt", "w" ) + if not cFile:IsFile("motd.txt") then + CreateFile = io.open("motd.txt", "w") CreateFile:write("@6Welcome to the Cuberite test server!\n@6http://www.cuberite.org/\n@6Type /help for all commands") CreateFile:close() end - for line in io.lines( "motd.txt" ) do - line = line:gsub("(@.)", - function(a_Str) - local Char = a_Str:sub(2, 2) - if (Char == "@") then - -- If the input was "@@" then simply replace it with a single "@" - return "@" - end - - local Color = ReturnColorFromChar(Char) - if (Color) then - return Color - end - end - ) - - table.insert(Messages, line) + for Line in io.lines("motd.txt") do + table.insert(MOTD, Line) end end -function ShowMOTDTo( Player ) - for I=1, #Messages do - Player:SendMessage(Messages[I]) +function ShowMOTD(Player) + for i = 1, #MOTD do + Player:SendMessage(MOTD[i]) end end +function HandleMOTDCommand(Split, Player) + ShowMOTD(Player) + return true +end diff --git a/onjoin.lua b/onjoin.lua deleted file mode 100644 index 76803c4..0000000 --- a/onjoin.lua +++ /dev/null @@ -1,13 +0,0 @@ -function OnPlayerJoined(a_Player) - -- Send the MOTD to the player: - ShowMOTDTo(a_Player) - - -- Add a message to the webadmin chat: - WEBLOGINFO(a_Player:GetName() .. " has joined the game") - - return false -end - - - - diff --git a/playerjoin.lua b/playerjoin.lua new file mode 100644 index 0000000..a0d3d7a --- /dev/null +++ b/playerjoin.lua @@ -0,0 +1,7 @@ +function OnPlayerJoined(Player) + -- Send the MOTD to the player: + ShowMOTD(Player) + + -- Add a message to the webadmin chat: + WEBLOGINFO(Player:GetName() .. " has joined the game") +end From dc86e7d6bc60b458104d6641732379bd994d1d20 Mon Sep 17 00:00:00 2001 From: mathiascode Date: Mon, 16 Mar 2020 07:45:14 +0200 Subject: [PATCH 2/2] Use https --- motd.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/motd.lua b/motd.lua index ade366a..d30799f 100644 --- a/motd.lua +++ b/motd.lua @@ -4,7 +4,7 @@ function LoadMOTD() -- Check if the file 'motd.txt' exists, if not, create it with default content: if not cFile:IsFile("motd.txt") then CreateFile = io.open("motd.txt", "w") - CreateFile:write("@6Welcome to the Cuberite test server!\n@6http://www.cuberite.org/\n@6Type /help for all commands") + CreateFile:write("@6Welcome to the Cuberite test server!\n@6https://cuberite.org/\n@6Type /help for all commands") CreateFile:close() end