[Dev] Is there a need for an OfflinePlayer

More like

.getPlayerOnline()

For what purpose exactly should they do that?

I also think having only one player class is better. Like lrock23 said. It would just be easier for everyone to use only one class.

You need an interface for defining player data which is accessible regardless of online status, and an interface for defining player data which is only relevant while connected.

Bukkit’s solution (contrary to some of what jacklin wrote) was for an OfflinePlayer which represented the data available at all times, and a Player (extends OfflinePlayer) for the rest.

Player extends HumanEntity, Conversable, CommandSender, OfflinePlayer, PluginMessageRecipient

Meaning that the Player object (online player) is the only one that’s an entity, and it also can send commands, receive messages, etc.

The only other solution I see that isn’t cringe-worthy you could have is some sort of PlayerData class that holds what OfflinePlayer used to, and a Player object has a getPlayerData() method for acquiring/setting that info. If you just force all Player-related stuff into one class, you’re doing something horrid like throwing exceptions when they’re offline and you want their IP or want to have them send a message.

3 Likes

getOfflinePlayerData() on a Player object with an async API would be ideal.

Once we can figure out a scheduler, I want to work on a version of my Control Flow library to be used as a basis for an async API on API methods.

getOfflinePlayerData() on a Player object with an async API would be ideal

Sort of wondering how that would work out. The player is offline but I’d have a player object with a teleport function? What would happen if I called the teleport of the Player object (that represents an offline player)?

I think “nothing” is ok. Or a “PlayerOfflineException”. Even better would be moving the offline players location, but i think thats not possible. (?)

1 Like

Remember the naming conventions:
.isOnline()

That is possible by changing player’s .dat file.

2 Likes

Or you could just add their name to a hash map and teleport them on join.

Would require persisting/managing that state. If that is going to be done might as well update the DAT file.

Hmf

Actually, what can you do with online player you cannot do with the offlline one? The only thing that comes in mind to me is recieving and sending chat messages and commands.

2 Likes

I think everything is possible, but its the effort that matters ^^

Include one Player class for everything. And if a user tries to invoke methods that are only available to online players, while the target player is offline, throw a PlayerOfflineException

1 Like

Which methods would that be?

@ZachBora

.damage()
.getAddress()
.getEyeHeight()
.getLocation()
.getFallDistance()
.getFireTicks()

just to name a few.

.getLocation() would work if it returns the location where the player disconnected.

True. Didn’t think of that one.
Anyways, you see there’s many methods that could throw such an exception.

All of those could be taken from the player DAT except the .getAddress()

2 Likes