A common pattern when using remotes - on the server - is to require casting a player to an object representation of the player.
This may come as the following sort of situation:
As you might have noticed, there's some repeated code where we're repetitively having to grab the player entity here in place of the player.
We can instead use what's called a wrapper to do this for us and make it as if we were connecting directly to the remote and it had the entity as the player argument rather than a player.
We can define a
withPlayerEntity wrapper, which will achieve what we're doing above in each remote separately. This is the recommended method when augmenting the player argument as it's the safest method and guaranteed to run after all the middleware.
Then we can apply this to the code above.
And as you can see, this reduces repetitive code and gives us the
PlayerEntity object to work with. Simple as that.