Skip to content

Commit

Permalink
Use collection initializers (IDE0028)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron2550 committed Nov 15, 2023
1 parent 9a56803 commit ff24a25
Show file tree
Hide file tree
Showing 66 changed files with 136 additions and 136 deletions.
14 changes: 7 additions & 7 deletions Obsidian.API/AI/AStarPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ internal class AStarPath

private readonly IWorld world;

private readonly List<Vector> validMoves = new()
{
private readonly List<Vector> validMoves =
[
Vector.Left,
Vector.Right,
Vector.Forwards,
Expand All @@ -43,7 +43,7 @@ internal class AStarPath
Vector.Backwards + Vector.Down,
Vector.Left + Vector.Down,
Vector.Right + Vector.Down,
};
];

public AStarPath(IWorld world)
{
Expand All @@ -58,11 +58,11 @@ public List<Vector> GetPath(Vector startPos, Vector targetPos)
// Out of range?
float distanceSquared = (targetPos - startPos).MagnitudeSquared();
if (distanceSquared > MaxRange * MaxRange)
return new List<Vector>();
return [];


List<Node> openList = new();
List<Node> closedList = new();
List<Node> openList = [];
List<Node> closedList = [];

openList.Add(startNode);

Expand Down Expand Up @@ -130,7 +130,7 @@ public List<Vector> GetPath(Vector startPos, Vector targetPos)
}
}

return new List<Vector>();
return [];
}

private bool IsValidMove(Vector curPos, Vector nextPos)
Expand Down
2 changes: 1 addition & 1 deletion Obsidian.API/Containers/BaseContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public abstract class BaseContainer : IEnumerable<ItemStack>

public Guid Uuid { get; } = Guid.NewGuid();

public List<IPlayer> Viewers { get; } = new();
public List<IPlayer> Viewers { get; } = [];

public ItemStack? this[int index] { get => this.items[index]; set => this.items[index] = value; }

Expand Down
4 changes: 2 additions & 2 deletions Obsidian.API/Crafting/Builders/CookingRecipeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public sealed class CookingRecipeBuilder : BaseRecipeBuilder<SmeltingRecipe>, II

private readonly SmeltingType type;

private Ingredient ingredient = new();
private Ingredient ingredient = [];

private float experience;

Expand Down Expand Up @@ -62,7 +62,7 @@ public override SmeltingRecipe Build()
Identifier = this.Identifier ?? throw new NullReferenceException("Recipe must have a name"),
Type = type,
Group = this.Group,
Result = this.Result != null ? new Ingredient { this.Result } : throw new NullReferenceException("Result is not set."),
Result = this.Result != null ? [this.Result] : throw new NullReferenceException("Result is not set."),
Ingredient = this.ingredient,
Experience = this.experience,
CookingTime = this.cookingTime,
Expand Down
4 changes: 2 additions & 2 deletions Obsidian.API/Crafting/Builders/CuttingRecipeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Obsidian.API.Crafting.Builders;

