Skip to content

Commit f15b403

Browse files
committed
Implement nullable reference types.
1 parent a9274c3 commit f15b403

File tree

104 files changed

+580
-442
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+580
-442
lines changed

NWN.Toolbox/src/Core/Config/Config.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@ internal sealed class Config
1111
public int Version { get; set; } = 1;
1212

1313
[Description("ChatCommands is a module that provides a system of implementing chat commands in C#. It automatically handles command argument parsing, help lists and more.")]
14-
public ChatCommandConfig ChatCommands { get; set; } = new ChatCommandConfig();
14+
public ChatCommandConfig? ChatCommands { get; set; } = new ChatCommandConfig();
1515

1616
[Description("ServerRestart is a module that automatically shutdowns the server after a period of time. A custom start script, or service like docker is required to automatically start the server again after shutdown.")]
17-
public ServerRestartConfig ServerRestart { get; set; } = new ServerRestartConfig();
17+
public ServerRestartConfig? ServerRestart { get; set; } = new ServerRestartConfig();
1818

1919
[Description("ToolboxWindows is a module that adds a number of utility windows and tools for improved DM functionality, server administration and more.")]
20-
public WindowConfig ToolboxWindows { get; set; } = new WindowConfig();
20+
public WindowConfig? ToolboxWindows { get; set; } = new WindowConfig();
2121

2222
[Description("Permissions is a module that allows server admins to control what tools and features players/DMs can use by creating groups and assigning permissions.")]
23-
public PermissionsConfig Permissions { get; set; } = new PermissionsConfig();
23+
public PermissionsConfig? Permissions { get; set; } = new PermissionsConfig();
2424

2525
[Description("VersionCheck is a module that defines client version requirements to connect to the server (e.g. for NUI).")]
26-
public VersionCheckConfig VersionCheck { get; set; } = new VersionCheckConfig();
26+
public VersionCheckConfig? VersionCheck { get; set; } = new VersionCheckConfig();
2727

2828
[Description("Languages is a module that allows characters to speak in different languages.")]
29-
public LanguageConfig Languages { get; set; } = new LanguageConfig();
29+
public LanguageConfig? Languages { get; set; } = new LanguageConfig();
3030
}
3131
}

NWN.Toolbox/src/Core/Config/ConfigService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public ConfigService(PluginStorageService pluginStorageService)
5757

5858
public void SaveConfig<T>(string fileName, T instance)
5959
{
60+
ArgumentNullException.ThrowIfNull(instance, nameof(instance));
6061
string yaml = serializer.Serialize(instance);
6162
File.WriteAllText(GetConfigPath(fileName), yaml);
6263
}

NWN.Toolbox/src/Core/Config/Features/ChatCommandConfig.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ internal sealed class ChatCommandConfig : IFeatureConfig
1111
public bool Enabled { get; set; } = true;
1212

1313
[Description("Character prefixes that define if a message is detected as a command.")]
14-
public List<string> CommandPrefixes { get; set; } = new List<string> { "/" };
14+
public List<string>? CommandPrefixes { get; set; } = new List<string> { "/" };
1515

1616
[Description("A list of words/prefixes that are ignored by command processing. E.g. '/' ignores all usages of '//' if the command prefix is /.")]
17-
public List<string> IgnoreCommands { get; set; } = new List<string> { "/" };
17+
public List<string>? IgnoreCommands { get; set; } = new List<string> { "/" };
1818
}
1919
}

NWN.Toolbox/src/Core/Config/Features/FeatureConfigExtensions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
13
namespace Jorteck.Toolbox.Core
24
{
35
internal static class FeatureConfigExtensions
46
{
5-
public static bool IsEnabled(this IFeatureConfig config)
7+
public static bool IsEnabled([NotNullWhen(true)] this IFeatureConfig? config)
68
{
79
return config != null && config.Enabled;
810
}

NWN.Toolbox/src/Core/Config/Features/PermissionsConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ internal sealed class PermissionsConfig : IFeatureConfig
1313
public bool ChatCommandEnable { get; set; } = true;
1414

1515
[Description("The base chat command name.")]
16-
public string ChatCommand { get; set; } = "perms";
16+
public string? ChatCommand { get; set; } = "perms";
1717
}
1818
}

