From eaf6deb0bc5648cdac10f2fd1bfd98a3317aba52 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Thu, 7 Sep 2017 22:11:34 +0200 Subject: [PATCH] + cached user data --- .gitignore | 2 +- .gitlab-ci.yml | 8 -- .gitlab/issue_templates/Bug.md | 3 - .gitlab/issue_templates/Feature.md | 0 .gitlab/settings.xml | 18 ----- .../commons/player/DatabasePlayer.java | 75 ++++++++++++++++--- .../univento/commons/player/rank/Group.java | 16 ++-- .../eu/univento/commons/player/rank/Rank.java | 49 ++++++------ .../commons/player/user/UserInformation.java | 1 - 9 files changed, 100 insertions(+), 72 deletions(-) delete mode 100644 .gitlab-ci.yml delete mode 100644 .gitlab/issue_templates/Bug.md delete mode 100644 .gitlab/issue_templates/Feature.md delete mode 100644 .gitlab/settings.xml diff --git a/.gitignore b/.gitignore index 9d2a752..be0fa1e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ Commons.iml -target \ No newline at end of file +/target/ diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index b5adfa0..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,8 +0,0 @@ -image: maven:3-jdk-8 - -build: - script: "mvn clean --settings .gitlab/settings.xml" - artifacts: - name: "Commons" - paths: - - "target/*.jar" \ No newline at end of file diff --git a/.gitlab/issue_templates/Bug.md b/.gitlab/issue_templates/Bug.md deleted file mode 100644 index 6f0f4bf..0000000 --- a/.gitlab/issue_templates/Bug.md +++ /dev/null @@ -1,3 +0,0 @@ -Was hast du gemacht als der Bug aufgetreten ist ? - -Ausgabe des `/bureport` Befehls: \ No newline at end of file diff --git a/.gitlab/issue_templates/Feature.md b/.gitlab/issue_templates/Feature.md deleted file mode 100644 index e69de29..0000000 diff --git a/.gitlab/settings.xml b/.gitlab/settings.xml deleted file mode 100644 index 8093b52..0000000 --- a/.gitlab/settings.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - univentoEU - download - ${env.password} - - - - - - univentoEU - univentoEU Mirror Repo - http://play.univento.eu:8081/repository/public/ - * - - - \ 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 f490f39..b9c3a18 100644 --- a/src/main/java/eu/univento/commons/player/DatabasePlayer.java +++ b/src/main/java/eu/univento/commons/player/DatabasePlayer.java @@ -26,11 +26,9 @@ import io.vertx.ext.mongo.MongoClient; import lombok.Getter; import java.time.Instant; -import java.util.Calendar; -import java.util.Collection; -import java.util.LinkedList; -import java.util.UUID; -import java.util.concurrent.CompletableFuture; +import java.util.*; +import java.util.concurrent.*; +import java.util.logging.Level; /** * @author joethei @@ -43,34 +41,88 @@ public class DatabasePlayer { private UUID uuid; private String name; + private JsonObject json; + private Rank rank; private PlayerSettings settings; private Language language; private boolean muted; + private ScheduledFuture updateFuture; + public DatabasePlayer(UUID uuid) { this.uuid = uuid; } - public void load() { + public void load(String host) { + Commons.getCommons().getDatabaseManager().getMongoDB().getClient().find("players", new JsonObject().put("uuid", uuid), res -> { + if(res.succeeded()) { + if(res.result().isEmpty()) insert(host); + }else { + Commons.getCommons().getLogger().log(Level.SEVERE, res.cause().getMessage()); + res.cause().printStackTrace(); + } + }); getRankAsync().whenComplete((rank1, throwable) -> rank = rank1); getSettingsAsync().whenComplete((playerSettings, throwable) -> settings = playerSettings); isMutedAsync().whenComplete((aBoolean, throwable) -> muted = aBoolean); getLanguageAsync().whenComplete((language1, throwable) -> language = language1); - Commons.getCommons().getDatabaseManager().getRedis().getClient().get("Name:" + uuid.toString(), event -> { - if(event.succeeded()) { - name = event.result(); + Commons.getCommons().getDatabaseManager().getRedis().getClient().get("Name:" + uuid.toString(), res -> { + if(res.succeeded()) { + name = res.result(); }else { UserInformation.get(uuid.toString()).whenComplete((userInformation, throwable) -> { name = userInformation.getUsername(); - Commons.getCommons().getDatabaseManager().getRedis().getClient().set("Name:" + uuid.toString(), name, event1 -> { - if(event1.failed()) event1.cause().printStackTrace(); + Commons.getCommons().getDatabaseManager().getRedis().getClient().set("Name:" + uuid.toString(), name, event -> { + if(event.failed()) event.cause().printStackTrace(); }); }); } }); + ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); + Runnable updater = this::update; + updateFuture = scheduler.scheduleAtFixedRate(updater, 5, 5, TimeUnit.MINUTES); + } + + public void save() { + updateFuture.cancel(true); + } + + private void update() { + Commons.getCommons().getDatabaseManager().getMongoDB().getClient().findOne("players", new JsonObject().put("uuid", uuid), null, res -> { + if(res.failed()) res.cause().printStackTrace(); + json = res.result(); + }); + } + + //TODO: add more stuff + private void insert(String hostname) { + JsonObject social = new JsonObject().put("tsID", "null").put("boardID", 0); + JsonObject currency = new JsonObject().put("vents", 0); + + JsonObject generalSettings = new JsonObject(); + JsonObject socialSettings = new JsonObject().put("partyRequests", true).put("friendRequests", true).put("friendJump", true).put("clanRequests", true).put("tsMove", true); + JsonObject minigamesSettings = new JsonObject(); + + JsonObject settings = new JsonObject().put("general", generalSettings).put("social", socialSettings).put("minigames", minigamesSettings).put("nicked", false).put("language", Locale.ENGLISH.getLanguage()); + + JsonObject statistics = new JsonObject(); + JsonObject friends = new JsonObject(); + JsonObject history = new JsonObject().put(Instant.now().toString(), "PreIntro"); + JsonObject items = new JsonObject(); + + JsonObject json = new JsonObject().put("uuid", uuid.toString()).put("lastName", name).put("rank", Rank.Player.name()).put("firstLogin", Instant.now()).put("lastLogin", Instant.now()).put("lastOnline", Instant.now()).put("onlineTime", 0L) + .put("lastIP", hostname).put("social", social).put("currency", currency).put("settings", settings).put("statistics", statistics).put("friends", friends).put("history", history).put("items", items); + + + Commons.getCommons().getDatabaseManager().getMongoDB().getClient().insert("players", json, res -> { + if(res.failed()) { + Commons.getCommons().getLogger().log(Level.SEVERE, res.cause().getMessage()); + res.cause().printStackTrace(); + } + }); } public Language getLanguage() { @@ -416,6 +468,7 @@ public class DatabasePlayer { res.cause().printStackTrace(); } }); + update(); } diff --git a/src/main/java/eu/univento/commons/player/rank/Group.java b/src/main/java/eu/univento/commons/player/rank/Group.java index 14a1aac..2a29b36 100644 --- a/src/main/java/eu/univento/commons/player/rank/Group.java +++ b/src/main/java/eu/univento/commons/player/rank/Group.java @@ -15,19 +15,21 @@ import lombok.Getter; @Getter public enum Group { - None("", "", "", ""), - Developer("§3", "§8[§3Dev§8] §3", " §8»§7 ", "§3Dev | "), - Moderator("§c", "§8[§cMod§8] §3", "§8»§7", "§cMod | "), - Supporter("§9", "§8[§9Sup§8] §9", " §8»§7 ", "§9Sup | "), - Builder("§2", "§8[§2Builder§8] §2", " §8»§7 ", "§2Builder | "), - Creative_Director("§e", "§8[§eDesign§8] §e", " §8»§7 ", "§eDesign | "); + None(0, "", "", "", ""), + Developer(11, "§3", "§8[§3Dev§8] §3", " §8»§7 ", "§3Dev | "), + Moderator(13, "§c", "§8[§cMod§8] §3", "§8»§7", "§cMod | "), + Supporter(14, "§9", "§8[§9Sup§8] §9", " §8»§7 ", "§9Sup | "), + Builder(12, "§2", "§8[§2Builder§8] §2", " §8»§7 ", "§2Builder | "), + Creative_Director(15, "§e", "§8[§eCreative Director§8] §e", " §8»§7 ", "§eDesign | "); + private final int ts; private final String color; private final String prefix; private final String suffix; private final String tab; - Group(String color, String prefix, String suffix, String tab) { + Group(int ts, String color, String prefix, String suffix, String tab) { + this.ts = ts; this.color = color; this.prefix = prefix; this.suffix = suffix; diff --git a/src/main/java/eu/univento/commons/player/rank/Rank.java b/src/main/java/eu/univento/commons/player/rank/Rank.java index c417f2e..805bf19 100644 --- a/src/main/java/eu/univento/commons/player/rank/Rank.java +++ b/src/main/java/eu/univento/commons/player/rank/Rank.java @@ -14,45 +14,44 @@ import lombok.Getter; public enum Rank { - Admin(18, 0, 0, Group.None, "a", "§4", "§8[§4Admin§8] §4", " §8»§7 ", "§4Admin | "), + Admin(18, 10, 0, Group.None, "a", "§4", "§8[§4Admin§8] §4", " §8»§7 ", "§4Admin | "), - SrDeveloper(11, 0, 0, Group.Developer, "b"), - Developer(10, 0, 0, Group.Developer, "c"), - JrDeveloper(9, 0, 0, Group.Developer, "d"), + SrDeveloper(11, 0, Group.Developer, "b"), + Developer(10, 0, Group.Developer, "c"), + JrDeveloper(9, 0, Group.Developer, "d"), - SrBuilder(8, 0, 0, Group.Builder, "e"), - Builder(7, 0, 0, Group.Builder, "f"), - JrBuilder(6, 0, 0, Group.Builder, "g"), + SrBuilder(8, 0, Group.Builder, "e"), + Builder(7, 0, Group.Builder, "f"), + JrBuilder(6, 0, Group.Builder, "g"), - SrModerator(17, 0, 0, Group.Moderator, "h"), - Moderator(16, 0, 0, Group.Moderator, "i"), - JrModerator(15, 0, 0, Group.Moderator, "j"), + SrModerator(17, 0, Group.Moderator, "h"), + Moderator(16, 0, Group.Moderator, "i"), + JrModerator(15, 0, Group.Moderator, "j"), - SrSupporter(14, 0, 0, Group.Supporter, "k"), - Supporter(13, 0, 0, Group.Supporter, "l"), - JrSupporter(12, 0, 0, Group.Supporter, "m"), + SrSupporter(14, 0, Group.Supporter, "k"), + Supporter(13, 0, Group.Supporter, "l"), + JrSupporter(12, 0, Group.Supporter, "m"), - Graphic(5, 0, 0, Group.Creative_Director, "n"), - Sound(4, 0, 0, Group.Creative_Director, "o"), + Graphic(5, 0, Group.Creative_Director, "n"), + Sound(4, 0, Group.Creative_Director, "o"), - VIP(3, 0, 0, Group.None, "p", "§5", "§5", " §8»§7 ", "§5"), - Premium(2, 0, 0, Group.None, "q", "§6", "§6", " §8»§7 ", "§6"), - Player(1, 0, 0, Group.None, "r","§7", "§7", " §8»§7 ", "§7"); + VIP(3, 16, 0, Group.None, "p", "§5", "§5", " §8»§7 ", "§5"), + Premium(2, 17, 0, Group.None, "q", "§6", "§6", " §8»§7 ", "§6"), + Player(1, 18, 0, Group.None, "r","§7", "§7", " §8»§7 ", "§7"); @Getter private final int value; - @Getter private final int ts; @Getter private final int board; @Getter private final Group group; @Getter private final String team; + private int ts; private String color; private String prefix; private String suffix; private String tab; - Rank(int value, int ts, int board, Group group, String team) { + Rank(int value, int board, Group group, String team) { this.value = value; - this.ts = ts; this.board = board; this.group = group; this.team = team; @@ -60,17 +59,21 @@ public enum Rank { Rank(int value, int ts, int board, Group group, String team, String color, String prefix, String suffix, String tab) { this.value = value; - this.ts = ts; this.board = board; this.group = group; this.team = team; - + this.ts = ts; this.color = color; this.prefix = prefix; this.suffix = suffix; this.tab = tab; } + public int getTs() { + if(group == Group.None) return ts; + return group.getTs(); + } + public String getColor() { if(group == Group.None) return color; return group.getColor(); diff --git a/src/main/java/eu/univento/commons/player/user/UserInformation.java b/src/main/java/eu/univento/commons/player/user/UserInformation.java index eb4f087..a221da9 100644 --- a/src/main/java/eu/univento/commons/player/user/UserInformation.java +++ b/src/main/java/eu/univento/commons/player/user/UserInformation.java @@ -30,7 +30,6 @@ public class UserInformation { client.getAbs("https://mcapi.de/api/user/" + identifier).ssl(true).send(ar -> { if(ar.succeeded()) { future.complete(ar.result().bodyAsJsonObject().mapTo(UserInformation.class)); - //future.complete(new UserInformation(response.bodyAsJsonObject())); }else future.complete(null); }); return future;