commit
240ca3c972
@ -27,6 +27,7 @@ namespace TrueCraft.Commands
|
|||||||
Commands.Add(new PositionCommand());
|
Commands.Add(new PositionCommand());
|
||||||
Commands.Add(new TimeCommand());
|
Commands.Add(new TimeCommand());
|
||||||
Commands.Add(new LogCommand());
|
Commands.Add(new LogCommand());
|
||||||
|
Commands.Add(new TellCommand());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
69
TrueCraft/Commands/TellCommand.cs
Normal file
69
TrueCraft/Commands/TellCommand.cs
Normal 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>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -56,6 +56,7 @@
|
|||||||
<Compile Include="Commands\GiveMeCommand.cs" />
|
<Compile Include="Commands\GiveMeCommand.cs" />
|
||||||
<Compile Include="Commands\HelpCommand.cs" />
|
<Compile Include="Commands\HelpCommand.cs" />
|
||||||
<Compile Include="Commands\PingCommand.cs" />
|
<Compile Include="Commands\PingCommand.cs" />
|
||||||
|
<Compile Include="Commands\TellCommand.cs" />
|
||||||
<Compile Include="Commands\TimeCommand.cs" />
|
<Compile Include="Commands\TimeCommand.cs" />
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
Reference in New Issue
Block a user