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