refactor: use pattern matching for null checks (is null / is not null)

Convert remaining == null to is null and != null to is not null
across 17 files in CommandHandler/ArgumentType, StructuredComponents,
and DeclareCommands for idiomatic C# style.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-03-24 00:47:03 +00:00
parent c7bc25aa17
commit 94bf42710a
17 changed files with 33 additions and 33 deletions

View file

@ -17,7 +17,7 @@ namespace MinecraftClient.CommandHandler.ArgumentType
public override Task<Suggestions> ListSuggestions<TSource>(CommandContext<TSource> context, SuggestionsBuilder builder)
{
McClient? client = CmdResult.currentHandler;
if (client != null)
if (client is not null)
{
var botList = client.GetLoadedChatBots();
foreach (var bot in botList)

View file

@ -18,10 +18,10 @@ namespace MinecraftClient.CommandHandler.ArgumentType
public override Task<Suggestions> ListSuggestions<TSource>(CommandContext<TSource> context, SuggestionsBuilder builder)
{
McClient? client = CmdResult.currentHandler;
if (client != null)
if (client is not null)
{
Inventory.Container? inventory = client.GetInventory(0);
if (inventory != null)
if (inventory is not null)
{
for (int i = 1; i <= 9; ++i)
{

View file

@ -18,7 +18,7 @@ namespace MinecraftClient.CommandHandler.ArgumentType
public override Task<Suggestions> ListSuggestions<TSource>(CommandContext<TSource> context, SuggestionsBuilder builder)
{
McClient? client = CmdResult.currentHandler;
if (client != null)
if (client is not null)
{
var invList = client.GetInventories();
foreach (var inv in invList)

View file

@ -19,7 +19,7 @@ namespace MinecraftClient.CommandHandler.ArgumentType
public override Task<Suggestions> ListSuggestions<TSource>(CommandContext<TSource> context, SuggestionsBuilder builder)
{
McClient? client = CmdResult.currentHandler;
if (client != null && context.Nodes.Count >= 2)
if (client is not null && context.Nodes.Count >= 2)
{
string invName = context.Nodes[1].Range.Get(builder.Input);
if (!int.TryParse(invName, out int invId))
@ -33,11 +33,11 @@ namespace MinecraftClient.CommandHandler.ArgumentType
};
Inventory.Container? inventory = client.GetInventory(invId);
if (inventory != null)
if (inventory is not null)
{
foreach ((int slot, Inventory.Item item) in inventory.Items)
{
if (item != null && item.Count > 0)
if (item is not null && item.Count > 0)
{
string slotStr = slot.ToString();
if (slotStr.StartsWith(builder.RemainingLowerCase, StringComparison.InvariantCultureIgnoreCase))

View file

@ -19,10 +19,10 @@ namespace MinecraftClient.CommandHandler.ArgumentType
public override Task<Suggestions> ListSuggestions<TSource>(CommandContext<TSource> context, SuggestionsBuilder builder)
{
McClient? client = CmdResult.currentHandler;
if (client != null)
if (client is not null)
{
var bot = (Map?)client.GetLoadedChatBots().Find(bot => bot.GetType().Name == "Map");
if (bot != null)
if (bot is not null)
{
var mapList = bot.cachedMaps;
foreach (var map in mapList)

View file

@ -19,7 +19,7 @@ namespace MinecraftClient.CommandHandler.ArgumentType
public override Task<Suggestions> ListSuggestions<TSource>(CommandContext<TSource> context, SuggestionsBuilder builder)
{
McClient? client = CmdResult.currentHandler;
if (client != null)
if (client is not null)
{
var entityList = client.GetEntities().Values.ToList();
foreach (var entity in entityList)

View file

@ -235,7 +235,7 @@ namespace MinecraftClient.Protocol.Handlers.packet.s2c
return false;
List<Tuple<string, string>> currentArguments = signedArguments;
if (signedCapture != null)
if (signedCapture is not null)
{
currentArguments = new List<Tuple<string, string>>(signedArguments.Count + 1);
currentArguments.AddRange(signedArguments);
@ -317,7 +317,7 @@ namespace MinecraftClient.Protocol.Handlers.packet.s2c
case CommandNodeKind.Literal:
return TryConsumeLiteral(command, position, node.Name!, out nextPosition);
case CommandNodeKind.Argument:
if (node.Argument == null || !TryConsumeArgument(command, position, node.Argument.Value, out nextPosition))
if (node.Argument is null || !TryConsumeArgument(command, position, node.Argument.Value, out nextPosition))
return false;
if (node.Argument.Value.IsSigned)
@ -585,7 +585,7 @@ namespace MinecraftClient.Protocol.Handlers.packet.s2c
};
}
if (name == null)
if (name is null)
{
layout = s_unknownLegacyArgumentType;
return true;

View file

@ -17,7 +17,7 @@ public class BundleContentsComponent(DataTypes dataTypes, ItemPalette itemPalett
for (var i = 0; i < count; i++)
{
var item = dataTypes.ReadNextItemSlot(data, itemPalette);
if (item != null)
if (item is not null)
Items.Add(item);
}
}

View file

@ -17,7 +17,7 @@ public class ChargedProjectilesComponent(DataTypes dataTypes, ItemPalette itemPa
for (var i = 0; i < count; i++)
{
var item = dataTypes.ReadNextItemSlot(data, itemPalette);
if (item != null)
if (item is not null)
Items.Add(item);
}
}

View file

@ -114,7 +114,7 @@ public class ConsumableComponent(DataTypes dataTypes, ItemPalette itemPalette, S
var data = new List<byte>();
data.AddRange(DataTypes.GetFloat(ConsumeSeconds));
data.AddRange(DataTypes.GetVarInt(Animation));
if (Sound != null) data.AddRange(Sound.Serialize());
if (Sound is not null) data.AddRange(Sound.Serialize());
data.AddRange(DataTypes.GetBool(HasConsumeParticles));
data.AddRange(DataTypes.GetVarInt(Effects.Count));
foreach (var effect in Effects)

View file

@ -61,25 +61,25 @@ public class EquippableComponent(DataTypes dataTypes, ItemPalette itemPalette, S
{
var data = new List<byte>();
data.AddRange(DataTypes.GetVarInt(Slot));
if (EquipSound != null) data.AddRange(EquipSound.Serialize());
if (EquipSound is not null) data.AddRange(EquipSound.Serialize());
data.AddRange(DataTypes.GetBool(HasModel));
if (HasModel && Model != null)
if (HasModel && Model is not null)
data.AddRange(DataTypes.GetString(Model));
data.AddRange(DataTypes.GetBool(HasCameraOverlay));
if (HasCameraOverlay && CameraOverlay != null)
if (HasCameraOverlay && CameraOverlay is not null)
data.AddRange(DataTypes.GetString(CameraOverlay));
data.AddRange(DataTypes.GetBool(HasAllowedEntities));
if (HasAllowedEntities)
{
data.AddRange(DataTypes.GetVarInt(AllowedEntitiesType));
if (AllowedEntitiesType == 0 && AllowedEntitiesTag != null)
if (AllowedEntitiesType == 0 && AllowedEntitiesTag is not null)
{
data.AddRange(DataTypes.GetString(AllowedEntitiesTag));
}
else if (AllowedEntitiesIds != null)
else if (AllowedEntitiesIds is not null)
{
foreach (var id in AllowedEntitiesIds)
data.AddRange(DataTypes.GetVarInt(id));

View file

@ -30,11 +30,11 @@ public class RepairableComponent(DataTypes dataTypes, ItemPalette itemPalette, S
{
var data = new List<byte>();
data.AddRange(DataTypes.GetVarInt(Type));
if (Type == 0 && TagName != null)
if (Type == 0 && TagName is not null)
{
data.AddRange(DataTypes.GetString(TagName));
}
else if (ItemIds != null)
else if (ItemIds is not null)
{
foreach (var id in ItemIds)
data.AddRange(DataTypes.GetVarInt(id));

View file

@ -24,7 +24,7 @@ public class UseCooldownComponent(DataTypes dataTypes, ItemPalette itemPalette,
var data = new List<byte>();
data.AddRange(DataTypes.GetFloat(Seconds));
data.AddRange(DataTypes.GetBool(HasCooldownGroup));
if (HasCooldownGroup && CooldownGroup != null)
if (HasCooldownGroup && CooldownGroup is not null)
data.AddRange(DataTypes.GetString(CooldownGroup));
return new Queue<byte>(data);
}

View file

@ -44,7 +44,7 @@ public class BlockPredicateSubcomponent(DataTypes dataTypes, SubComponentRegistr
data.AddRange(DataTypes.GetBool(HasBlocks));
if (HasBlocks)
{
if(BlockSet == null)
if(BlockSet is null)
throw new ArgumentNullException($"Can not serialize a BlockPredicate when the BlockSet is empty but HasBlocks is true!");
data.AddRange(BlockSet.Serialize());
@ -54,7 +54,7 @@ public class BlockPredicateSubcomponent(DataTypes dataTypes, SubComponentRegistr
data.AddRange(DataTypes.GetBool(HasProperities));
if (HasProperities)
{
if(Properties == null || Properties.Count == 0)
if(Properties is null || Properties.Count == 0)
throw new ArgumentNullException($"Can not serialize a BlockPredicate when the Properties is empty but HasProperties is true!");
data.AddRange(DataTypes.GetVarInt(Properties.Count));
@ -66,7 +66,7 @@ public class BlockPredicateSubcomponent(DataTypes dataTypes, SubComponentRegistr
data.AddRange(DataTypes.GetBool(HasNbt));
if (HasNbt)
{
if(Nbt == null)
if(Nbt is null)
throw new ArgumentNullException($"Can not serialize a BlockPredicate when the Nbt is empty but HasNbt is true!");
data.AddRange(DataTypes.GetNbt(Nbt));

View file

@ -39,7 +39,7 @@ public class BlockSetSubcomponent(DataTypes dataTypes, SubComponentRegistry subC
if (Type == 0) return new Queue<byte>(data);
if(BlockIds == null || BlockIds.Count == 0)
if(BlockIds is null || BlockIds.Count == 0)
throw new ArgumentNullException($"Can not serialize an empty list of Block IDs in a Block Set when the type is not 0!");
for(var i = 0; i < Type - 1; i++)

View file

@ -47,12 +47,12 @@ public class PropertySubComponent(DataTypes dataTypes, SubComponentRegistry subC
}
else
{
data.AddRange(DataTypes.GetBool(MinValue != null));
if (MinValue != null)
data.AddRange(DataTypes.GetBool(MinValue is not null));
if (MinValue is not null)
data.AddRange(DataTypes.GetString(MinValue));
data.AddRange(DataTypes.GetBool(MaxValue != null));
if (MaxValue != null)
data.AddRange(DataTypes.GetBool(MaxValue is not null));
if (MaxValue is not null)
data.AddRange(DataTypes.GetString(MaxValue));
}

View file

@ -31,7 +31,7 @@ public abstract class SubComponentRegistry(DataTypes dataTypes)
var parseMethod = instance.GetType().GetMethod("Parse", BindingFlags.Instance | BindingFlags.NonPublic);
if (parseMethod == null)
if (parseMethod is null)
throw new InvalidOperationException($"Sub component parser type {subComponentParserType.Name} does not have a Parse method.");
parseMethod.Invoke(instance, new object[] { data });