From 0e93d502ef17b0610abd2c450e26d9154818908a Mon Sep 17 00:00:00 2001 From: Xephi Date: Tue, 21 Apr 2015 16:43:49 +0200 Subject: [PATCH] Optimize the cache, it will slow the server starting, but will be much easier to get auths --- .../java/fr/xephi/authme/datasource/CacheDataSource.java | 9 ++++++++- .../fr/xephi/authme/listener/AuthMePlayerListener.java | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java b/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java index 524652c55..e005d0621 100644 --- a/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java +++ b/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java @@ -18,13 +18,20 @@ public class CacheDataSource implements DataSource { public CacheDataSource(AuthMe plugin, DataSource source) { this.plugin = plugin; this.source = source; + /* + * We need to load all players in cache ... + * It will took more time to load the server, + * but it will be much easier to check for an isAuthAvailable ! + */ + for(PlayerAuth auth : source.getAllAuths()) + cache.put(auth.getNickname(), auth); } @Override public synchronized boolean isAuthAvailable(String user) { if (cache.containsKey(user.toLowerCase())) return true; - return source.isAuthAvailable(user.toLowerCase()); + return false; } @Override diff --git a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java index 20279b827..bb189feed 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java @@ -549,7 +549,6 @@ public class AuthMePlayerListener implements Listener { } Player player = event.getPlayer(); final String name = player.getName().toLowerCase(); - Location spawnLoc = plugin.getSpawnLocation(player); gm = player.getGameMode(); gameMode.put(name, gm); BukkitScheduler sched = plugin.getServer().getScheduler(); @@ -583,6 +582,7 @@ public class AuthMePlayerListener implements Listener { return; } } + Location spawnLoc = plugin.getSpawnLocation(player); if (data.isAuthAvailable(name)) { if (Settings.isSessionsEnabled) { PlayerAuth auth = data.getAuth(name);