Skip to content

Commit

Permalink
Merge pull request #216 from cuberite/motdcleanup
Browse files Browse the repository at this point in the history
Clean up MOTD code
  • Loading branch information
bearbin authored Mar 21, 2020
2 parents 70c4de6 + dc86e7d commit 3f2bba9
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 100 deletions.
56 changes: 0 additions & 56 deletions functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 )

Expand Down
3 changes: 1 addition & 2 deletions main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ g_UsePrefixes = true


-- Global variables
Messages = {}
WorldsSpawnProtect = {}
WorldsWorldLimit = {}
WorldsWorldDifficulty = {}
Expand Down Expand Up @@ -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())
Expand Down
43 changes: 14 additions & 29 deletions motd.lua
Original file line number Diff line number Diff line change
@@ -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" )
CreateFile:write("@6Welcome to the Cuberite test server!\n@6http://www.cuberite.org/\n@6Type /help for all commands")
if not cFile:IsFile("motd.txt") then
CreateFile = io.open("motd.txt", "w")
CreateFile:write("@6Welcome to the Cuberite test server!\n@6https://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
13 changes: 0 additions & 13 deletions onjoin.lua

This file was deleted.

7 changes: 7 additions & 0 deletions playerjoin.lua
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3f2bba9

Please sign in to comment.