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

UnturnedPlayer factory methods #26

Open
Game4Freak opened this issue Jul 19, 2020 · 2 comments
Open

UnturnedPlayer factory methods #26

Game4Freak opened this issue Jul 19, 2020 · 2 comments

Comments

@Game4Freak
Copy link

Game4Freak commented Jul 19, 2020

I think most plugin devs use the UnturnedPlayer class because it provides multiple shortcuts that are very handy.
But most of the factory methods dont work as expected and can result in many issues.
This has been a issue in RocketMod too for a long long time.
UnturnedPlayer.FromName only returns a valid UnturnedPlayer object if an actual player is found (how it should work).
But UnturnedPlayer.FromCSteamID will always return a valid UnturnedPlayer object if the CSteamID isnt null or empty or 0.
That means that you will get a object back even if no actual player exists.
When you use that object it will throw error out like nothing because it's player object is null.
https://github.com/SmartlyDressedGames/Legally-Distinct-Missile/blob/master/Rocket.Unturned/Player/UnturnedPlayer.cs#L170
So most of the time you have to check if your UnturnedPlayer object is null and if the UnturnedPlayer.Player object is null.
I think that UnturnedPlayer.FromCSteamID should only return a valid UnturnedPlayer object if an actual player is found.

@Game4Freak
Copy link
Author

Also UnturnedPlayer.FromSteamPlayer and UnturnedPlayer.FromPlayer will have similar issues when you pass null to them

@SDGNelson
Copy link
Member

On the one hand I am hesitant to change the behavior of existing Rocket code, but I have seen a lot of exceptions related to the unusual way those method work. Your proposal seems reasonable to me, and returning null in those cases is how I would expect them to work.

Would anyone else like to weigh in on this or voice their thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants