Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up MOTD code #216

Merged
merged 2 commits into from
Mar 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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