Ignore colour codes for /whonick.

This commit is contained in:
UnknownShadow200 2016-04-10 15:09:13 +10:00
parent 47db736f16
commit 0e1f67efba
4 changed files with 38 additions and 37 deletions

View File

@ -17,10 +17,10 @@
*/
using System.Data;
using MCGalaxy.SQL;
namespace MCGalaxy.Commands
{
public sealed class CmdWhoNick : Command
{
namespace MCGalaxy.Commands {
public sealed class CmdWhoNick : Command {
public override string name { get { return "whonick"; } }
public override string shortcut { get { return ""; } }
public override string type { get { return CommandTypes.Information; } }
@ -28,19 +28,16 @@ namespace MCGalaxy.Commands
public override LevelPermission defaultRank { get { return LevelPermission.Guest; } }
public CmdWhoNick() { }
public override void Use(Player p, string message)
{
public override void Use(Player p, string message) {
if (message == "") { Help(p); return; }
if (PlayerInfo.FindNick(message) == null)
{
Player.SendMessage(p, "The player is not online.");
return;
Player nick = PlayerInfo.FindNick(p, message);
if (nick == null) {
Player.SendMessage(p, "The player is not online."); return;
}
Player.SendMessage(p, "This player's real username is " + PlayerInfo.FindNick(message).name);
Player.SendMessage(p, "This player's real username is " + nick.name);
}
public override void Help(Player p)
{
public override void Help(Player p) {
Player.SendMessage(p, "/whonick <nickname> - Displays player's real username");
}
}

View File

@ -672,7 +672,7 @@ catch { }*/
public static Player FindExact(string name) { return PlayerInfo.FindExact(name); }
[Obsolete("Use PlayerInfo.FindNick(name)")]
public static Player FindNick(string name) { return PlayerInfo.FindNick(name); }
public static Player FindNick(string name) { return PlayerInfo.FindNick(null, name); }
static byte FreeId() {
/*

View File

@ -94,14 +94,18 @@ namespace MCGalaxy {
return null;
}
public static Player FindNick(string nick) {
public static Player FindNick(Player p, string nick) {
nick = Colors.StripColours(nick);
Player[] players = PlayerInfo.Online.Items;
Player match = null; int matches = 0;
foreach (Player p in players) {
if (p.DisplayName.Equals(nick, comp)) return p;
if (p.DisplayName.IndexOf(nick, comp) >= 0) {
match = p; matches++;
foreach (Player pl in players) {
if (!Player.CanSee(p, pl)) continue;
string name = Colors.StripColours(nick);
if (name.Equals(nick, comp)) return pl;
if (name.IndexOf(nick, comp) >= 0) {
match = pl; matches++;
}
}
return matches == 1 ? match : null;

View File

@ -177,14 +177,14 @@ namespace MCGalaxy {
}
public static string StripColours(string value) {
if (value.IndexOf('%') == -1)
if (value.IndexOf('%') == -1 && value.IndexOf('&') == -1)
return value;
char[] output = new char[value.Length];
int usedChars = 0;
for (int i = 0; i < value.Length; i++) {
char token = value[i];
if( token == '%' ) {
if( token == '%' || token == '&' ) {
i++; // Skip over the following colour code.
} else {
output[usedChars++] = token;