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

Mark (commonly used) Java methods NotNull/Nullable #1490

Open
madsboddum opened this issue Jan 2, 2024 · 1 comment
Open

Mark (commonly used) Java methods NotNull/Nullable #1490

madsboddum opened this issue Jan 2, 2024 · 1 comment
Labels
[Common Player] Service Most common services for the player IMPROVEMENT Enhancement of an existing feature

Comments

@madsboddum
Copy link
Member

Return values and method arguments for Java code. Cover common classes such as Player and CreatureObject, so we can reduce the likelihood of NullPointerExceptions.
Player#getCreatureObject
Player#getPlayerObject

This will also help with the Kotlin conversion somewhat, as we're required to be explicit about nullability there.

These changes alone will result in a big diff, so definitely try to keep the changes simple.

@madsboddum madsboddum added the IMPROVEMENT Enhancement of an existing feature label Jan 2, 2024
@madsboddum
Copy link
Member Author

madsboddum commented Apr 20, 2024

There's a lot of code that assumes Player#getCreatureObject and Player#getPlayerObject won't return null.

And if we did add checks for null in hundreds of methods, I suspect they would all have the same handling of the situation: Nothing should happen.

Perhaps a stronger separation between the zone server and the login server is a better alternative. The reason this can even happen is because the same object, Player, is used at both the login server and the zone server. When at the character selection screen, Player#getCreatureObject obviously makes no sense yet.

Slicing zone server specific stuff into a different object, like a ZonedCharacter, might solve this in a more elegant manner.
Player can return a null ZonedCharacter, but ZonedCharacter#getCreatureObject shouldn't ever return null.

When executing a command, we can have command handlers work on ZonedCharacter instead of Player. You can't execute commands from the login screen, so moving the command handlers etc. to the new class seems sensible.
Some command handlers may need information from Player, so ZonedCharacter can simply have a getPlayer method.

@Undercova Undercova added the [Common Player] Service Most common services for the player label Aug 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Common Player] Service Most common services for the player IMPROVEMENT Enhancement of an existing feature
Projects
None yet
Development

No branches or pull requests

2 participants