NWN.Toolbox/src/Core/Config/Features/ServerRestartConfig.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ internal sealed class ServerRestartConfig : IFeatureConfig
1717
public uint RestartTimeSecs { get; set; } = 44 * 60 * 60;
1818

1919
[Description("Defines a restart schedule using a cron expression: https://crontab.guru/\n # If defined, overrides restart_time_secs.")]
20-
public string RestartTimeCron { get; set; } = "";
20+
public string? RestartTimeCron { get; set; } = "";
2121

2222
[Description("The periods at which restart timer warnings are broadcasted to all players.")]
23-
public List<uint> RestartWarningSecs { get; set; } = new List<uint> { 0, 60, 300, 1800, 3600, 14400 };
23+
public List<uint>? RestartWarningSecs { get; set; } = new List<uint> { 0, 60, 300, 1800, 3600, 14400 };
2424

2525
[Description("The boot message shown to players when the server is restarting.")]
26-
public string BootMessage { get; set; } = "The server is restarting.";
26+
public string? BootMessage { get; set; } = "The server is restarting.";
2727

2828
[Description("The warning message shown to players at each restart_warning_secs period.")]
29-
public string WarnMessage { get; set; } = "The server will restart in <time>.";
29+
public string? WarnMessage { get; set; } = "The server will restart in <time>.";
3030

3131
[Description("The warning message shown to players when server restart is imminent.")]
32-
public string WarnMessageNow { get; set; } = "The server is restarting now!";
32+
public string? WarnMessageNow { get; set; } = "The server is restarting now!";
3333
}
3434
}

NWN.Toolbox/src/Core/Config/Features/VersionCheckConfig.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ internal sealed class VersionCheckConfig : IFeatureConfig
1010
public bool Enabled { get; set; } = false;
1111

1212
[Description("The minimum version for the server. Clients who are below the version will be kicked when they attempt to connect.")]
13-
public Version MinimumVersion { get; set; } = new Version
13+
public Version? MinimumVersion { get; set; } = new Version
1414
{
1515
MajorVersion = 8193,
1616
MinorVersion = 30,
1717
};
1818

1919
[Description("The recommended version for the server. Clients who are below the recommended version will see a warning message after they connect to the server.")]
20-
public Version RecommendedVersion { get; set; } = new Version
20+
public Version? RecommendedVersion { get; set; } = new Version
2121
{
2222
MajorVersion = 8193,
2323
MinorVersion = 34,

NWN.Toolbox/src/Core/Config/Features/WindowConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ internal sealed class WindowConfig
1818
public ListMode ListMode { get; set; } = ListMode.Blacklist;
1919

2020
[Description("The list of windows to use as the whitelist/blacklist. Dependant on list_mode.")]
21-
public List<string> Windows { get; set; } = new List<string>();
21+
public List<string>? Windows { get; set; } = new List<string>();
2222
}
2323

2424
internal enum ListMode

NWN.Toolbox/src/Core/Data/DatabaseDesignFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ internal sealed class DatabaseDesignFactory : IDesignTimeDbContextFactory<Databa
88
{
99
public Database CreateDbContext(string[] args)
1010
{
11-
string directoryPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
11+
string directoryPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!;
1212
string path = Path.Combine(directoryPath!, "toolbox-design-data.db");
1313
return new Database($"Data Source={path}");
1414
}

NWN.Toolbox/src/Core/Data/Models/EncounterModel.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ namespace Jorteck.Toolbox.Core
77
{
88
internal sealed class EncounterModel
99
{
10-
public string Name { get; set; }
10+
public required string Name { get; set; }
1111

12-
public string Author { get; set; }
12+
public required string Author { get; set; }
1313

1414
public DateTime Created { get; set; }
1515

1616
public DateTime Updated { get; set; }
1717

18-
public List<EncounterSpawn> Creatures { get; set; }
18+
public List<EncounterSpawn>? Creatures { get; set; }
1919

2020
public sealed class EncounterSpawn
2121
{
@@ -25,9 +25,9 @@ public sealed class EncounterSpawn
2525
public float LocalOffsetY { get; set; }
2626
public float LocalOffsetZ { get; set; }
2727

28-
public byte[] CreatureData { get; set; }
28+
public required byte[]? CreatureData { get; set; }
2929

30-
public EncounterModel Encounter { get; set; }
30+
public required EncounterModel Encounter { get; set; }
3131
}
3232
}
3333

0 commit comments

Comments
 (0)