Merge pull request #80 from manio143/tellCommand

/tell command added
This commit is contained in:
Drew DeVault 2015-05-13 14:35:14 -06:00
commit 240ca3c972
3 changed files with 71 additions and 0 deletions

View File

@ -27,6 +27,7 @@ namespace TrueCraft.Commands
Commands.Add(new PositionCommand());
Commands.Add(new TimeCommand());
Commands.Add(new LogCommand());
Commands.Add(new TellCommand());
}
/// <summary>

View File

@ -0,0 +1,69 @@
using System;
using System.Linq;
using TrueCraft.API.Networking;
using TrueCraft.API;
namespace TrueCraft.Commands
{
public class TellCommand : Command
{
public override string Name
{
get { return "tell"; }
}
public override string Description
{
get { return "Whisper someone a message."; }
}
public override string[] Aliases
{
get { return new string[0]; }
}
public override void Handle(IRemoteClient client, string alias, string[] arguments)
{
if (arguments.Length < 2)
{
Help(client, alias, arguments);
return;
}
string username = arguments[0];
var messageBuilder = new System.Text.StringBuilder();
for (int i = 1; i < arguments.Length; i++)
messageBuilder.Append(arguments[i] + " ");
var message = messageBuilder.ToString();
var receivingPlayer = GetPlayerByName(client, username);
if (receivingPlayer == null)
{
client.SendMessage("No client with the username \"" + username + "\" was found.");
return;
}
if (receivingPlayer == client)
{
client.SendMessage(ChatColor.Red + "You can't send a private message to yourself!");
return;
}
receivingPlayer.SendMessage(ChatColor.Gray + "<"+ client.Username + " -> You> " + message);
}
protected static IRemoteClient GetPlayerByName(IRemoteClient client, string username)
{
var receivingPlayer =
client.Server.Clients.FirstOrDefault(
c => String.Equals(c.Username, username, StringComparison.CurrentCultureIgnoreCase));
return receivingPlayer;
}
public override void Help(IRemoteClient client, string alias, string[] arguments)
{
client.SendMessage("Correct usage is /" + alias + "<player> <message>");
}
}
}

View File

@ -56,6 +56,7 @@
<Compile Include="Commands\GiveMeCommand.cs" />
<Compile Include="Commands\HelpCommand.cs" />
<Compile Include="Commands\PingCommand.cs" />
<Compile Include="Commands\TellCommand.cs" />
<Compile Include="Commands\TimeCommand.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />