diff --git a/Commons.iml b/Commons.iml index fd94446..eb28cd2 100644 --- a/Commons.iml +++ b/Commons.iml @@ -44,16 +44,17 @@ + + + - - diff --git a/pom.xml b/pom.xml index 1e90df4..b4e83ad 100644 --- a/pom.xml +++ b/pom.xml @@ -135,6 +135,7 @@ lombok 1.14.8 + io.vertx vertx-core @@ -161,6 +162,16 @@ 3.4.1 + + org.apache.logging.log4j + log4j-api + 2.6.2 + + + org.apache.logging.log4j + log4j-core + 2.6.2 + org.slf4j slf4j-api @@ -182,6 +193,13 @@ guava 19.0 + + + com.github.ben-manes.caffeine + caffeine + 2.5.2 + + org.apache.commons commons-lang3 @@ -192,6 +210,7 @@ commons-io 2.5 + joda-time joda-time @@ -202,16 +221,7 @@ TeamSpeak-3-Java-API v1.0.13 - - org.apache.logging.log4j - log4j-api - 2.6.2 - - - org.apache.logging.log4j - log4j-core - 2.6.2 - + com.github.nsp JSkills diff --git a/src/main/java/eu/univento/commons/Commons.java b/src/main/java/eu/univento/commons/Commons.java index 665403c..c6e9999 100644 --- a/src/main/java/eu/univento/commons/Commons.java +++ b/src/main/java/eu/univento/commons/Commons.java @@ -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() { diff --git a/src/main/java/eu/univento/commons/configuration/ConfigurationHandler.java b/src/main/java/eu/univento/commons/configuration/ConfigurationHandler.java index c8045d1..b4c09fb 100644 --- a/src/main/java/eu/univento/commons/configuration/ConfigurationHandler.java +++ b/src/main/java/eu/univento/commons/configuration/ConfigurationHandler.java @@ -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; diff --git a/src/main/java/eu/univento/commons/database/DatabaseManager.java b/src/main/java/eu/univento/commons/database/DatabaseManager.java index 1ea5b69..b228abb 100644 --- a/src/main/java/eu/univento/commons/database/DatabaseManager.java +++ b/src/main/java/eu/univento/commons/database/DatabaseManager.java @@ -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; diff --git a/src/main/java/eu/univento/commons/database/MongoDB.java b/src/main/java/eu/univento/commons/database/MongoDB.java index 34e1143..728f4cd 100644 --- a/src/main/java/eu/univento/commons/database/MongoDB.java +++ b/src/main/java/eu/univento/commons/database/MongoDB.java @@ -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; diff --git a/src/main/java/eu/univento/commons/database/MySQL.java b/src/main/java/eu/univento/commons/database/MySQL.java index 718bbdf..3c7190c 100644 --- a/src/main/java/eu/univento/commons/database/MySQL.java +++ b/src/main/java/eu/univento/commons/database/MySQL.java @@ -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; diff --git a/src/main/java/eu/univento/commons/event/MessageEvent.java b/src/main/java/eu/univento/commons/event/MessageEvent.java index 23d8952..a9eb66b 100644 --- a/src/main/java/eu/univento/commons/event/MessageEvent.java +++ b/src/main/java/eu/univento/commons/event/MessageEvent.java @@ -7,7 +7,7 @@ package eu.univento.commons.event; /** * @author joethei - * @version 0.1 + * @version 1.0 */ public interface MessageEvent { diff --git a/src/main/java/eu/univento/commons/helpers/Location.java b/src/main/java/eu/univento/commons/helpers/Location.java index ad36351..c2f20f4 100644 --- a/src/main/java/eu/univento/commons/helpers/Location.java +++ b/src/main/java/eu/univento/commons/helpers/Location.java @@ -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; - } } \ No newline at end of file diff --git a/src/main/java/eu/univento/commons/logging/LoggingHandler.java b/src/main/java/eu/univento/commons/logging/LoggingHandler.java index 9144154..ba9193e 100644 --- a/src/main/java/eu/univento/commons/logging/LoggingHandler.java +++ b/src/main/java/eu/univento/commons/logging/LoggingHandler.java @@ -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); } } \ No newline at end of file diff --git a/src/main/java/eu/univento/commons/player/DatabasePlayer.java b/src/main/java/eu/univento/commons/player/DatabasePlayer.java index 7bf4656..fc7dfc4 100644 --- a/src/main/java/eu/univento/commons/player/DatabasePlayer.java +++ b/src/main/java/eu/univento/commons/player/DatabasePlayer.java @@ -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) { diff --git a/src/main/java/eu/univento/commons/player/ban/BanData.java b/src/main/java/eu/univento/commons/player/ban/BanData.java index 4620317..9d046e2 100644 --- a/src/main/java/eu/univento/commons/player/ban/BanData.java +++ b/src/main/java/eu/univento/commons/player/ban/BanData.java @@ -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; diff --git a/src/main/java/eu/univento/commons/player/ban/BanReason.java b/src/main/java/eu/univento/commons/player/ban/BanReason.java index b152743..b2c2490 100644 --- a/src/main/java/eu/univento/commons/player/ban/BanReason.java +++ b/src/main/java/eu/univento/commons/player/ban/BanReason.java @@ -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; /** diff --git a/src/main/java/eu/univento/commons/player/friend/FriendData.java b/src/main/java/eu/univento/commons/player/friend/FriendData.java index c32c742..097e189 100644 --- a/src/main/java/eu/univento/commons/player/friend/FriendData.java +++ b/src/main/java/eu/univento/commons/player/friend/FriendData.java @@ -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; diff --git a/src/main/java/eu/univento/commons/player/kick/KickData.java b/src/main/java/eu/univento/commons/player/kick/KickData.java index 191c44a..234dda7 100644 --- a/src/main/java/eu/univento/commons/player/kick/KickData.java +++ b/src/main/java/eu/univento/commons/player/kick/KickData.java @@ -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; diff --git a/src/main/java/eu/univento/commons/player/kick/KickReason.java b/src/main/java/eu/univento/commons/player/kick/KickReason.java index 6aefb75..17227da 100644 --- a/src/main/java/eu/univento/commons/player/kick/KickReason.java +++ b/src/main/java/eu/univento/commons/player/kick/KickReason.java @@ -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; /** diff --git a/src/main/java/eu/univento/commons/player/language/Language.java b/src/main/java/eu/univento/commons/player/language/Language.java index 9cd2653..2bc41cf 100644 --- a/src/main/java/eu/univento/commons/player/language/Language.java +++ b/src/main/java/eu/univento/commons/player/language/Language.java @@ -17,7 +17,7 @@ import java.util.Locale; /** * @author joethei - * @version 0.1 + * @version 1.5 */ public class Language { diff --git a/src/main/java/eu/univento/commons/player/language/MessageConstant.java b/src/main/java/eu/univento/commons/player/language/MessageConstant.java index 2ed611f..4b45431 100644 --- a/src/main/java/eu/univento/commons/player/language/MessageConstant.java +++ b/src/main/java/eu/univento/commons/player/language/MessageConstant.java @@ -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; diff --git a/src/main/java/eu/univento/commons/player/mute/MuteData.java b/src/main/java/eu/univento/commons/player/mute/MuteData.java index 975628c..dca3d82 100644 --- a/src/main/java/eu/univento/commons/player/mute/MuteData.java +++ b/src/main/java/eu/univento/commons/player/mute/MuteData.java @@ -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; diff --git a/src/main/java/eu/univento/commons/player/mute/MuteReason.java b/src/main/java/eu/univento/commons/player/mute/MuteReason.java index 9492ae7..cd62fc7 100644 --- a/src/main/java/eu/univento/commons/player/mute/MuteReason.java +++ b/src/main/java/eu/univento/commons/player/mute/MuteReason.java @@ -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; /** diff --git a/src/main/java/eu/univento/commons/player/ranking/Ranking.java b/src/main/java/eu/univento/commons/player/ranking/Ranking.java index 9c38a62..24985b4 100644 --- a/src/main/java/eu/univento/commons/player/ranking/Ranking.java +++ b/src/main/java/eu/univento/commons/player/ranking/Ranking.java @@ -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; /** diff --git a/src/main/java/eu/univento/commons/player/settings/PlayerSettings.java b/src/main/java/eu/univento/commons/player/settings/PlayerSettings.java index 1d9df17..9f01394 100644 --- a/src/main/java/eu/univento/commons/player/settings/PlayerSettings.java +++ b/src/main/java/eu/univento/commons/player/settings/PlayerSettings.java @@ -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; diff --git a/src/main/java/eu/univento/commons/player/statistics/GameStat.java b/src/main/java/eu/univento/commons/player/statistics/GameStat.java deleted file mode 100644 index 6da6143..0000000 --- a/src/main/java/eu/univento/commons/player/statistics/GameStat.java +++ /dev/null @@ -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; -} \ No newline at end of file diff --git a/src/main/java/eu/univento/commons/player/statistics/GameStatistics.java b/src/main/java/eu/univento/commons/player/statistics/GameStatistics.java new file mode 100644 index 0000000..e151d5f --- /dev/null +++ b/src/main/java/eu/univento/commons/player/statistics/GameStatistics.java @@ -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 impact; + + public GameStatistics() { + impact = Caffeine.newBuilder().maximumSize(1000).expireAfterWrite(5, TimeUnit.MINUTES).buildAsync((player, executor) -> { + CompletableFuture 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; + }); + + + } +} \ No newline at end of file diff --git a/src/main/java/eu/univento/commons/player/statistics/GameStats.java b/src/main/java/eu/univento/commons/player/statistics/GameStats.java deleted file mode 100644 index c96c5b1..0000000 --- a/src/main/java/eu/univento/commons/player/statistics/GameStats.java +++ /dev/null @@ -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 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 stats) { - player.setInDatabase(type.getName() + "Stats", stats); - } - - public void setStat(String name, Long value) { - Map map = stats; - map.put(name, value); - setStats(map); - } -} \ No newline at end of file diff --git a/src/main/java/eu/univento/commons/player/statistics/ImpactStatistics.java b/src/main/java/eu/univento/commons/player/statistics/ImpactStatistics.java new file mode 100644 index 0000000..d622690 --- /dev/null +++ b/src/main/java/eu/univento/commons/player/statistics/ImpactStatistics.java @@ -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; +} \ No newline at end of file diff --git a/src/main/java/eu/univento/commons/player/uuid/NameFetcher.java b/src/main/java/eu/univento/commons/player/uuid/NameFetcher.java index eb2344a..fa571b7 100644 --- a/src/main/java/eu/univento/commons/player/uuid/NameFetcher.java +++ b/src/main/java/eu/univento/commons/player/uuid/NameFetcher.java @@ -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; } diff --git a/src/main/java/eu/univento/commons/server/ServerInfo.java b/src/main/java/eu/univento/commons/server/ServerInfo.java index a67ca7a..e4449b4 100644 --- a/src/main/java/eu/univento/commons/server/ServerInfo.java +++ b/src/main/java/eu/univento/commons/server/ServerInfo.java @@ -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 getServerInfo(String server) { CompletableFuture 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; - } \ No newline at end of file diff --git a/src/main/java/eu/univento/commons/server/ServerType.java b/src/main/java/eu/univento/commons/server/ServerType.java index 3446771..10d4af5 100644 --- a/src/main/java/eu/univento/commons/server/ServerType.java +++ b/src/main/java/eu/univento/commons/server/ServerType.java @@ -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; + } } \ No newline at end of file diff --git a/src/main/main.iml b/src/main/main.iml deleted file mode 100644 index 301081b..0000000 --- a/src/main/main.iml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file