1
0
Fork 0

More new plugin awesomeness

git-svn-id: http://mc-server.googlecode.com/svn/trunk@174 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
faketruth 2012-01-26 22:44:37 +00:00
parent 507d9d57a9
commit 45e286fdcd
17 changed files with 359 additions and 6 deletions

30
Plugins/NewTest/ban.lua Normal file
View File

@ -0,0 +1,30 @@
function HandleBanCommand( Split, Player )
if( #Split < 2 ) then
Player:SendMessage( cChatColor.Green .. "Usage: /ban [Player] <Reason>" )
return true
end
local World = Player:GetWorld()
local OtherPlayer = World:GetPlayer( Split[2] )
if( OtherPlayer == nil ) then
Player:SendMessage( cChatColor.Green .. "Could not find player " .. Split[2] )
return true
end
local Reason = "You have been banned"
if( #Split > 2 ) then
Reason = table.concat(Split, " ", 3)
end
local Server = cRoot:Get():GetServer()
LOGINFO( Player:GetName() .. " is banning " .. OtherPlayer:GetName() .. " ( "..Reason..") " )
Server:SendMessage( "Banning " .. OtherPlayer:GetName() )
local ClientHandle = OtherPlayer:GetClientHandle()
ClientHandle:Kick( Reason )
BannedPlayersIni:SetValueB("Banned", OtherPlayer:GetName(), true)
BannedPlayersIni:WriteFile()
return true
end

View File

@ -0,0 +1,10 @@
function HandleChangeGMCommand( Split, Player )
if( #Split ~= 2 ) then
Player:SendMessage( cChatColor.Green .. "Usage: /gm [GameMode (0|1)]" )
return true
end
Player:SetGameMode(Split[2])
return true
end

View File

@ -0,0 +1,15 @@
function HandleGotoWorldCommand( Split, Player )
if( #Split ~= 2 ) then
Player:SendMessage( cChatColor.Green .. "Usage: /gotoworld [WorldName]" )
return true
end
if( Player:MoveToWorld(Split[2]) == false ) then
Player:SendMessage( cChatColor.Green .. "Could not move to world '" .. Split[2] .. "'!" )
return true
end
Player:SendMessage( cChatColor.Green .. "Moved successfully to '" .. Split[2] .. "'! :D" )
return true
end

54
Plugins/NewTest/help.lua Normal file
View File

@ -0,0 +1,54 @@
function HandleHelpCommand( Split, Player )
local PluginManager = cRoot:Get():GetPluginManager()
local LinesPerPage = 9
local CurrentPage = 1
local CurrentLine = 0
if( #Split == 2 ) then
CurrentPage = tonumber(Split[2])
end
local Pages = {}
local PluginList = PluginManager:GetAllPlugins()
for i, Plugin in ipairs( PluginList ) do
local Commands = Plugin:GetCommands()
for i, v in ipairs( Commands ) do
if( Player:HasPermission( v.Permission ) ) then
local PageNum = math.floor( CurrentLine/LinesPerPage )+1
if( Pages[ PageNum ] == nil ) then Pages[ PageNum ] = {} end -- Create page
if( Pages[ PageNum ].ShownName ~= Plugin:GetName() and SHOW_PLUGIN_NAMES == true ) then
if( CurrentLine == LinesPerPage * PageNum -1 ) then -- Don't add if it's the last line of the page, it looks silly
-- Add it to the next page instead
CurrentLine = CurrentLine+1
PageNum = math.floor( CurrentLine/LinesPerPage )+1
if( Pages[ PageNum ] == nil ) then Pages[ PageNum ] = {} end -- Create page
table.insert( Pages[ PageNum ], cChatColor.Gold .. Plugin:GetName() )
else
Pages[ PageNum ].ShownName = Plugin:GetName()
table.insert( Pages[ PageNum ], cChatColor.Gold .. Plugin:GetName() )
end
CurrentLine = CurrentLine+1
PageNum = math.floor( CurrentLine/LinesPerPage )+1
if( Pages[ PageNum ] == nil ) then Pages[ PageNum ] = {} end -- Create page
end
local Message = cChatColor.Blue .. v.Command .. v.Description;
table.insert( Pages[ PageNum ], Message )
CurrentLine = CurrentLine+1
end
end
end
Player:SendMessage( cChatColor.Purple .. "- All commands - " .. cChatColor.Gold .. "[Page " .. (CurrentPage) .."/"..#Pages.."]" )
if( Pages[CurrentPage] ~= nil ) then
for i, v in ipairs(Pages[CurrentPage]) do
Player:SendMessage( v )
end
end
return true
end

65
Plugins/NewTest/item.lua Normal file
View File

@ -0,0 +1,65 @@
function HandleItemCommand( Split, Player )
if( #Split ~= 2 and #Split ~=3 ) then
Player:SendMessage( cChatColor.Green .. "Usage: /item [ItemID/Name:Dmg] <Amount>" )
return true
end
local FoundItem = false
local ItemSyntax = Split[2] -- Contains item string with optional metadata
local ItemData = StringSplit( Split[2], ":" )
-- Default item values
local ItemID = 0
local ItemMeta = 0
local ItemAmount = 1
if( #ItemData > 0 ) then
ItemID = ItemData[1]
end
if( tonumber(ItemID) ~= nil ) then -- Definitely a number
ItemID = tonumber(ItemID)
if( IsValidItem( ItemID ) ) then
FoundItem = true
end
end
if( FoundItem == false ) then
if ( HAVE_ITEM_NAMES == true ) then
local Item = ItemsTable[ ItemID ]
if( Item ~= nil ) then
ItemID = Item.m_ItemID
ItemMeta = Item.m_ItemHealth
FoundItem = true
end
end
end
-- Override metadata from item in list, if metadata was given
if( #ItemData > 1 and tonumber( ItemData[2] ) ~= nil ) then -- Metadata is given, and is a number
ItemMeta = tonumber( ItemData[2] )
end
if( FoundItem == false ) then
Player:SendMessage( cChatColor.Green .. "Invalid Item ID / Name !" )
return true
end
if( #Split == 3 ) then
ItemAmount = tonumber( Split[3] )
if( ItemAmount == nil or ItemAmount < 1 or ItemAmount > 512 ) then
Player:SendMessage( cChatColor.Green .. "Invalid Amount !" )
return true
end
end
local NewItem = cItem( ItemID, ItemAmount, ItemMeta )
if( Player:GetInventory():AddItem( NewItem ) == true ) then
Player:SendMessage( cChatColor.Green .. "There you go !" )
LOG("Gave " .. Player:GetName() .. " " .. ItemAmount .. " times " .. ItemID .. ":" .. ItemMeta)
else
Player:SendMessage( cChatColor.Green .. "Not enough space in inventory !" )
end
return true
end

27
Plugins/NewTest/kick.lua Normal file
View File

@ -0,0 +1,27 @@
function HandleKickCommand( Split, Player )
if( #Split < 2 ) then
Player:SendMessage( cChatColor.Green .. "Usage: /kick [Player] <Reason>" )
return true
end
local World = Player:GetWorld()
local OtherPlayer = World:GetPlayer( Split[2] )
if( OtherPlayer == nil ) then
Player:SendMessage( cChatColor.Green .. "Could not find player " .. Split[2] )
return true
end
local Reason = "You have been kicked"
if( #Split > 2 ) then
Reason = table.concat(Split, " ", 3)
end
local Server = cRoot:Get():GetServer()
LOGINFO( Player:GetName() .. " is kicking " .. OtherPlayer:GetName() .. " ( "..Reason..") " )
Server:SendMessage( "Kicking " .. OtherPlayer:GetName() )
local ClientHandle = OtherPlayer:GetClientHandle()
ClientHandle:Kick( Reason )
return true
end

View File

@ -9,7 +9,46 @@ function Initialize( Plugin )
Plugin:SetName("LOLOL new plugin!")
PluginManager = cRoot:Get():GetPluginManager()
PluginManager:AddHook( Plugin, cPluginManager.E_PLUGIN_TICK )
PluginManager:AddHook( Plugin, cPluginManager.E_PLUGIN_PLAYER_JOIN )
PluginManager:AddHook( Plugin, cPluginManager.E_PLUGIN_LOGIN )
PluginManager:AddHook( Plugin, cPluginManager.E_PLUGIN_BLOCK_PLACE )
PluginManager:AddHook( Plugin, cPluginManager.E_PLUGIN_KILLED )
Plugin:AddCommand("/help", " - [Page] Show this message", "core.help")
Plugin:AddCommand("/pluginlist", " - Show list of plugins", "core.pluginlist")
Plugin:AddCommand("/tp", " - [Player] - Teleport yourself to a player", "core.teleport")
Plugin:AddCommand("/item", " - [ItemID/Name] <Amount> - Spawn an item for yourself", "core.item")
Plugin:AddCommand("/list", " - Shows list of connected players", "core.playerlist")
Plugin:AddCommand("/motd", " - Show message of the day", "core.motd")
Plugin:AddCommand("/reload", " - Reload all plugins", "core.reload")
Plugin:AddCommand("/time", " - [Day/Night] - Sets the time of day", "core.time")
Plugin:AddCommand("/spawn", " - Return to the spawn", "core.spawn")
Plugin:AddCommand("/kick", " - [Player] - Kick a player", "core.kick")
Plugin:AddCommand("/ban", " - [Player] - Ban a player", "core.ban")
Plugin:AddCommand("/unban", " - [Player] - Unban a player", "core.unban")
Plugin:AddCommand("/top", " - Teleport yourself to the top most block", "core.top")
Plugin:AddCommand("/gm", " - [Gamemode (0|1)] - Change your gamemode", "core.changegm")
Plugin:AddCommand("/gotoworld", " - Move to a different world!", "core.gotoworld")
Plugin:BindCommand( "/help", "core.help", HandleHelpCommand )
Plugin:BindCommand( "/pluginlist","core.pluginlist", HandlePluginListCommand )
Plugin:BindCommand( "/tp", "core.teleport", HandleTPCommand )
Plugin:BindCommand( "/item", "core.item", HandleItemCommand )
Plugin:BindCommand( "/i", "core.item", HandleItemCommand )
Plugin:BindCommand( "/list", "core.playerlist", HandlePlayerListCommand )
Plugin:BindCommand( "/who", "core.playerlist", HandlePlayerListCommand )
Plugin:BindCommand( "/playerlist","core.playerlist", HandlePlayerListCommand )
Plugin:BindCommand( "/motd", "core.motd", HandleMOTDCommand )
Plugin:BindCommand( "/reload", "core.reload", HandleReloadCommand )
Plugin:BindCommand( "/time", "core.time", HandleTimeCommand )
Plugin:BindCommand( "/spawn", "core.spawn", HandleSpawnCommand )
Plugin:BindCommand( "/home", "core.spawn", HandleSpawnCommand )
Plugin:BindCommand( "/kick", "core.kick", HandleKickCommand )
Plugin:BindCommand( "/ban", "core.ban", HandleBanCommand )
Plugin:BindCommand( "/unban", "core.unban", HandleUnbanCommand )
Plugin:BindCommand( "/top", "core.top", HandleTopCommand )
Plugin:BindCommand( "/gm", "core.changegm", HandleChangeGMCommand )
Plugin:BindCommand( "/gotoworld", "core.gotoworld", HandleGotoWorldCommand )
LOGINFO("Plugin name is: " .. Plugin:GetName() )

10
Plugins/NewTest/motd.lua Normal file
View File

@ -0,0 +1,10 @@
function HandleMOTDCommand( Split, Player )
ShowMOTDTo( Player )
return true
end
function ShowMOTDTo( Player )
Player:SendMessage( cChatColor.Gold .. "Welcome to the MCServer test server!" );
Player:SendMessage( cChatColor.Gold .. "http://mcserver.ae-c.net/" );
Player:SendMessage( cChatColor.Gold .. "Type /help for all commands" );
end

View File

@ -0,0 +1,16 @@
function HandlePlayerListCommand( Split, Player )
local World = Player:GetWorld()
local PlayerList = World:GetAllPlayers()
local Message = cChatColor.Green .. "Connected players: (".. cChatColor.White.. #PlayerList .. cChatColor.Green .. ")"
Player:SendMessage( Message )
local PlayerTable = {}
for i, TempPlayer in ipairs( PlayerList ) do
local PlayerName = TempPlayer:GetName()
table.insert(PlayerTable, PlayerName )
end
Player:SendMessage( table.concat(PlayerTable, " ") )
return true
end

View File

@ -0,0 +1,13 @@
function HandlePluginListCommand( Split, Player )
local PluginManager = cRoot:Get():GetPluginManager()
local PluginList = PluginManager:GetAllPlugins()
local PluginTable = {}
for i, Plugin in ipairs( PluginList ) do
table.insert(PluginTable, Plugin:GetName() )
end
Player:SendMessage( cChatColor.Green .. "Loaded plugins:" )
Player:SendMessage( cChatColor.Gold .. table.concat(PluginTable, cChatColor.Gold.." ") )
return true
end

View File

@ -0,0 +1,6 @@
function HandleReloadCommand( Split, Player )
Server = cRoot:Get():GetServer()
Server:SendMessage( cChatColor.Green .. "Reloading all plugins." )
cRoot:Get():GetPluginManager():ReloadPlugins()
return true
end

View File

@ -0,0 +1,6 @@
function HandleSpawnCommand( Split, Player )
World = Player:GetWorld()
Player:TeleportTo( World:GetSpawnX(), World:GetSpawnY(), World:GetSpawnZ() )
LOGINFO( Player:GetName() .. " returned to spawn." )
return true
end

View File

@ -0,0 +1,18 @@
function HandleTPCommand( Split, Player )
if( #Split ~= 2 ) then
Player:SendMessage( cChatColor.Green .. "Usage: /tp [PlayerName]" )
return true
end
local World = Player:GetWorld()
local OtherPlayer = World:GetPlayer( Split[2] )
if( OtherPlayer == nil ) then
Player:SendMessage( cChatColor.Green .. "Can't find player " .. Split[2] )
elseif( OtherPlayer == Player ) then
Player:SendMessage( cChatColor.Green .. "Already there :)" )
else
Player:TeleportTo( OtherPlayer )
Player:SendMessage( cChatColor.Green .. "You teleported to "..OtherPlayer:GetName().."!" )
OtherPlayer:SendMessage( cChatColor.Green .. Player:GetName().." teleported to you!" )
end
return true
end

View File

@ -1,5 +0,0 @@
LOGINFO("tick.lua!! ")
function Tick( DeltaTime )
LOGINFO("Tick in tick.lua; LOOLOL = " .. LOOLOL .. " Plugin name = " .. PLUGIN:GetName() )
end

18
Plugins/NewTest/time.lua Normal file
View File

@ -0,0 +1,18 @@
function HandleTimeCommand( Split, Player )
if( #Split ~= 2 ) then
Player:SendMessage( cChatColor.Green .. "Usage: /time [Day/Night]" )
return true;
end
local Server = cRoot:Get():GetServer()
if( string.upper( Split[2] ) == "DAY") then
Player:GetWorld():SetWorldTime( 0 )
Server:SendMessage( cChatColor.Green .. Player:GetName() .. " set the time to Day.")
elseif( string.upper( Split[2] ) == "NIGHT") then
Player:GetWorld():SetWorldTime( 12000 + 1000 )
Server:SendMessage( cChatColor.Green .. Player:GetName() .. " set the time to Night.")
else
Player:SendMessage( cChatColor.Green .. "Usage: /time [Day/Night]" )
end
return true
end

11
Plugins/NewTest/top.lua Normal file
View File

@ -0,0 +1,11 @@
function HandleTopCommand( Split, Player )
local World = Player:GetWorld()
local PlayerPos = Player:GetPosition()
local Height = World:GetHeight( math.floor(PlayerPos.x), math.floor(PlayerPos.z) )
Player:TeleportTo( PlayerPos.x, Height+1, PlayerPos.z )
Player:SendMessage("Teleported to the top block")
return true
end

20
Plugins/NewTest/unban.lua Normal file
View File

@ -0,0 +1,20 @@
function HandleUnbanCommand( Split, Player )
if( #Split < 2 ) then
Player:SendMessage( cChatColor.Green .. "Usage: /unban [Player]" )
return true
end
if( BannedPlayersIni:GetValueB("Banned", Split[2], false) == false ) then
Player:SendMessage( cChatColor.Green .. Split[2] .. " is not banned!" )
return true
end
BannedPlayersIni:SetValueB("Banned", Split[2], false, false)
BannedPlayersIni:WriteFile()
local Server = cRoot:Get():GetServer()
LOGINFO( Player:GetName() .. " is unbanning " .. Split[2] )
Server:SendMessage( "Unbanning " .. Split[2] )
return true
end