Modernize null-check patterns: use 'is null' and 'is not null'

Replace '== null' with 'is null' and '!= null' with 'is not null'
across 19 core files following modern C# pattern matching conventions.

Only literal null comparisons are changed. Assignments, value
comparisons, and LINQ expressions are left untouched.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-03-24 00:27:07 +00:00
parent 902e944cbb
commit c5df6a49c6
19 changed files with 111 additions and 111 deletions

View file

@ -1350,7 +1350,7 @@ namespace MinecraftClient.Protocol.Handlers
/// <returns>Byte array for this NBT tag</returns>
private byte[] GetNbt(Dictionary<string, object>? nbt, bool root)
{
if (nbt == null || nbt.Count == 0)
if (nbt is null || nbt.Count == 0)
return new byte[] { 0 }; // TAG_End
List<byte> bytes = new();
@ -1699,7 +1699,7 @@ namespace MinecraftClient.Protocol.Handlers
{
List<byte> slotData = new();
if (item == null || item.IsEmpty)
if (item is null || item.IsEmpty)
{
slotData.AddRange(GetBool(false));
}
@ -1727,7 +1727,7 @@ namespace MinecraftClient.Protocol.Handlers
if (protocolversion >= Protocol18Handler.MC_1_20_6_Version)
{
if (item == null || item.IsEmpty)
if (item is null || item.IsEmpty)
{
slotData.AddRange(GetVarInt(0));
}
@ -1736,7 +1736,7 @@ namespace MinecraftClient.Protocol.Handlers
slotData.AddRange(GetVarInt(item.Count));
slotData.AddRange(GetVarInt(itemPalette.ToId(item.Type)));
if (item.Components != null && item.Components.Count > 0)
if (item.Components is not null && item.Components.Count > 0)
{
slotData.AddRange(GetVarInt(item.Components.Count));
slotData.AddRange(GetVarInt(0)); // components to remove
@ -1756,7 +1756,7 @@ namespace MinecraftClient.Protocol.Handlers
}
else if (protocolversion > Protocol18Handler.MC_1_13_Version)
{
if (item == null || item.IsEmpty)
if (item is null || item.IsEmpty)
slotData.AddRange(GetBool(false));
else
{
@ -1768,7 +1768,7 @@ namespace MinecraftClient.Protocol.Handlers
}
else
{
if (item == null || item.IsEmpty)
if (item is null || item.IsEmpty)
slotData.AddRange(GetShort(-1));
else
{
@ -1849,7 +1849,7 @@ namespace MinecraftClient.Protocol.Handlers
/// <returns>String representation</returns>
public string ByteArrayToString(byte[]? bytes)
{
if (bytes == null)
if (bytes is null)
return "null";
else
return BitConverter.ToString(bytes).Replace("-", " ");
@ -1890,7 +1890,7 @@ namespace MinecraftClient.Protocol.Handlers
{
List<byte> fields = new();
fields.AddRange(GetLastSeenMessageList(ack.lastSeen, isOnlineMode));
if (!isOnlineMode || ack.lastReceived == null)
if (!isOnlineMode || ack.lastReceived is null)
fields.AddRange(GetBool(false)); // Has last received message
else
{

View file

@ -123,7 +123,7 @@ namespace MinecraftClient.Protocol.Message
{
string sender = message.isSenderJson ? ParseText(message.displayName!) : message.displayName!;
string content;
if (Config.Signature.ShowModifiedChat && message.unsignedContent != null)
if (Config.Signature.ShowModifiedChat && message.unsignedContent is not null)
{
content = ParseText(message.unsignedContent!);
if (string.IsNullOrEmpty(content))
@ -315,7 +315,7 @@ namespace MinecraftClient.Protocol.Message
Task<Dictionary<string, string>?> fetckFileTask =
httpClient.GetFromJsonAsync<Dictionary<string, string>>(translation_file_location);
fetckFileTask.Wait();
if (fetckFileTask.Result != null && fetckFileTask.Result.Count > 0)
if (fetckFileTask.Result is not null && fetckFileTask.Result.Count > 0)
{
TranslationRules = fetckFileTask.Result;
TranslationRules["Version"] = TranslationsFile_Version;

View file

@ -44,13 +44,13 @@ namespace MinecraftClient.Protocol
{
Uuid = uuid;
Name = name;
if (property != null)
if (property is not null)
Property = property;
Gamemode = gamemode;
Ping = ping;
DisplayName = displayName;
lastMessageVerified = false;
if (timeStamp != null && publicKey != null && signature != null)
if (timeStamp is not null && publicKey is not null && signature is not null)
{
DateTimeOffset dateTimeOffset = DateTimeOffset.FromUnixTimeMilliseconds((long)timeStamp);
KeyExpiresAt = dateTimeOffset.UtcDateTime;
@ -119,7 +119,7 @@ namespace MinecraftClient.Protocol
/// <returns>Is this message vaild</returns>
public bool VerifyMessage(string message, long timestamp, long salt, ref byte[] signature)
{
if (PublicKey == null || IsKeyExpired())
if (PublicKey is null || IsKeyExpired())
return false;
else
{
@ -146,12 +146,12 @@ namespace MinecraftClient.Protocol
{
if (lastMessageVerified == false)
return false;
if (PublicKey == null || IsKeyExpired() || (this.precedingSignature != null && precedingSignature == null))
if (PublicKey is null || IsKeyExpired() || (this.precedingSignature is not null && precedingSignature is null))
{
lastMessageVerified = false;
return false;
}
if (this.precedingSignature != null && !this.precedingSignature.SequenceEqual(precedingSignature!))
if (this.precedingSignature is not null && !this.precedingSignature.SequenceEqual(precedingSignature!))
{
lastMessageVerified = false;
return false;
@ -181,12 +181,12 @@ namespace MinecraftClient.Protocol
{
if (lastMessageVerified == false)
return false;
if (PublicKey == null || IsKeyExpired() || (this.precedingSignature != null && precedingSignature == null))
if (PublicKey is null || IsKeyExpired() || (this.precedingSignature is not null && precedingSignature is null))
{
lastMessageVerified = false;
return false;
}
if (this.precedingSignature != null && !this.precedingSignature.SequenceEqual(precedingSignature!))
if (this.precedingSignature is not null && !this.precedingSignature.SequenceEqual(precedingSignature!))
{
lastMessageVerified = false;
return false;
@ -212,7 +212,7 @@ namespace MinecraftClient.Protocol
/// <returns>Is this message chain vaild</returns>
public bool VerifyMessage(string message, Guid playerUuid, Guid chatUuid, int messageIndex, long timestamp, long salt, ref byte[] signature, Tuple<int, byte[]?>[] previousMessageSignatures)
{
if (PublicKey == null || IsKeyExpired())
if (PublicKey is null || IsKeyExpired())
return false;
// net.minecraft.server.network.ServerPlayNetworkHandler#validateMessage

View file

@ -925,7 +925,7 @@ namespace MinecraftClient.Protocol
int code = DoHTTPSPost("authserver.mojang.com", 443, "/refresh", json_request, ref result);
if (code == 200)
{
if (result == null)
if (result is null)
{
return LoginResult.NullError;
}
@ -976,7 +976,7 @@ namespace MinecraftClient.Protocol
Config.Main.General.AuthServer.UseHttps, ref result);
if (code == 200)
{
if (result == null)
if (result is null)
{
return LoginResult.NullError;
}
@ -1251,7 +1251,7 @@ namespace MinecraftClient.Protocol
contentType = header.Value;
}
if (body != null)
if (body is not null)
request.Content = new StringContent(body, Encoding.UTF8, contentType);
if (Settings.Config.Logging.DebugMessages)
@ -1279,9 +1279,9 @@ namespace MinecraftClient.Protocol
}
}
}, TimeSpan.FromSeconds(30));
if (postResult != null)
if (postResult is not null)
result = postResult;
if (exception != null)
if (exception is not null)
throw exception;
return statusCode;
}