diff --git a/MCServer/Plugins/Core/README.md b/MCServer/Plugins/Core/README.md index d840459a0..418c23b87 100644 --- a/MCServer/Plugins/Core/README.md +++ b/MCServer/Plugins/Core/README.md @@ -1,23 +1,70 @@ -Core Plugin (Forked) -=========== +MCServer Core Plugin +==================== -A fork of MCServer's Core plugin. +The Core plugin for MCServer provides the default utility commands and also a lot of WebAdmin goodness. -**New Features:** -* Simplified commands, such as 'gotoworld' -> 'portal' -* Simplified and combined LUA files, such as 'listworlds.lua & gotoworld.lua' -> 'worlds-portal.lua' -* Fixed 'tp' command not working due to typography errors -* Fixed 'arithmetic on nil value' on startup due to inactivation of world limiter -* Massive overhaul / redesign of webadmin GUI interface. - * Added jQuery transition effect - * Completely redesigned CSS - * Added new logo - * Made HTML5 compliant -* Beautified 'help' menu -* Rewrite of death messages - fixed strange grammar and edited to more faithfully reflect Vanilla -* Added 'unban' console command +Commands +-------- -**How to Use** + * /back + * /ban + * /downfall + * /give + * /gm + * /groups + * /help + * /i + * /item + * /kick + * /locate + * /me + * /motd + * /plugins + * /portal + * /rank + * /regen + * /reload + * /save-all + * /spawn + * /stop + * /time + * /top + * /tp + * /tpa + * /tpaccept + * /unban + * /viewdistance + * /worlds -Simply copy all LUA files into Plugins/Core (delete existing files first, except banned.ini and whitelist.ini!) -Then, copy webadmin to MCServer root directory (delete existing directory first!) +**Also, console commands:** + + * ban + * banlist + * getversion + * help + * list + * listgroups + * numchunks + * players + * rank + * reload + * say + * setversion + * unban + * unload + +Contributors +------------ + +FakeTruth +xoft +tigerw +bearbin +tonibm19 + +(If you want your name here, please submit a PR after you've done your contributions.) + +How to Use +---------- + +Core should be installed in MCServer by default. diff --git a/MCServer/Plugins/Core/console.lua b/MCServer/Plugins/Core/console.lua index 59a60ae62..8fd548612 100644 --- a/MCServer/Plugins/Core/console.lua +++ b/MCServer/Plugins/Core/console.lua @@ -5,21 +5,22 @@ function InitConsoleCommands() -- Please keep the list alpha-sorted PluginMgr:BindConsoleCommand("ban", HandleConsoleBan, " ~ Bans a player by name"); - PluginMgr:BindConsoleCommand("unban", HandleConsoleUnban, " ~ Unbans a player by name"); - PluginMgr:BindConsoleCommand("banlist", HandleConsoleBanList, " - Lists all players banned by name"); PluginMgr:BindConsoleCommand("banlist ips", HandleConsoleBanList, " - Lists all players banned by IP"); + PluginMgr:BindConsoleCommand("banlist", HandleConsoleBanList, " - Lists all players banned by name"); + PluginMgr:BindConsoleCommand("getversion", HandleConsoleVersion, " - Gets server version reported to 1.4+ clients"); PluginMgr:BindConsoleCommand("help", HandleConsoleHelp, " - Lists all commands"); PluginMgr:BindConsoleCommand("list", HandleConsoleList, " - Lists all players in a machine-readable format"); PluginMgr:BindConsoleCommand("listgroups", HandleConsoleListGroups, " - Shows a list of all the groups"); PluginMgr:BindConsoleCommand("numchunks", HandleConsoleNumChunks, " - Shows number of chunks currently loaded"); PluginMgr:BindConsoleCommand("players", HandleConsolePlayers, " - Lists all connected players"); - PluginMgr:BindConsoleCommand("getversion", HandleConsoleVersion, " - Gets server version reported to 1.4+ clients"); - PluginMgr:BindConsoleCommand("setversion", HandleConsoleVersion, " ~ Sets server version reported to 1.4+ clients"); PluginMgr:BindConsoleCommand("rank", HandleConsoleRank, " ~ Add a player to a group"); PluginMgr:BindConsoleCommand("reload", HandleConsoleReload, " - Reloads all plugins"); PluginMgr:BindConsoleCommand("save-all", HandleConsoleSaveAll, " - Saves all chunks"); PluginMgr:BindConsoleCommand("say", HandleConsoleSay, " - Sends a chat message to all players"); + PluginMgr:BindConsoleCommand("setversion", HandleConsoleVersion, " ~ Sets server version reported to 1.4+ clients"); + PluginMgr:BindConsoleCommand("unban", HandleConsoleUnban, " ~ Unbans a player by name"); PluginMgr:BindConsoleCommand("unload", HandleConsoleUnload, " - Unloads all unused chunks"); + end function HandleConsoleBan(Split) diff --git a/MCServer/Plugins/Core/give.lua b/MCServer/Plugins/Core/give.lua index d1c7ae59f..ba3a1eb41 100644 --- a/MCServer/Plugins/Core/give.lua +++ b/MCServer/Plugins/Core/give.lua @@ -1,39 +1,65 @@ function HandleGiveCommand(Split, Player) - if ((#Split ~= 2) and (#Split ~=3)) then - Player:SendMessage(cChatColor.Yellow .. "[INFO] " .. cChatColor.White .. "Usage: /give [ItemType/Name:Dmg] " ); - return true; + + -- Make sure there are a correct number of arguments. + if #Split ~= 3 and #Split ~= 4 and #Split ~= 5 then + Player:SendMessage( cChatColor.Yellow .. "[INFO] " .. cChatColor.White .. "Usage: /give [amount] [meta]" ) + return true end - local Item = cItem(); - local FoundItem = StringToItem(Split[2], Item); - - if not(IsValidItem(Item.m_ItemType)) then -- StringToItem does not check if item is valid + -- Get the item from the arguments and check it's valid. + local Item = cItem() + if #Split == 5 then + local FoundItem = StringToItem(Split[3] .. ":" .. Split[5], Item) + else + local FoundItem = StringToItem(Split[3], Item) + end + if not IsValidItem(Item.m_ItemType) then -- StringToItem does not check if item is valid FoundItem = false end - if not(FoundItem) then + if not FoundItem then Player:SendMessage(cChatColor.Rose .. "[INFO] " .. cChatColor.White .. "Invalid item id or name!" ) return true end - local ItemAmount = 1; - if (#Split == 3) then - ItemAmount = tonumber(Split[3]); - if ((ItemAmount == nil) or (ItemAmount < 1) or (ItemAmount > 512)) then - Player:SendMessage(cChatColor.Rose .. "[INFO] " .. cChatColor.White .. "Invalid amount!" ); - return true; + -- Work out how many items the user wants. + local ItemAmount = 1 + if #Split > 3 then + ItemAmount = tonumber(Split[4]) + if ItemAmount == nil or ItemAmount < 1 or ItemAmount > 512 then + Player:SendMessage(cChatColor.Rose .. "[INFO] " .. cChatColor.White .. "Invalid amount!" ) + return true end end - Item.m_ItemCount = ItemAmount; + Item.m_ItemCount = ItemAmount - local ItemsGiven = Player:GetInventory():AddItem(Item); - if (ItemsGiven == ItemAmount) then - Player:SendMessage(cChatColor.Green .. "[INFO] " .. cChatColor.White .. "There you go!" ); - LOG("Gave " .. Player:GetName() .. " " .. Item.m_ItemCount .. " times " .. Item.m_ItemType .. ":" .. Item.m_ItemDamage); - else - Player:SendMessage(cChatColor.Rose .. "[INFO] " .. cChatColor.White .. "Not enough space in inventory, only gave " .. ItemsGiven); - LOG("Player " .. Player:GetName() .. " asked for " .. Item.m_ItemCount .. " times " .. Item.m_ItemType .. ":" .. Item.m_ItemDamage ..", but only could fit " .. ItemsGiven); + -- Get the playername from the split. + local playerName = Split[2] + + local function giveItems(newPlayer) + local ItemsGiven = newPlayer:GetInventory():AddItem(Item) + if ItemsGiven == ItemAmount then + newPlayer:SendMessage(cChatColor.Green .. "[INFO] " .. cChatColor.White .. "You were given " .. Item.m_ItemCount .. " of " .. Item.m_ItemType .. "." ) + if not newPlayer == Player then + Player:SendMessage(cChatColor.Green .. "[INFO] " .. cChatColor.White .. "Items given!" ) + end + LOG("Gave " .. newPlayer:GetName() .. " " .. Item.m_ItemCount .. " times " .. Item.m_ItemType .. ":" .. Item.m_ItemDamage) + else + Player:SendMessage( cChatColor.Rose .. "[INFO] " .. cChatColor.White .. "Not enough space in inventory, only gave " .. ItemsGiven) + LOG( "Player " .. Player:GetName() .. " asked for " .. Item.m_ItemCount .. " times " .. Item.m_ItemType .. ":" .. Item.m_ItemDamage ..", but only could fit " .. ItemsGiven ) + end + return true end - return true; -end \ No newline at end of file + + -- Finally give the items to the player. + itemStatus = cRoot:Get():FindAndDoWithPlayer(playerName, giveItems) + + -- Check to make sure that giving items was successful. + if not itemStatus then + Player:SendMessage( cChatColor.Rose .. "[INFO] " .. cChatColor.White .. "There was no player that matched your query.") + end + + return true + +end diff --git a/MCServer/Plugins/Core/item.lua b/MCServer/Plugins/Core/item.lua new file mode 100644 index 000000000..b665e5208 --- /dev/null +++ b/MCServer/Plugins/Core/item.lua @@ -0,0 +1,24 @@ +function HandleItemCommand(Split, Player) + + if ((#Split ~= 2) and (#Split ~=3)) then + Player:SendMessage(cChatColor.Yellow .. "[INFO] " .. cChatColor.White .. "Usage: /i [:meta] [amount]" ) + return true + end + + itemSplit = StringSplit(Split[2], ":") + + newSplit[1] = "/give" + newSplit[2] = Player:GetName() + newSplit[3] = itemSplit[1] + if Split[3] ~= nil then + newSplit[4] = Split[3] + else + newSplit[4] = 1 + end + if itemSplit[2] ~= nil then + newSplit[5] = itemSplit[2] + end + + HandleGiveCommand(newSplit, Player) + return true +end \ No newline at end of file diff --git a/MCServer/Plugins/Core/main.lua b/MCServer/Plugins/Core/main.lua index 3fd9c6585..9c476a48c 100644 --- a/MCServer/Plugins/Core/main.lua +++ b/MCServer/Plugins/Core/main.lua @@ -29,12 +29,16 @@ function Initialize(Plugin) --BIND COMMANDS PluginManager:BindCommand("/back", "core.back", HandleBackCommand, " - Return to your last position"); PluginManager:BindCommand("/ban", "core.ban", HandleBanCommand, " ~ Ban a player"); - PluginManager:BindCommand("/give", "core.give", HandleGiveCommand, " ~ Give yourself an item"); + PluginManager:BindCommand("/downfall", "core.downfall", HandleDownfallCommand, " - Toggles the weather"); + PluginManager:BindCommand("/give", "core.give", HandleGiveCommand, " ~ Give someone an item"); PluginManager:BindCommand("/gm", "core.changegm", HandleChangeGMCommand, " ~ Change your gamemode"); - PluginManager:BindCommand("/help", "core.help", HandleHelpCommand, " ~ Show available commands"); - PluginManager:BindCommand("/kick", "core.kick", HandleKickCommand, " ~ Kick a player"); PluginManager:BindCommand("/groups", "core.groups", HandleGroupsCommand, " - Shows a list of all the groups"); + PluginManager:BindCommand("/help", "core.help", HandleHelpCommand, " ~ Show available commands"); + PluginManager:BindCommand("/i", "core.give", HandleItemCommand, "") + PluginManager:BindCommand("/item", "core.give", HandleItemCommand, " - Give yourself an item.") + PluginManager:BindCommand("/kick", "core.kick", HandleKickCommand, " ~ Kick a player"); PluginManager:BindCommand("/locate", "core.locate", HandleLocateCommand, " - Show your current server coordinates"); + PluginManager:BindCommand("/me", "core.me", HandleMeCommand, " ~ Tell what you are doing"); PluginManager:BindCommand("/motd", "core.motd", HandleMOTDCommand, " - Show message of the day"); PluginManager:BindCommand("/plugins", "core.plugins", HandlePluginsCommand, " - Show list of plugins"); PluginManager:BindCommand("/portal", "core.portal", HandlePortalCommand, " ~ Move to a different world"); @@ -45,8 +49,6 @@ function Initialize(Plugin) PluginManager:BindCommand("/spawn", "core.spawn", HandleSpawnCommand, " - Return to the spawn"); PluginManager:BindCommand("/stop", "core.stop", HandleStopCommand, " - Stops the server"); PluginManager:BindCommand("/time", "core.time", HandleTimeCommand, " ~ Sets the time of day"); - PluginManager:BindCommand("/downfall", "core.downfall", HandleDownfallCommand, " - Toggles the weather"); - PluginManager:BindCommand("/me", "core.me", HandleMeCommand, " ~ Tell what you are doing"); PluginManager:BindCommand("/top", "core.top", HandleTopCommand, " - Teleport yourself to the top most block"); PluginManager:BindCommand("/tp", "core.teleport", HandleTPCommand, " ~ Teleport yourself to a player"); PluginManager:BindCommand("/tpa", "core.teleport", HandleTPACommand, " ~ Ask to teleport yourself to a player"); diff --git a/MCServer/Plugins/Core/time.lua b/MCServer/Plugins/Core/time.lua index b5d3c991a..fd2816f23 100644 --- a/MCServer/Plugins/Core/time.lua +++ b/MCServer/Plugins/Core/time.lua @@ -9,7 +9,7 @@ function HandleTimeCommand( Split, Player ) Server:SendMessage(cChatColor.Green .. "[INFO] " .. cChatColor.White .. "Time was set to daytime" ) elseif( string.upper( Split[2] ) == "NIGHT") then Player:GetWorld():SetTimeOfDay( 12000 + 1000 ) - Server:SendMessage(cChatColor.Green .. "[INFO] " .. cChatColor.White .. "Time was set to nighttime" ) + Server:SendMessage(cChatColor.Green .. "[INFO] " .. cChatColor.White .. "Time was set to night time" ) elseif( string.upper(Split[2]) == "SET" ) and ( tonumber(Split[3]) ~= nil) then Player:GetWorld():SetTimeOfDay( tonumber(Split[3]) ) Server:SendMessage(cChatColor.Green .. "[INFO] " .. cChatColor.White .. "Time was set to " .. Split[3] ) @@ -20,4 +20,4 @@ function HandleTimeCommand( Split, Player ) Player:SendMessage(cChatColor.Yellow .. "[INFO] " .. cChatColor.White .. "Usage: /time [Day/Night/Set/Add]" ) end return true -end \ No newline at end of file +end