+ asynchronous statistics cache for games
This commit is contained in:
parent
5db8688a1e
commit
1de1adb47c
@ -44,16 +44,17 @@
|
||||
<orderEntry type="library" name="Maven: org.mongodb:bson:3.4.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.vertx:vertx-rabbitmq-client:3.4.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.rabbitmq:amqp-client:3.6.5" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-api:2.6.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-core:2.6.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.3.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.google.guava:guava:19.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.ben-manes.caffeine:caffeine:2.5.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: commons-io:commons-io:2.5" level="project" />
|
||||
<orderEntry type="library" name="Maven: joda-time:joda-time:2.9.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.TheHolyWaffle:TeamSpeak-3-Java-API:v1.0.13" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-api:2.6.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-core:2.6.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.nsp:JSkills:master-0.9.0-g8b333ec-15" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.ejml:simple:0.28" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.ejml:core:0.28" level="project" />
|
||||
|
30
pom.xml
30
pom.xml
@ -135,6 +135,7 @@
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.14.8</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.vertx</groupId>
|
||||
<artifactId>vertx-core</artifactId>
|
||||
@ -161,6 +162,16 @@
|
||||
<version>3.4.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-api</artifactId>
|
||||
<version>2.6.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.6.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
@ -182,6 +193,13 @@
|
||||
<artifactId>guava</artifactId>
|
||||
<version>19.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.ben-manes.caffeine</groupId>
|
||||
<artifactId>caffeine</artifactId>
|
||||
<version>2.5.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
@ -192,6 +210,7 @@
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.5</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>joda-time</groupId>
|
||||
<artifactId>joda-time</artifactId>
|
||||
@ -202,16 +221,7 @@
|
||||
<artifactId>TeamSpeak-3-Java-API</artifactId>
|
||||
<version>v1.0.13</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-api</artifactId>
|
||||
<version>2.6.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.6.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.nsp</groupId>
|
||||
<artifactId>JSkills</artifactId>
|
||||
|
@ -1,9 +1,16 @@
|
||||
/*
|
||||
* Copyright (c) 2017 univento.eu - All rights reserved
|
||||
* You are not allowed to use, distribute or modify this code
|
||||
*/
|
||||
|
||||
package eu.univento.commons;
|
||||
|
||||
import eu.univento.commons.configuration.ConfigurationHandler;
|
||||
import eu.univento.commons.database.DatabaseManager;
|
||||
import eu.univento.commons.logging.LoggingHandler;
|
||||
import eu.univento.commons.messaging.MessageHandler;
|
||||
import eu.univento.commons.messaging.MessagingManager;
|
||||
import eu.univento.commons.player.statistics.GameStatistics;
|
||||
import io.vertx.core.Vertx;
|
||||
import lombok.Getter;
|
||||
|
||||
@ -22,6 +29,7 @@ public class Commons {
|
||||
private ConfigurationHandler configurationHandler;
|
||||
private LoggingHandler loggingHandler;
|
||||
private Vertx vertx;
|
||||
private GameStatistics gameStatistics;
|
||||
|
||||
public Commons() {
|
||||
commons = this;
|
||||
@ -30,6 +38,9 @@ public class Commons {
|
||||
messagingManager = new MessagingManager();
|
||||
databaseManager = new DatabaseManager();
|
||||
loggingHandler = new LoggingHandler();
|
||||
gameStatistics = new GameStatistics();
|
||||
|
||||
Thread.setDefaultUncaughtExceptionHandler((t, e) -> MessageHandler.sendMessage("log.Exceptions", e.getMessage()));
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) 2017 univento.eu - All rights reserved
|
||||
* You are not allowed to use, distribute or modify this code
|
||||
*/
|
||||
|
||||
package eu.univento.commons.configuration;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) 2017 univento.eu - All rights reserved
|
||||
* You are not allowed to use, distribute or modify this code
|
||||
*/
|
||||
|
||||
package eu.univento.commons.database;
|
||||
|
||||
import eu.univento.commons.Commons;
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) 2017 univento.eu - All rights reserved
|
||||
* You are not allowed to use, distribute or modify this code
|
||||
*/
|
||||
|
||||
package eu.univento.commons.database;
|
||||
|
||||
import eu.univento.commons.Commons;
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) 2017 univento.eu - All rights reserved
|
||||
* You are not allowed to use, distribute or modify this code
|
||||
*/
|
||||
|
||||
package eu.univento.commons.database;
|
||||
|
||||
import eu.univento.commons.Commons;
|
||||
|
@ -7,7 +7,7 @@ package eu.univento.commons.event;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 0.1
|
||||
* @version 1.0
|
||||
*/
|
||||
public interface MessageEvent {
|
||||
|
||||
|
@ -1,5 +1,11 @@
|
||||
/*
|
||||
* Copyright (c) 2017 univento.eu - All rights reserved
|
||||
* You are not allowed to use, distribute or modify this code
|
||||
*/
|
||||
|
||||
package eu.univento.commons.helpers;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
@ -8,6 +14,7 @@ import lombok.Getter;
|
||||
*/
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class Location {
|
||||
|
||||
private final String world;
|
||||
@ -16,13 +23,4 @@ public class Location {
|
||||
private final double z;
|
||||
private final float pitch;
|
||||
private final float yaw;
|
||||
|
||||
public Location(String world, double x, double y, double z, float pitch, float yaw) {
|
||||
this.world = world;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.pitch = pitch;
|
||||
this.yaw = yaw;
|
||||
}
|
||||
}
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) 2017 univento.eu - All rights reserved
|
||||
* You are not allowed to use, distribute or modify this code
|
||||
*/
|
||||
|
||||
package eu.univento.commons.logging;
|
||||
|
||||
import eu.univento.commons.messaging.MessageHandler;
|
||||
@ -12,7 +17,7 @@ public class LoggingHandler {
|
||||
|
||||
public LoggingHandler() {}
|
||||
|
||||
public void log(ServerType type, String message) {
|
||||
MessageHandler.sendMessage("log." + type.getName(), message);
|
||||
public void log(String message) {
|
||||
MessageHandler.sendMessage("log." + ServerType.getServerType().getName(), message);
|
||||
}
|
||||
}
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) 2017 univento.eu - All rights reserved
|
||||
* You are not allowed to use, distribute or modify this code
|
||||
*/
|
||||
|
||||
package eu.univento.commons.player;
|
||||
|
||||
import eu.univento.commons.Commons;
|
||||
@ -75,7 +80,6 @@ public class DatabasePlayer {
|
||||
getObjectFromDatabase("ranking").whenComplete((entries, throwable) ->
|
||||
future.complete(Ranking.valueOf(entries.getString("ranking"))));
|
||||
return future;
|
||||
|
||||
}
|
||||
|
||||
public void ban(BanReason reason, UUID banner, String customMessage, String proof) {
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) 2017 univento.eu - All rights reserved
|
||||
* You are not allowed to use, distribute or modify this code
|
||||
*/
|
||||
|
||||
package eu.univento.commons.player.ban;
|
||||
|
||||
import eu.univento.commons.player.uuid.NameFetcher;
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) 2017 univento.eu - All rights reserved
|
||||
* You are not allowed to use, distribute or modify this code
|
||||
*/
|
||||
|
||||
package eu.univento.commons.player.ban;
|
||||
|
||||
/**
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) 2017 univento.eu - All rights reserved
|
||||
* You are not allowed to use, distribute or modify this code
|
||||
*/
|
||||
|
||||
package eu.univento.commons.player.friend;
|
||||
|
||||
import eu.univento.commons.player.uuid.NameFetcher;
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) 2017 univento.eu - All rights reserved
|
||||
* You are not allowed to use, distribute or modify this code
|
||||
*/
|
||||
|
||||
package eu.univento.commons.player.kick;
|
||||
|
||||
import eu.univento.commons.player.uuid.NameFetcher;
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) 2017 univento.eu - All rights reserved
|
||||
* You are not allowed to use, distribute or modify this code
|
||||
*/
|
||||
|
||||
package eu.univento.commons.player.kick;
|
||||
|
||||
/**
|
||||
|
@ -17,7 +17,7 @@ import java.util.Locale;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 0.1
|
||||
* @version 1.5
|
||||
*/
|
||||
public class Language {
|
||||
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) 2017 univento.eu - All rights reserved
|
||||
* You are not allowed to use, distribute or modify this code
|
||||
*/
|
||||
|
||||
package eu.univento.commons.player.language;
|
||||
|
||||
import lombok.Getter;
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) 2017 univento.eu - All rights reserved
|
||||
* You are not allowed to use, distribute or modify this code
|
||||
*/
|
||||
|
||||
package eu.univento.commons.player.mute;
|
||||
|
||||
import eu.univento.commons.player.uuid.NameFetcher;
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) 2017 univento.eu - All rights reserved
|
||||
* You are not allowed to use, distribute or modify this code
|
||||
*/
|
||||
|
||||
package eu.univento.commons.player.mute;
|
||||
|
||||
/**
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) 2017 univento.eu - All rights reserved
|
||||
* You are not allowed to use, distribute or modify this code
|
||||
*/
|
||||
|
||||
package eu.univento.commons.player.ranking;
|
||||
|
||||
/**
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) 2017 univento.eu - All rights reserved
|
||||
* You are not allowed to use, distribute or modify this code
|
||||
*/
|
||||
|
||||
package eu.univento.commons.player.settings;
|
||||
|
||||
import eu.univento.commons.player.DatabasePlayer;
|
||||
|
@ -1,15 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 0.1
|
||||
*/
|
||||
public interface GameStat {
|
||||
|
||||
//@Getter ServerType type = null;
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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;
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
package eu.univento.commons.player.statistics;
|
||||
|
||||
import eu.univento.commons.player.DatabasePlayer;
|
||||
import eu.univento.commons.server.ServerType;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 0.1
|
||||
*/
|
||||
|
||||
public class GameStats {
|
||||
|
||||
public ServerType type;
|
||||
private DatabasePlayer player;
|
||||
private Map<String, Object> stats = new HashMap<>();
|
||||
|
||||
public GameStats(ServerType type, DatabasePlayer player) {
|
||||
this.type = type;
|
||||
this.player = player;
|
||||
player.getObjectFromDatabase(type.getName()).whenComplete((entries, throwable) -> {
|
||||
//TODO: add stuff here or change the entire stats system
|
||||
});
|
||||
}
|
||||
|
||||
public Long getStat(String name) {
|
||||
return (Long) stats.get(name);
|
||||
}
|
||||
|
||||
private void setStats(Map<String, Object> stats) {
|
||||
player.setInDatabase(type.getName() + "Stats", stats);
|
||||
}
|
||||
|
||||
public void setStat(String name, Long value) {
|
||||
Map<String, Object> map = stats;
|
||||
map.put(name, value);
|
||||
setStats(map);
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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 lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class ImpactStatistics {
|
||||
|
||||
private int gamesPlayed;
|
||||
private int gamesWon;
|
||||
private int gamesLost;
|
||||
private int kills;
|
||||
private int deaths;
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package eu.univento.commons.player.uuid;
|
||||
|
||||
import eu.univento.commons.Commons;
|
||||
import eu.univento.commons.server.ServerType;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
@ -28,7 +27,7 @@ public class NameFetcher {
|
||||
|
||||
String uniqueId = (String) response.get("uuid");
|
||||
if (uniqueId.length() == 0)
|
||||
Commons.getCommons().getLoggingHandler().log(ServerType.getServerType() ,"A Username for UUID '" + uuid.toString() + "' was not found in the database! Is the account not premium?");
|
||||
Commons.getCommons().getLoggingHandler().log("A Username for UUID '" + uuid.toString() + "' was not found in the database! Is the account not premium?");
|
||||
|
||||
return (String) response.get("username");
|
||||
} catch (IOException |ParseException e) {
|
||||
@ -43,17 +42,16 @@ public class NameFetcher {
|
||||
|
||||
String name = (String) response.get("name");
|
||||
if (name == null)
|
||||
Commons.getCommons().getLoggingHandler().log(ServerType.getServerType(),"A Username for UUID '" + uuid.toString() + "' was not found in the database! Is the account not premium?");
|
||||
Commons.getCommons().getLoggingHandler().log("A Username for UUID '" + uuid.toString() + "' was not found in the database! Is the account not premium?");
|
||||
|
||||
String cause = (String) response.get("cause");
|
||||
String errorMessage = (String) response.get("errorMessage");
|
||||
if (cause != null && cause.length() > 0) {
|
||||
Commons.getCommons().getLoggingHandler().log(ServerType.getServerType(), errorMessage);
|
||||
Commons.getCommons().getLoggingHandler().log(errorMessage);
|
||||
}
|
||||
return name;
|
||||
} catch (IOException | ParseException e) {
|
||||
e.printStackTrace();
|
||||
Commons.getCommons().getLoggingHandler().log(ServerType.getServerType(), "A Username for UUID '" + uuid.toString() + "' was not found in the database! Is the account not premium?");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) 2017 univento.eu - All rights reserved
|
||||
* You are not allowed to use, distribute or modify this code
|
||||
*/
|
||||
|
||||
package eu.univento.commons.server;
|
||||
|
||||
import eu.univento.commons.event.MessageEvent;
|
||||
@ -18,6 +23,10 @@ import java.util.regex.Pattern;
|
||||
@Getter
|
||||
public class ServerInfo {
|
||||
|
||||
private String name;
|
||||
private ServerType type;
|
||||
private int players;
|
||||
|
||||
public static CompletableFuture<ServerInfo> getServerInfo(String server) {
|
||||
CompletableFuture<ServerInfo> future = new CompletableFuture<>();
|
||||
UUID uuid = UUID.randomUUID();
|
||||
@ -39,8 +48,4 @@ public class ServerInfo {
|
||||
return future;
|
||||
}
|
||||
|
||||
private String name;
|
||||
private ServerType type;
|
||||
private int players;
|
||||
|
||||
}
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) 2017 univento.eu - All rights reserved
|
||||
* You are not allowed to use, distribute or modify this code
|
||||
*/
|
||||
|
||||
package eu.univento.commons.server;
|
||||
|
||||
import lombok.Getter;
|
||||
@ -29,5 +34,10 @@ public enum ServerType {
|
||||
this.name = name;
|
||||
this.prefix = prefix;
|
||||
}
|
||||
@Getter @Setter private static ServerType serverType;
|
||||
@Setter private static ServerType serverType;
|
||||
|
||||
public static ServerType getServerType() {
|
||||
if(serverType == null) return ServerType.NONE;
|
||||
return serverType;
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/java" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="target" level="project" />
|
||||
</component>
|
||||
</module>
|
Loading…
Reference in New Issue
Block a user