mirror of
https://github.com/oliverbooth/VpSharp
synced 2024-11-09 22:55:42 +00:00
refactor!: revert e71494ef83
This commit is contained in:
parent
e71494ef83
commit
c381e079c3
@ -13,6 +13,6 @@ public sealed class RequireBotOwnerAttribute : PreExecutionCheckAttribute
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
return Task.FromResult(context.Avatar.User == context.Client.CurrentUser);
|
||||
return Task.FromResult(context.Avatar.UserId == context.Client.CurrentUser?.Id);
|
||||
}
|
||||
}
|
||||
|
@ -52,6 +52,6 @@ public sealed class RequireUserIdAttribute : PreExecutionCheckAttribute
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
return Task.FromResult(UserIds.Any(i => context.Avatar.User.Id == i));
|
||||
return Task.FromResult(UserIds.Contains(context.Avatar.UserId));
|
||||
}
|
||||
}
|
||||
|
@ -47,14 +47,14 @@ public sealed class RequireUserNameAttribute : PreExecutionCheckAttribute
|
||||
public IReadOnlyList<string> Names { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
protected internal override Task<bool> PerformAsync(CommandContext context)
|
||||
protected internal override async Task<bool> PerformAsync(CommandContext context)
|
||||
{
|
||||
if (context is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
VirtualParadiseUser user = context.Avatar.User;
|
||||
return Task.FromResult(Names.Contains(user.Name));
|
||||
VirtualParadiseUser user = await context.Avatar.GetUserAsync().ConfigureAwait(false);
|
||||
return Names.Contains(user.Name);
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ namespace VpSharp.Entities;
|
||||
public sealed class VirtualParadiseAvatar : IEquatable<VirtualParadiseAvatar>
|
||||
{
|
||||
private readonly VirtualParadiseClient _client;
|
||||
private VirtualParadiseUser? _user;
|
||||
|
||||
internal VirtualParadiseAvatar(VirtualParadiseClient client, int session)
|
||||
{
|
||||
@ -60,10 +61,10 @@ public sealed class VirtualParadiseAvatar : IEquatable<VirtualParadiseAvatar>
|
||||
public int Type { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the user associated with this avatar.
|
||||
/// Gets the user ID associated with this avatar.
|
||||
/// </summary>
|
||||
/// <value>The user.</value>
|
||||
public VirtualParadiseUser User { get; internal set; } = null!;
|
||||
/// <value>The user ID.</value>
|
||||
public int UserId { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Determines if two <see cref="VirtualParadiseAvatar" /> instances are equal.
|
||||
@ -150,7 +151,7 @@ public sealed class VirtualParadiseAvatar : IEquatable<VirtualParadiseAvatar>
|
||||
return true;
|
||||
}
|
||||
|
||||
return Session == other.Session && User.Equals(other.User);
|
||||
return Session == other.Session && UserId.Equals(other.UserId);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -163,10 +164,20 @@ public sealed class VirtualParadiseAvatar : IEquatable<VirtualParadiseAvatar>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
// ReSharper disable NonReadonlyMemberInGetHashCode
|
||||
return HashCode.Combine(Session, User);
|
||||
return HashCode.Combine(Session, UserId);
|
||||
// ReSharper restore NonReadonlyMemberInGetHashCode
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the user associated with this avatar.
|
||||
/// </summary>
|
||||
/// <returns>The user.</returns>
|
||||
public async Task<VirtualParadiseUser> GetUserAsync()
|
||||
{
|
||||
_user ??= await _client.GetUserAsync(UserId).ConfigureAwait(false);
|
||||
return _user;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a console message to the avatar with no name.
|
||||
/// </summary>
|
||||
@ -469,6 +480,6 @@ public sealed class VirtualParadiseAvatar : IEquatable<VirtualParadiseAvatar>
|
||||
/// <inheritdoc />
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Avatar #{Session}; {User.Name} ({Name})";
|
||||
return $"Avatar #{Session}; User #{UserId} ({Name})";
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public sealed partial class VirtualParadiseClient
|
||||
existing.Location = avatar.Location;
|
||||
existing.Application = avatar.Application;
|
||||
existing.Type = avatar.Type;
|
||||
existing.User = avatar.User;
|
||||
existing.UserId = avatar.UserId;
|
||||
return existing;
|
||||
});
|
||||
}
|
||||
@ -62,7 +62,8 @@ public sealed partial class VirtualParadiseClient
|
||||
{
|
||||
Name = vp_string(sender, StringAttribute.AvatarName),
|
||||
Location = new Location(CurrentWorld!, position, rotation),
|
||||
Application = new Application(applicationName, applicationVersion)
|
||||
Application = new Application(applicationName, applicationVersion),
|
||||
UserId = vp_int(sender, IntegerAttribute.UserId)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -89,7 +89,6 @@ public sealed partial class VirtualParadiseClient
|
||||
private void OnAvatarAddNativeEvent(nint sender)
|
||||
{
|
||||
VirtualParadiseAvatar avatar = ExtractAvatar(sender);
|
||||
avatar.User = GetUserAsync(vp_int(sender, IntegerAttribute.UserId)).ConfigureAwait(false).GetAwaiter().GetResult();
|
||||
avatar = AddOrUpdateAvatar(avatar);
|
||||
_avatarJoined.OnNext(avatar);
|
||||
}
|
||||
|
@ -408,7 +408,7 @@ public sealed partial class VirtualParadiseClient : IDisposable
|
||||
Application = _configuration.Application!,
|
||||
Name = $"[{_configuration.BotName}]",
|
||||
Location = new Location(world, Vector3d.Zero, Rotation.None),
|
||||
User = CurrentUser!
|
||||
UserId = CurrentUser!.Id
|
||||
};
|
||||
|
||||
if (CurrentWorld is not null)
|
||||
|
Loading…
Reference in New Issue
Block a user