mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-15 13:04:36 +00:00
fix: handle null/empty profile name in ProfileComponent serialization
Prevents NullReferenceException crash when receiving player head items with an empty or absent profile name. The Minecraft protocol permits empty names in the profile component; the serialization path now falls back to an empty string instead of throwing.
This commit is contained in:
parent
31876d485a
commit
85fe6b451b
1 changed files with 3 additions and 16 deletions
|
|
@ -112,12 +112,7 @@ public class ProfileComponent(DataTypes dataTypes, ItemPalette itemPalette, SubC
|
|||
|
||||
data.AddRange(DataTypes.GetBool(HasName));
|
||||
if (HasName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Name))
|
||||
throw new NullReferenceException("Can't serialize the ProfileComponent because the Name is null/empty!");
|
||||
|
||||
data.AddRange(DataTypes.GetString(Name));
|
||||
}
|
||||
data.AddRange(DataTypes.GetString(Name ?? ""));
|
||||
|
||||
data.AddRange(DataTypes.GetBool(HasUniqueId));
|
||||
if (HasUniqueId)
|
||||
|
|
@ -140,22 +135,14 @@ public class ProfileComponent(DataTypes dataTypes, ItemPalette itemPalette, SubC
|
|||
if (!HasUniqueId)
|
||||
throw new NullReferenceException("Can't serialize the ProfileComponent because a full profile requires a UUID!");
|
||||
|
||||
if (!HasName || string.IsNullOrEmpty(Name))
|
||||
throw new NullReferenceException("Can't serialize the ProfileComponent because a full profile requires a name!");
|
||||
|
||||
data.AddRange(DataTypes.GetUUID(Uuid));
|
||||
data.AddRange(DataTypes.GetString(Name));
|
||||
data.AddRange(DataTypes.GetString(Name ?? ""));
|
||||
}
|
||||
else
|
||||
{
|
||||
data.AddRange(DataTypes.GetBool(HasName));
|
||||
if (HasName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Name))
|
||||
throw new NullReferenceException("Can't serialize the ProfileComponent because HasName is true, but the Name is null/empty!");
|
||||
|
||||
data.AddRange(DataTypes.GetString(Name));
|
||||
}
|
||||
data.AddRange(DataTypes.GetString(Name ?? ""));
|
||||
|
||||
data.AddRange(DataTypes.GetBool(HasUniqueId));
|
||||
if (HasUniqueId)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue