Use LoadingCache instead of a regular map + more datastore fixes

This commit is contained in:
Luck committed 2016-10-22 20:39:26 +01:00
1 parent 55a0de7899
commit 33c78e4a17
52 files changed
+210 -191

No files matched your search

@@ -95,28 +95,28 @@ public class BungeeListener extends AbstractListener implements Listener {
final PendingConnection c = e.getConnection();
if (!cache.isOnlineMode()) {
UUID uuid = plugin.getDatastore().getUUID(c.getName()).getOrDefault(null);
UUID uuid = plugin.getDatastore().getUUID(c.getName()).getUnchecked();
if (uuid != null) {
cache.addToCache(c.getUniqueId(), uuid);
} else {
// No previous data for this player
plugin.getApiProvider().fireEventAsync(new UserFirstLoginEvent(c.getUniqueId(), c.getName()));
cache.addToCache(c.getUniqueId(), c.getUniqueId());
plugin.getDatastore().force().saveUUIDData(c.getName(), c.getUniqueId()).getOrDefault(false);
plugin.getDatastore().force().saveUUIDData(c.getName(), c.getUniqueId()).getUnchecked();
}
} else {
UUID uuid = plugin.getDatastore().getUUID(c.getName()).getOrDefault(null);
UUID uuid = plugin.getDatastore().getUUID(c.getName()).getUnchecked();
if (uuid == null) {
plugin.getApiProvider().fireEventAsync(new UserFirstLoginEvent(c.getUniqueId(), c.getName()));
}
// Online mode, no cache needed. This is just for name -> uuid lookup.
plugin.getDatastore().force().saveUUIDData(c.getName(), c.getUniqueId()).getOrDefault(false);
plugin.getDatastore().force().saveUUIDData(c.getName(), c.getUniqueId()).getUnchecked();
}
// We have to make a new user on this thread whilst the connection is being held, or we get concurrency issues as the Bukkit server
// and the BungeeCord server try to make a new user at the same time.
plugin.getDatastore().force().loadUser(cache.getUUID(c.getUniqueId()), c.getName()).getOrDefault(false);
plugin.getDatastore().force().loadUser(cache.getUUID(c.getUniqueId()), c.getName()).getUnchecked();
User user = plugin.getUserManager().get(cache.getUUID(c.getUniqueId()));
if (user == null) {
plugin.getLog().warn("Failed to load user: " + c.getName());