44 lines
1.6 KiB
Java
44 lines
1.6 KiB
Java
/*
|
|
* Copyright (c) 2017 univento.eu - All rights reserved
|
|
* You are not allowed to use, distribute or modify this code
|
|
*/
|
|
|
|
package eu.univento.commons.player.statistics;
|
|
|
|
import com.github.benmanes.caffeine.cache.AsyncLoadingCache;
|
|
import com.github.benmanes.caffeine.cache.Caffeine;
|
|
import eu.univento.commons.Commons;
|
|
import eu.univento.commons.player.DatabasePlayer;
|
|
import io.vertx.core.json.JsonObject;
|
|
import lombok.Getter;
|
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
/**
|
|
* @author joethei
|
|
* @version 1.0
|
|
*/
|
|
|
|
@Getter
|
|
public class GameStatistics {
|
|
|
|
private AsyncLoadingCache<DatabasePlayer, ImpactStatistics> impact;
|
|
|
|
public GameStatistics() {
|
|
impact = Caffeine.newBuilder().maximumSize(1000).expireAfterWrite(5, TimeUnit.MINUTES).buildAsync((player, executor) -> {
|
|
CompletableFuture<ImpactStatistics> future = new CompletableFuture<>();
|
|
Commons.getCommons().getDatabaseManager().getMySQL().getClient().getConnection(res -> {
|
|
if(res.failed()) res.cause().printStackTrace();
|
|
res.result().query("SELECT * FROM Stats_Impact WHERE UUID='" + player.getUuid() + "';", result -> {
|
|
if(result.failed()) result.cause().printStackTrace();
|
|
JsonObject json = result.result().getNext().toJson();
|
|
future.complete(new ImpactStatistics(json.getInteger("gamesPlayed"), json.getInteger("gamesWon"), json.getInteger("gamesLost"), json.getInteger("kills"), json.getInteger("deaths")));
|
|
});
|
|
});
|
|
return future;
|
|
});
|
|
|
|
|
|
}
|
|
} |