summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--MCServer/Plugins/Core/README.md10
-rw-r--r--MCServer/Plugins/Core/console.lua63
-rw-r--r--MCServer/Plugins/Core/item.lua4
3 files changed, 70 insertions, 7 deletions
diff --git a/MCServer/Plugins/Core/README.md b/MCServer/Plugins/Core/README.md
index 418c23b87..bec3eb22b 100644
--- a/MCServer/Plugins/Core/README.md
+++ b/MCServer/Plugins/Core/README.md
@@ -56,11 +56,11 @@ Commands
Contributors
------------
-FakeTruth
-xoft
-tigerw
-bearbin
-tonibm19
+FakeTruth
+xoft
+tigerw
+bearbin
+tonibm19
(If you want your name here, please submit a PR after you've done your contributions.)
diff --git a/MCServer/Plugins/Core/console.lua b/MCServer/Plugins/Core/console.lua
index 8fd548612..c4ee291ea 100644
--- a/MCServer/Plugins/Core/console.lua
+++ b/MCServer/Plugins/Core/console.lua
@@ -9,6 +9,7 @@ function InitConsoleCommands()
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("give", HandleConsoleGive, " - Gives items to the specified player.")
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");
@@ -23,6 +24,66 @@ function InitConsoleCommands()
end
+function HandleConsoleGive(Split)
+
+ -- Make sure there are a correct number of arguments.
+ if #Split ~= 3 and #Split ~= 4 and #Split ~= 5 then
+ return true, "Usage: give <player> <item> [amount] [meta]"
+ end
+
+ -- 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
+ return true, "Invalid item id or name!"
+ end
+
+ -- 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
+ return true, "Invalid amount!"
+ end
+ end
+
+ Item.m_ItemCount = ItemAmount
+
+ -- 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 .. "There you go!" )
+ 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)
+ return true, "Only " .. Item.m_ItemCount .. " out of " .. ItemsGiven .. "items could be delivered.")
+ end
+ end
+
+ -- 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
+ return true, "There was no player that matched your query."
+ end
+
+ return true
+
+end
+end
+
function HandleConsoleBan(Split)
if (#Split < 2) then
return true, "Usage: ban [Player] <Reason>";
@@ -50,7 +111,7 @@ end
function HandleConsoleUnban(Split)
if( #Split < 2 ) then
- return true, "Usage: /unban [Player]"
+ return true, "Usage: unban [Player]"
end
if( BannedPlayersIni:GetValueB("Banned", Split[2], false) == false ) then
diff --git a/MCServer/Plugins/Core/item.lua b/MCServer/Plugins/Core/item.lua
index b665e5208..37a2b8cf5 100644
--- a/MCServer/Plugins/Core/item.lua
+++ b/MCServer/Plugins/Core/item.lua
@@ -5,7 +5,8 @@ function HandleItemCommand(Split, Player)
return true
end
- itemSplit = StringSplit(Split[2], ":")
+ local itemSplit = StringSplit(Split[2], ":")
+ local newSplit = {}
newSplit[1] = "/give"
newSplit[2] = Player:GetName()
@@ -21,4 +22,5 @@ function HandleItemCommand(Split, Player)
HandleGiveCommand(newSplit, Player)
return true
+
end \ No newline at end of file