public sealed class CuttingRecipeBuilder : BaseRecipeBuilder<CuttingRecipe>, IIngredientRecipe<IOutputCountRecipe<CuttingRecipe>>, IOutputCountRecipe<CuttingRecipe>
{
private Ingredient ingredient = new();
private Ingredient ingredient = [];

public int Count { get; set; }

Expand Down Expand Up @@ -37,7 +37,7 @@ public override CuttingRecipe Build()
Identifier = this.Identifier ?? throw new NullReferenceException("Name must not be null"),
Type = CraftingType.Stonecutting,
Group = this.Group,
Result = this.Result != null ? new Ingredient { this.Result } : throw new NullReferenceException("Result is not set."),
Result = this.Result != null ? [this.Result] : throw new NullReferenceException("Result is not set."),
Ingredient = this.ingredient ?? throw new NullReferenceException("Ingredient must not be null"),
Count = this.Count
};
Expand Down
6 changes: 3 additions & 3 deletions Obsidian.API/Crafting/Builders/ShapedRecipeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ public sealed class ShapedRecipeBuilder : BaseRecipeBuilder<ShapedRecipe>, IPatt
{
private readonly CraftingBookCategory category;

private readonly List<string> pattern = new();
private readonly List<string> pattern = [];

private readonly Dictionary<char, Ingredient> key = new();
private readonly Dictionary<char, Ingredient> key = [];

private bool showNotification;

Expand Down Expand Up @@ -61,7 +61,7 @@ public override ShapedRecipe Build()
Identifier = this.Identifier ?? throw new NullReferenceException("Recipe must have a name"),
Type = CraftingType.CraftingShaped,
Group = this.Group,
Result = this.Result != null ? new Ingredient { this.Result } : throw new NullReferenceException("Result is not set."),
Result = this.Result != null ? [this.Result] : throw new NullReferenceException("Result is not set."),
Pattern = new ReadOnlyCollection<string>(new List<string>(this.pattern)),
Key = new ReadOnlyDictionary<char, Ingredient>(new Dictionary<char, Ingredient>(this.key)),
Category = this.category,
Expand Down
4 changes: 2 additions & 2 deletions Obsidian.API/Crafting/Builders/ShapelessRecipeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public sealed class ShapelessRecipeBuilder : BaseRecipeBuilder<ShapelessRecipe>,
{
private readonly CraftingBookCategory category;

private readonly List<Ingredient> ingredients = new();
private readonly List<Ingredient> ingredients = [];

private ShapelessRecipeBuilder(CraftingBookCategory category) => this.category = category;

Expand All @@ -31,7 +31,7 @@ public override ShapelessRecipe Build()
Identifier = this.Identifier ?? throw new NullReferenceException("Recipe must have a name"),
Type = CraftingType.CraftingShapeless,
Group = this.Group,
Result = this.Result != null ? new Ingredient { this.Result } : throw new NullReferenceException("Result is not set."),
Result = this.Result != null ? [this.Result] : throw new NullReferenceException("Result is not set."),
Ingredients = new ReadOnlyCollection<Ingredient>(new List<Ingredient>(this.ingredients)),
Category = this.category
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ public sealed class SmithingTransformRecipeBuilder : BaseRecipeBuilder<SmithingT
IUpgradeIngredientRecipe<SmithingTransformRecipe>,
ITemplateIngredientRecipe<SmithingTransformRecipe>
{
private Ingredient @base = new();
private Ingredient addition = new();
private Ingredient template = new();
private Ingredient @base = [];
private Ingredient addition = [];
private Ingredient template = [];

private SmithingTransformRecipeBuilder() { }

Expand Down Expand Up @@ -55,7 +55,7 @@ public override SmithingTransformRecipe Build()
Base = this.@base,
Addition = this.addition,
Template = template,
Result = this.Result != null ? new Ingredient { this.Result } : throw new NullReferenceException("Result is not set.")
Result = this.Result != null ? [this.Result] : throw new NullReferenceException("Result is not set.")
};
}
}
2 changes: 1 addition & 1 deletion Obsidian.API/Crafting/Ingredient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class Ingredient : IEnumerable<ItemStack>

public Ingredient()
{
this.items = new List<ItemStack>();
this.items = [];
}

public void Add(ItemStack item) => this.items.Add(item);
Expand Down
6 changes: 3 additions & 3 deletions Obsidian.API/_Types/ChatMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,15 @@ public static string ReformatAmpersandPrefixes(string originalText)

public ChatMessage AddChatComponent(ChatMessage message)
{
this.With ??= new();
this.With ??= [];
this.With.Add(message);

return this;
}

