Implement tab list display name update

Packet 0x2D with action 0x03
This commit is contained in:
ORelio 2016-08-23 00:13:46 +02:00
parent 461385d057
commit b1d4f85b23
4 changed files with 31 additions and 7 deletions

View file

@ -597,6 +597,21 @@ namespace MinecraftClient
}
}
/// <summary>
/// Get an online player by UUID
/// </summary>
/// <param name="uuid">Player UUID</param>
/// <returns>The player, or NULL if not found</returns>
public PlayerInfo GetPlayer(Guid uuid)
{
lock (onlinePlayers)
{
if (onlinePlayers.ContainsKey(uuid))
return onlinePlayers[uuid];
return null;
}
}
/// <summary>
/// Registers the given plugin channel for the given bot.
/// </summary>

View file

@ -447,8 +447,17 @@ namespace MinecraftClient.Protocol.Handlers
readNextVarInt(packetData);
break;
case 0x03: //Update display name
if (readNextBool(packetData))
readNextString(packetData);
bool hasDisplayName = readNextBool(packetData);
string newDisplayName = null;
if (hasDisplayName)
newDisplayName = readNextString(packetData);
PlayerInfo player = handler.GetPlayer(uuid);
if (player != null)
{
if (hasDisplayName)
player.DisplayName = newDisplayName;
else player.DisplayName = player.Name;
}
break;
case 0x04: //Player Leave
handler.OnPlayerLeave(uuid);

View file

@ -23,6 +23,7 @@ namespace MinecraftClient.Protocol
string GetUserUUID();
string GetSessionID();
PlayerInfo[] GetOnlinePlayers();
PlayerInfo GetPlayer(Guid uuid);
Location GetCurrentLocation();
World GetWorld();

View file

@ -8,15 +8,14 @@ namespace MinecraftClient.Protocol
/// <summary>
/// Information about a player (player tab list item)
/// </summary>
public struct PlayerInfo : IComparable<PlayerInfo>
public class PlayerInfo : IComparable<PlayerInfo>
{
private Guid _uuid;
private string _name;
private string _displayName;
public Guid UUID { get { return _uuid; } }
public string Name { get { return _name; } }
public string DisplayName { get { return _displayName; } }
public string DisplayName { get; set; }
/// <summary>
/// Create a new PlayerInfo structure
@ -27,7 +26,7 @@ namespace MinecraftClient.Protocol
{
_uuid = uuid;
_name = name;
_displayName = name;
DisplayName = name;
}
/// <summary>
@ -39,7 +38,7 @@ namespace MinecraftClient.Protocol
public PlayerInfo(Guid uuid, string name, string displayName)
: this(uuid, name)
{
_displayName = displayName;
DisplayName = displayName;
}
/// <summary>