From 54a6338c40fbb4cc84d89d90091cb2eda3edec3e Mon Sep 17 00:00:00 2001 From: Daniel V Date: Sun, 3 May 2015 19:38:09 -0400 Subject: [PATCH] Give command fixes - You can no longer try to give a player an invalid item. - The give command now gives the specified player the items, and not the player that issued the command --- TrueCraft.sln | 19 ++++++++++++++++++- TrueCraft/Commands/CommandManager.cs | 2 +- TrueCraft/Commands/GiveCommand.cs | 16 +++++++++++++--- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/TrueCraft.sln b/TrueCraft.sln index 4f05a63..752bfb2 100644 --- a/TrueCraft.sln +++ b/TrueCraft.sln @@ -51,6 +51,23 @@ Global {FEE55B54-91B0-4325-A2C3-D576C0B7A81F}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(MonoDevelopProperties) = preSolution - StartupItem = TrueCraft\TrueCraft.csproj + Policies = $0 + $0.TextStylePolicy = $1 + $1.FileWidth = 120 + $1.inheritsSet = VisualStudio + $1.inheritsScope = text/plain + $1.scope = text/x-csharp + $0.CSharpFormattingPolicy = $2 + $2.BeforeMethodDeclarationParentheses = False + $2.BeforeMethodCallParentheses = False + $2.BeforeConstructorDeclarationParentheses = False + $2.BeforeIndexerDeclarationBracket = False + $2.BeforeDelegateDeclarationParentheses = False + $2.AfterDelegateDeclarationParameterComma = True + $2.NewParentheses = False + $2.SpacesBeforeBrackets = False + $2.inheritsSet = Mono + $2.inheritsScope = text/x-csharp + $2.scope = text/x-csharp EndGlobalSection EndGlobal diff --git a/TrueCraft/Commands/CommandManager.cs b/TrueCraft/Commands/CommandManager.cs index 3b7657d..464a1b5 100644 --- a/TrueCraft/Commands/CommandManager.cs +++ b/TrueCraft/Commands/CommandManager.cs @@ -41,7 +41,7 @@ namespace TrueCraft.Commands ICommand foundCommand = FindByName(alias) ?? FindByAlias(alias); if (foundCommand == null) { - client.SendMessage("Unable to locate the command \"" + alias + "\". It might be in a different server!"); + client.SendMessage("Invalid command \"" + alias + "\"."); return; } foundCommand.Handle(client, alias, arguments); diff --git a/TrueCraft/Commands/GiveCommand.cs b/TrueCraft/Commands/GiveCommand.cs index 6f0a152..7911155 100644 --- a/TrueCraft/Commands/GiveCommand.cs +++ b/TrueCraft/Commands/GiveCommand.cs @@ -32,13 +32,23 @@ namespace TrueCraft.Commands Help(Client, Alias, Arguments); return; } - // TODO: Send items to the client mentioned in the command, not the client issuing the command - // TODO: Check to make sure an item with that ID actually exists + + IRemoteClient receiver = Client.Server.Clients.SingleOrDefault(c => c.Username == Arguments[1]); short id; sbyte count; if (short.TryParse(Arguments[2], out id) && sbyte.TryParse(Arguments[3], out count)) { - var inventory = Client.Inventory as InventoryWindow; + if (receiver == null) { + Client.SendMessage("No client with the username \"" + Arguments[1] + "\" was found."); + return; + } + + if (Client.Server.ItemRepository.GetItemProvider(id) == null) { + Client.SendMessage("Invalid item id \"" + id + "\"."); + return; + } + + var inventory = receiver.Inventory as InventoryWindow; inventory.PickUpStack(new ItemStack(id, count)); } }