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

@ -1,26 +1,26 @@
/* /*
Copyright 2011 MCForge Copyright 2011 MCForge
Dual-licensed under the Educational Community License, Version 2.0 and Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing, Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS" software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses. permissions and limitations under the Licenses.
*/ */
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) {
Player[] players = PlayerInfo.Online.Items; nick = Colors.StripColours(nick);
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;