mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-09-19 02:11:55 +02:00
run saveAuth async in CacheDataSource
This commit is contained in:
parent
3996c8cfca
commit
f975fefd4a
@ -12,16 +12,18 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
public class CacheDataSource implements DataSource {
|
public class CacheDataSource implements DataSource {
|
||||||
|
|
||||||
private final DataSource source;
|
private final DataSource source;
|
||||||
|
private final AuthMe plugin;
|
||||||
private ConcurrentHashMap<String, PlayerAuth> cache = new ConcurrentHashMap<>();
|
private ConcurrentHashMap<String, PlayerAuth> cache = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
public CacheDataSource(AuthMe plugin, DataSource src) {
|
public CacheDataSource(AuthMe pl, DataSource src) {
|
||||||
|
this.plugin = pl;
|
||||||
this.source = src;
|
this.source = src;
|
||||||
/*
|
/*
|
||||||
* We need to load all players in cache ... It will took more time to
|
* 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
|
* load the server, but it will be much easier to check for an
|
||||||
* isAuthAvailable !
|
* isAuthAvailable !
|
||||||
*/
|
*/
|
||||||
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable(){
|
pl.getServer().getScheduler().runTaskAsynchronously(pl, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
for (PlayerAuth auth : source.getAllAuths()) {
|
for (PlayerAuth auth : source.getAllAuths()) {
|
||||||
@ -46,12 +48,17 @@ public class CacheDataSource implements DataSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized boolean saveAuth(PlayerAuth auth) {
|
public synchronized boolean saveAuth(final PlayerAuth auth) {
|
||||||
if (source.saveAuth(auth)) {
|
|
||||||
cache.put(auth.getNickname(), auth);
|
cache.put(auth.getNickname(), auth);
|
||||||
return true;
|
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (!source.saveAuth(auth)) {
|
||||||
|
cache.remove(auth.getNickname());
|
||||||
}
|
}
|
||||||
return false;
|
}
|
||||||
|
});
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user