public ChatMessage AddChatComponent(IEnumerable<ChatMessage> message)
{
this.With ??= new();
this.With ??= [];
this.With.AddRange(message);

return this;
Expand All @@ -188,7 +188,7 @@ public ChatMessage AddChatComponent(IEnumerable<ChatMessage> message)

public ChatMessage AddExtra(ChatMessage message)
{
Extra ??= new List<ChatMessage>();
Extra ??= [];
Extra.Add(message);

return this;
Expand Down
8 changes: 4 additions & 4 deletions Obsidian.API/_Types/Inventory/ItemMetaBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ public class ItemMetaBuilder

public IReadOnlyList<ChatMessage> Lore { get; }

private readonly Dictionary<EnchantmentType, Enchantment> enchantments = new Dictionary<EnchantmentType, Enchantment>();
private readonly Dictionary<EnchantmentType, Enchantment> storedEnchantments = new Dictionary<EnchantmentType, Enchantment>();
private readonly Dictionary<EnchantmentType, Enchantment> enchantments = [];
private readonly Dictionary<EnchantmentType, Enchantment> storedEnchantments = [];

private readonly List<string> canDestroy = new List<string>();
private readonly List<string> canDestroy = [];

private readonly List<ChatMessage> lore = new List<ChatMessage>();
private readonly List<ChatMessage> lore = [];

public ItemMetaBuilder()
{
Expand Down
2 changes: 1 addition & 1 deletion Obsidian.API/_Types/Traversal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private static float Frac1(float x)
public List<VectorF> Run()
{

List<VectorF> blocks = new List<VectorF>();
List<VectorF> blocks = [];

float tMaxX, tMaxY, tMaxZ, tDeltaX, tDeltaY, tDeltaZ;
VectorF voxel = new VectorF();
Expand Down
2 changes: 1 addition & 1 deletion Obsidian.Nbt/NbtCompound.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Obsidian.Nbt;

public class NbtCompound : INbtTag, IEnumerable<KeyValuePair<string, INbtTag>>
{
private readonly Dictionary<string, INbtTag> children = new();
private readonly Dictionary<string, INbtTag> children = [];

public int Count => this.children.Count;

Expand Down
2 changes: 1 addition & 1 deletion Obsidian.Nbt/NbtList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Obsidian.Nbt;

public class NbtList : INbtTag, IList<INbtTag>
{
private readonly List<INbtTag> baseList = new();
private readonly List<INbtTag> baseList = [];

public int Count => this.baseList.Count;

Expand Down
4 changes: 2 additions & 2 deletions Obsidian.SourceGenerators/Packets/MethodsRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ internal sealed class MethodsRegistry
public IReadOnlyList<Method> WriteMethods => writeMethods;
public IReadOnlyList<Method> ReadMethods => readMethods;

private readonly List<Method> writeMethods = new();
private readonly List<Method> readMethods = new();
private readonly List<Method> writeMethods = [];
private readonly List<Method> readMethods = [];

public bool TryGetWriteMethod(Property property, out Method method)
{
Expand Down
2 changes: 1 addition & 1 deletion Obsidian.SourceGenerators/Registry/Models/BlockProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal class BlockProperty
private const string BooleanName = "bool";
private const string IntegerName = "int";

internal static Dictionary<string, string[]> enumValuesCache = new();
internal static Dictionary<string, string[]> enumValuesCache = [];

private BlockProperty(string name, string tag, string type, string[] values, int? customOffset = null, bool isBooleanToggled = true)
{
Expand Down
2 changes: 1 addition & 1 deletion Obsidian.SourceGenerators/Registry/Models/Codec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal sealed class Codec : IHasName, IRegistryItem

public int RegistryId { get; }

public Dictionary<string, JsonElement> Properties { get; set; } = new();
public Dictionary<string, JsonElement> Properties { get; set; } = [];

public Codec(string name, int registryId)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal static class Customizations

static Customizations()
{
BannedNames = new();
BannedNames = [];
foreach (Type type in typeof(int).Assembly.GetTypes())
{
BannedNames.Add(type.Name);
Expand Down
2 changes: 1 addition & 1 deletion Obsidian.SourceGenerators/Registry/Models/Tag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static Tag Get(JsonProperty property, Dictionary<string, ITaggable> tagga
private static void UpdateMissedTags(string propertyName, string valueTag, Dictionary<string, List<string>> missedTags)
{
if (!missedTags.ContainsKey(propertyName))
missedTags.Add(propertyName, new() { valueTag });
missedTags.Add(propertyName, [valueTag]);
else
missedTags[propertyName].Add(valueTag);
}
Expand Down
4 changes: 2 additions & 2 deletions Obsidian/Blocks/BlockMetaBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public class BlockMetaBuilder

public IReadOnlyList<string> CanPlaceOn { get; }

private readonly List<string> canPlaceOn = new List<string>();
private readonly List<string> canPlaceOn = [];

private readonly List<ChatMessage> lore = new List<ChatMessage>();
private readonly List<ChatMessage> lore = [];

public BlockMetaBuilder()
{
Expand Down
2 changes: 1 addition & 1 deletion Obsidian/BossBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class BossBar : IBossBar
private Server server;

private BossBarRemoveAction removeAction;
public HashSet<Guid> Players { get; } = new();
public HashSet<Guid> Players { get; } = [];

public Guid Uuid { get; } = Guid.NewGuid();

Expand Down
6 changes: 3 additions & 3 deletions Obsidian/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,13 @@ public Client(ConnectionContext connectionContext, ServerConfiguration config, i
id = playerId;
Server = originServer;

LoadedChunks = new();
LoadedChunks = [];
packetCryptography = new();
handler = new(config);
networkStream = new(connectionContext.Transport);
minecraftStream = new(networkStream);

missedKeepAlives = new List<long>();
missedKeepAlives = [];
var linkOptions = new DataflowLinkOptions { PropagateCompletion = true };
var blockOptions = new ExecutionDataflowBlockOptions { CancellationToken = cancellationSource.Token, EnsureOrdered = true };
var sendPacketBlock = new ActionBlock<IClientboundPacket>(packet =>
Expand Down Expand Up @@ -634,7 +634,7 @@ internal void SendKeepAlive(DateTimeOffset time)

internal Task RemovePlayerFromListAsync(IPlayer player) => QueuePacketAsync(new PlayerInfoRemovePacket
{
UUIDs = new() { player.Uuid }
UUIDs = [player.Uuid]
});

internal async Task AddPlayerToListAsync(IPlayer player)
Expand Down
2 changes: 1 addition & 1 deletion Obsidian/Commands/CommandNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class CommandNode

public CommandNodeType Type { get; set; }

public HashSet<CommandNode> Children = new();
public HashSet<CommandNode> Children = [];

public async Task CopyToAsync(MinecraftStream stream)
{
Expand Down
4 changes: 2 additions & 2 deletions Obsidian/Commands/Framework/CommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public class CommandHandler
public CommandHandler()
{
_commandParser = new CommandParser(DefaultPrefix);
_commands = new List<Command>();
_argumentParsers = new List<BaseArgumentParser>();
_commands = [];
_argumentParsers = [];
_prefix = DefaultPrefix;

// Find all predefined argument parsers
Expand Down
2 changes: 1 addition & 1 deletion Obsidian/Commands/Framework/Entities/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public Command(string name, string[] aliases, string description, string usage,
Plugin = plugin;
ParentType = parentType;
AllowedIssuers = allowedIssuers;
Overloads = new List<MethodInfo>();
Overloads = [];
}

public bool CheckCommand(string[] input, Command? parent)
Expand Down
2 changes: 1 addition & 1 deletion Obsidian/Entities/FallingBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public sealed partial class FallingBlock : Entity

private readonly float windResFactor = 0.98F;

private HashSet<Vector> checkedBlocks = new();
private HashSet<Vector> checkedBlocks = [];

public FallingBlock(VectorF position) : base()
{
Expand Down
6 changes: 3 additions & 3 deletions Obsidian/Entities/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public sealed partial class Player : Living, IPlayer
/// </summary>
protected ILogger Logger { get; private set; }

internal HashSet<int> visiblePlayers = new();
internal HashSet<int> visiblePlayers = [];

//TODO: better name??
internal short inventorySlot = 36;
Expand All @@ -55,7 +55,7 @@ public sealed partial class Player : Living, IPlayer

public BaseContainer? OpenedContainer { get; set; }

public List<SkinProperty> SkinProperties { get; set; } = new();
public List<SkinProperty> SkinProperties { get; set; } = [];

public Vector? LastDeathLocation { get; set; }

Expand Down Expand Up @@ -954,7 +954,7 @@ internal async Task<bool> UpdateChunksAsync(bool unloadAll = false, int distance
client.LoadedChunks.Clear();
}

List<(int X, int Z)> clientNeededChunks = new();
List<(int X, int Z)> clientNeededChunks = [];
List<(int X, int Z)> clientUnneededChunks = new(client.LoadedChunks);

(int playerChunkX, int playerChunkZ) = Position.ToChunkCoord();
Expand Down
2 changes: 1 addition & 1 deletion Obsidian/Events/AsyncEvent.T.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public sealed class AsyncEvent<T> : IEventRegistry
public string? Name { get; } // Name must be set in order to be visible to plugins

private readonly SemaphoreSlim semaphore = new(1);
private readonly List<Hook<T>> hooks = new();
private readonly List<Hook<T>> hooks = [];
private readonly Action<AsyncEvent<T>, Exception>? exceptionHandler;

public AsyncEvent()
Expand Down
Loading

0 comments on commit ff24a25

Please sign in to comment.