Skip to content

Commit

Permalink
Fixed bad code and the bug
Browse files Browse the repository at this point in the history
  • Loading branch information
milutinke committed Jan 28, 2024
1 parent 3bfe5aa commit f325dd7
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions MinecraftClient/Protocol/Handlers/Protocol18.cs
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,6 @@ internal bool HandlePacket(int packetId, Queue<byte> packetData)

private bool HandlePlayPackets(int packetId, Queue<byte> packetData)
{
try{
switch (packetPalette.GetIncommingTypeById(packetId))
{
case PacketTypesIn.KeepAlive: // Keep Alive (Play)
Expand Down Expand Up @@ -797,9 +796,10 @@ private bool HandlePlayPackets(int packetId, Queue<byte> packetData)
: null;

var chatInfo = Json.ParseJson(chatName).Properties;
var senderDisplayName =
(chatInfo.ContainsKey("insertion") ? chatInfo["insertion"] : (chatInfo.ContainsKey("text") ? chatInfo["text"] : ""))
.StringValue;
var senderDisplayName = chatInfo != null && chatInfo.Count > 0
? (chatInfo.ContainsKey("insertion") ? chatInfo["insertion"] : chatInfo["text"])
.StringValue
: "";
string? senderTeamName = null;
var messageTypeEnum =
ChatParser.ChatId2Type!.GetValueOrDefault(chatTypeId, ChatParser.MessageType.CHAT);
Expand Down Expand Up @@ -909,12 +909,14 @@ private bool HandlePlayPackets(int packetId, Queue<byte> packetData)

var chatInfo =
Json.ParseJson(targetName ?? chatName).Properties;
var senderDisplayName =
(chatInfo.ContainsKey("insertion") ? chatInfo["insertion"] : (chatInfo.ContainsKey("text") ? chatInfo["text"] : ""))
.StringValue;
var senderDisplayName = chatInfo != null && chatInfo.Count > 0
? (chatInfo.ContainsKey("insertion") ? chatInfo["insertion"] : chatInfo["text"])
.StringValue
: "";
string? senderTeamName = null;
if (targetName != null &&
messageTypeEnum is ChatParser.MessageType.TEAM_MSG_COMMAND_INCOMING or ChatParser.MessageType.TEAM_MSG_COMMAND_OUTGOING)
messageTypeEnum is ChatParser.MessageType.TEAM_MSG_COMMAND_INCOMING
or ChatParser.MessageType.TEAM_MSG_COMMAND_OUTGOING)
senderTeamName = Json.ParseJson(targetName).Properties["with"].DataArray[0]
.Properties["text"].StringValue;

Expand Down Expand Up @@ -2571,9 +2573,6 @@ private bool HandlePlayPackets(int packetId, Queue<byte> packetData)
}

return true; //Packet processed
}catch(Exception exception){
exception.printStackTrace();
}
}

/// <summary>
Expand Down

0 comments on commit f325dd7

Please sign in to comment.