minecrafter / RedisBungee

The leading player synchronization system for BungeeCord
https://www.spigotmc.org/resources/redisbungee.13494/
Eclipse Public License 1.0
157 stars 122 forks source link

PlayerChangedServerNetworkEvent : get origin and target #11

Closed punkeel closed 9 years ago

punkeel commented 9 years ago

Hi, I wanted to know if it was possible to include the server on which was the player before the switch, what is currently impossible due to the serversCache.put ocuring before you call the PlayerChangedServerNetwork event. (see https://github.com/thechunknetwork/RedisBungee/blob/47fc9792b0937d54c74a8a957329aa50747c3faf/src/main/java/com/imaginarycode/minecraft/redisbungee/DataManager.java#L268 )

In a way, this would mimick the ServerSwitchEvent, as we have access to this information via the ProxiedPlayer.getServer. By the way, couldn't this be a Multimap instead of a ConcurrentHashmap ? This way, you would have a list of players per server, and Multimap are already thread safe, I assume.

Thanks in advance, and thanks for all !

minecrafter commented 9 years ago

I forgot about the omission of the previous server; that is a simple fix.

Unfortunately, Guava Multimaps are not thread-safe unless synchronized (which I attempt to avoid), and while a common operation is to generate a server->player multimap, the DataManager reduces the overhead to that of (best-case) O(n) ConcurrentHashMap get operations (which is fairly minimal in terms of time, when you're talking about asynchronous programming).

punkeel commented 9 years ago

Hi, How do you think you would do this ? Edit the object sent via redisbungee, or add the value from the serversCache map ?

Thanks, I didn't knew Multimaps were synchronized.

As for the O(n) overhead, I haven't found the complexity of the HashMultimap, it looks like to be the same as HashMap ... which is O(n), O(n/m) or O(ln(n)) (see here).

Still, it's a minor change.

PS/ Another common query is "where is this player", and for this I don't know which one is the best.

Thanks!

punkeel commented 9 years ago

See #12

punkeel commented 9 years ago

Thanks! Oh, your change is backward compatible, even better !