mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-15 13:04:36 +00:00
Fix crash when scoreboard is updated on MC 1.20.4+
ChatParser.NbtToString crashed with InvalidCastException when a scoreboard update was received. The switch expressions for extra/with NBT arrays only handled int and string; everything else fell through to a hard cast to Dictionary<string,object>, which fails for long/short/byte/float/double. Replace with a pattern that explicitly matches string and Dictionary, and converts all other values (any numeric NBT type) to a text component via ToString(). This matches the behavior that ReadNbtField can return for TAG_Byte, TAG_Short, TAG_Int, TAG_Long, TAG_Float, and TAG_Double. Co-authored-by: milutinke <441903+milutinke@users.noreply.github.com> Agent-Logs-Url: https://github.com/MCCTeam/Minecraft-Console-Client/sessions/44b66082-14ee-4966-9c23-4074134e0187
This commit is contained in:
parent
0168cf8aa1
commit
8ab9f8505f
1 changed files with 6 additions and 12 deletions
|
|
@ -531,12 +531,9 @@ namespace MinecraftClient.Protocol.Message
|
|||
{
|
||||
var extraDict = extras[i] switch
|
||||
{
|
||||
int => new Dictionary<string, object> { { "text", $"{extras[i]}" } },
|
||||
string => new Dictionary<string, object>
|
||||
{
|
||||
{ "text", (string)extras[i] }
|
||||
},
|
||||
_ => (Dictionary<string, object>)extras[i]
|
||||
string s => new Dictionary<string, object> { { "text", s } },
|
||||
Dictionary<string, object> d => d,
|
||||
_ => new Dictionary<string, object> { { "text", extras[i]?.ToString() ?? string.Empty } }
|
||||
};
|
||||
|
||||
extraBuilder.Append(NbtToString(extraDict) + "§r");
|
||||
|
|
@ -556,12 +553,9 @@ namespace MinecraftClient.Protocol.Message
|
|||
{
|
||||
var withDict = withs[i] switch
|
||||
{
|
||||
int => new Dictionary<string, object> { { "text", $"{withs[i]}" } },
|
||||
string => new Dictionary<string, object>
|
||||
{
|
||||
{ "text", (string)withs[i] }
|
||||
},
|
||||
_ => (Dictionary<string, object>)withs[i]
|
||||
string s => new Dictionary<string, object> { { "text", s } },
|
||||
Dictionary<string, object> d => d,
|
||||
_ => new Dictionary<string, object> { { "text", withs[i]?.ToString() ?? string.Empty } }
|
||||
};
|
||||
|
||||
translateString.Add(NbtToString(withDict));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue