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 System.Data;
using MCGalaxy.SQL; using MCGalaxy.SQL;
namespace MCGalaxy.Commands namespace MCGalaxy.Commands {
{
public sealed class CmdWhoNick : Command public sealed class CmdWhoNick : Command {
{
public override string name { get { return "whonick"; } } public override string name { get { return "whonick"; } }
public override string shortcut { get { return ""; } } public override string shortcut { get { return ""; } }
public override string type { get { return CommandTypes.Information; } } public override string type { get { return CommandTypes.Information; } }
@ -28,19 +28,16 @@ namespace MCGalaxy.Commands
public override LevelPermission defaultRank { get { return LevelPermission.Guest; } } public override LevelPermission defaultRank { get { return LevelPermission.Guest; } }
public CmdWhoNick() { } public CmdWhoNick() { }
public override void Use(Player p, string message) public override void Use(Player p, string message) {
{
if (message == "") { Help(p); return; } if (message == "") { Help(p); return; }
if (PlayerInfo.FindNick(message) == null) Player nick = PlayerInfo.FindNick(p, message);
{ if (nick == null) {
Player.SendMessage(p, "The player is not online."); Player.SendMessage(p, "The player is not online."); return;
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"); 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); } public static Player FindExact(string name) { return PlayerInfo.FindExact(name); }
[Obsolete("Use PlayerInfo.FindNick(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() { static byte FreeId() {
/* /*

View File

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

View File

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