Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Player comparison #279

Merged
merged 1 commit into from
Nov 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions EXILED/Exiled.API/Features/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3724,6 +3724,37 @@ public void SetCooldownItem(float time, ItemType itemType)
/// <param name="projectileType">The projectile that will create the effect.</param>
public void ExplodeEffect(ProjectileType projectileType) => Map.ExplodeEffect(Position, projectileType);

/// <inheritdoc />
public override bool Equals(object obj)
{
Player player = obj as Player;
return (object)player != null && ReferenceHub == player.ReferenceHub;
}

/// <inheritdoc />
public override int GetHashCode()
{
return ReferenceHub.GetHashCode();
}

/// <summary>
/// Returns whether the two players are the same.
/// </summary>
/// <param name="player1">The first player instance.</param>
/// <param name="player2">The second player instance.</param>
/// <returns><see langword="true"/> if the values are equal.</returns>
#pragma warning disable SA1201
public static bool operator ==(Player player1, Player player2) => player1?.Equals(player2) ?? player2 is null;

/// <summary>
/// Returns whether the two players are different.
/// </summary>
/// <param name="player1">The first player instance.</param>
/// <param name="player2">The second player instance.</param>
/// <returns><see langword="true"/> if the values are not equal.</returns>
public static bool operator !=(Player player1, Player player2) => !(player1 == player2);
#pragma warning restore SA1201

/// <summary>
/// Converts the player in a human-readable format.
/// </summary>
Expand Down