Skip to content

[BUG] PlayerManagerService::GetPlayer always return a Player instance #141

@ianlucas

Description

@ianlucas

SwiftlyS2 Version

v1.0.3

Game

Counter-Strike 2

Operating System

Linux

Bug Description

GetPlayer in IPlayerManagerService interface states that it would return null if the player doesn't exist, but its type is IPlayer instead of IPlayer?.

/// <summary>
/// Retrieves the player associated with the specified player ID.
/// </summary>
/// <param name="playerid">The unique identifier of the player to retrieve. Must be a valid player ID.</param>
/// <returns>An <see cref="IPlayer"/> instance representing the player with the specified ID, or <c>null</c> if no such
/// player exists.</returns>
public IPlayer GetPlayer( int playerid );

Also the implementation just instantiates a new Player instead of validating if it is valid.

public IPlayer GetPlayer( int playerid )
{
return new Player(playerid);
}

Steps to Reproduce

Swiftly API usage.

Expected Behavior

Either the documentation comments needs to be updated, or the method should return null when the passed playerid isn't valid (the better approach as we may face exceptions if referencing an invalid entity).

Actual Behavior

GetPlayer always return a Player instance regardless its valid.

Logs/Console Output


Plugin Information

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions