1
0
mirror of https://github.com/oliverbooth/VpSharp synced 2024-11-23 00:18:46 +00:00

Validate non-null arguments for public API

This commit is contained in:
Oliver Booth 2022-11-30 18:16:37 +00:00
parent cfc73cfb62
commit cfd1e4c208
No known key found for this signature in database
GPG Key ID: 32A00B35503AF634
3 changed files with 17 additions and 0 deletions

View File

@ -134,6 +134,7 @@ public sealed class CommandsExtension : VirtualParadiseClientExtension
/// <inheritdoc /> /// <inheritdoc />
protected override Task OnMessageReceived(MessageReceivedEventArgs args) protected override Task OnMessageReceived(MessageReceivedEventArgs args)
{ {
ArgumentNullException.ThrowIfNull(args);
var message = args.Message; var message = args.Message;
if (message.Type != MessageType.ChatMessage) if (message.Type != MessageType.ChatMessage)

View File

@ -11,8 +11,10 @@ public static class VirtualParadiseClientExtensions
/// <param name="client">The <see cref="VirtualParadiseClient" />.</param> /// <param name="client">The <see cref="VirtualParadiseClient" />.</param>
/// <param name="configuration">The configuration required for the extensions.</param> /// <param name="configuration">The configuration required for the extensions.</param>
/// <returns>The commands extension instance.</returns> /// <returns>The commands extension instance.</returns>
/// <exception cref="ArgumentNullException"><paramref name="client" /> is <see langword="null" />.</exception>
public static CommandsExtension UseCommands(this VirtualParadiseClient client, CommandsExtensionConfiguration configuration) public static CommandsExtension UseCommands(this VirtualParadiseClient client, CommandsExtensionConfiguration configuration)
{ {
ArgumentNullException.ThrowIfNull(client);
return client.AddExtension<CommandsExtension>(configuration); return client.AddExtension<CommandsExtension>(configuration);
} }
} }

View File

@ -292,8 +292,10 @@ public sealed class VirtualParadiseAvatar : IEquatable<VirtualParadiseAvatar>
/// </summary> /// </summary>
/// <param name="world">The name of the world to which this avatar should be teleported.</param> /// <param name="world">The name of the world to which this avatar should be teleported.</param>
/// <param name="position">The position to which this avatar should be teleported.</param> /// <param name="position">The position to which this avatar should be teleported.</param>
/// <exception cref="ArgumentNullException"><paramref name="world" /> is <see langword="null" />.</exception>
public Task TeleportAsync(VirtualParadiseWorld world, Vector3d position) public Task TeleportAsync(VirtualParadiseWorld world, Vector3d position)
{ {
ArgumentNullException.ThrowIfNull(world);
return TeleportAsync(world.Name, position, Quaternion.Identity); return TeleportAsync(world.Name, position, Quaternion.Identity);
} }
@ -303,8 +305,10 @@ public sealed class VirtualParadiseAvatar : IEquatable<VirtualParadiseAvatar>
/// <param name="world">The name of the world to which this avatar should be teleported.</param> /// <param name="world">The name of the world to which this avatar should be teleported.</param>
/// <param name="position">The position to which this avatar should be teleported.</param> /// <param name="position">The position to which this avatar should be teleported.</param>
/// <param name="rotation">The rotation to which this avatar should be teleported.</param> /// <param name="rotation">The rotation to which this avatar should be teleported.</param>
/// <exception cref="ArgumentNullException"><paramref name="world" /> is <see langword="null" />.</exception>
public Task TeleportAsync(VirtualParadiseWorld world, Vector3d position, Quaternion rotation) public Task TeleportAsync(VirtualParadiseWorld world, Vector3d position, Quaternion rotation)
{ {
ArgumentNullException.ThrowIfNull(world);
return TeleportAsync(world.Name, position, rotation); return TeleportAsync(world.Name, position, rotation);
} }
@ -326,6 +330,16 @@ public sealed class VirtualParadiseAvatar : IEquatable<VirtualParadiseAvatar>
/// <param name="rotation">The rotation to which this avatar should be teleported.</param> /// <param name="rotation">The rotation to which this avatar should be teleported.</param>
public async Task TeleportAsync(string world, Vector3d position, Quaternion rotation) public async Task TeleportAsync(string world, Vector3d position, Quaternion rotation)
{ {
ArgumentNullException.ThrowIfNull(world);
#if NET7_0_OR_GREATER
ArgumentException.ThrowIfNullOrEmpty(world);
#else
if (string.IsNullOrEmpty(world))
{
throw new ArgumentException("World cannot be empty");
}
#endif
// ReSharper disable InconsistentlySynchronizedField // ReSharper disable InconsistentlySynchronizedField
bool isSelf = this == _client.CurrentAvatar; bool isSelf = this == _client.CurrentAvatar;
bool isNewWorld = world != Location.World.Name; bool isNewWorld = world != Location.World.Name;