+ cached user data

This commit is contained in:
BuildTools 2017-09-07 22:11:34 +02:00
parent bb8a615ca7
commit eaf6deb0bc
9 changed files with 100 additions and 72 deletions

2
.gitignore vendored
View File

@ -1,2 +1,2 @@
Commons.iml Commons.iml
target /target/

View File

@ -1,8 +0,0 @@
image: maven:3-jdk-8
build:
script: "mvn clean --settings .gitlab/settings.xml"
artifacts:
name: "Commons"
paths:
- "target/*.jar"

View File

@ -1,3 +0,0 @@
Was hast du gemacht als der Bug aufgetreten ist ?
Ausgabe des `/bureport` Befehls:

View File

@ -1,18 +0,0 @@
<settings>
<servers>
<server>
<id>univentoEU</id>
<username>download</username>
<password>${env.password}</password>
</server>
</servers>
<mirrors>
<mirror>
<id>univentoEU</id>
<name>univentoEU Mirror Repo</name>
<url>http://play.univento.eu:8081/repository/public/</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
</settings>

View File

@ -26,11 +26,9 @@ import io.vertx.ext.mongo.MongoClient;
import lombok.Getter; import lombok.Getter;
import java.time.Instant; import java.time.Instant;
import java.util.Calendar; import java.util.*;
import java.util.Collection; import java.util.concurrent.*;
import java.util.LinkedList; import java.util.logging.Level;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
/** /**
* @author joethei * @author joethei
@ -43,34 +41,88 @@ public class DatabasePlayer {
private UUID uuid; private UUID uuid;
private String name; private String name;
private JsonObject json;
private Rank rank; private Rank rank;
private PlayerSettings settings; private PlayerSettings settings;
private Language language; private Language language;
private boolean muted; private boolean muted;
private ScheduledFuture<?> updateFuture;
public DatabasePlayer(UUID uuid) { public DatabasePlayer(UUID uuid) {
this.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); getRankAsync().whenComplete((rank1, throwable) -> rank = rank1);
getSettingsAsync().whenComplete((playerSettings, throwable) -> settings = playerSettings); getSettingsAsync().whenComplete((playerSettings, throwable) -> settings = playerSettings);
isMutedAsync().whenComplete((aBoolean, throwable) -> muted = aBoolean); isMutedAsync().whenComplete((aBoolean, throwable) -> muted = aBoolean);
getLanguageAsync().whenComplete((language1, throwable) -> language = language1); getLanguageAsync().whenComplete((language1, throwable) -> language = language1);
Commons.getCommons().getDatabaseManager().getRedis().getClient().get("Name:" + uuid.toString(), event -> { Commons.getCommons().getDatabaseManager().getRedis().getClient().get("Name:" + uuid.toString(), res -> {
if(event.succeeded()) { if(res.succeeded()) {
name = event.result(); name = res.result();
}else { }else {
UserInformation.get(uuid.toString()).whenComplete((userInformation, throwable) -> { UserInformation.get(uuid.toString()).whenComplete((userInformation, throwable) -> {
name = userInformation.getUsername(); name = userInformation.getUsername();
Commons.getCommons().getDatabaseManager().getRedis().getClient().set("Name:" + uuid.toString(), name, event1 -> { Commons.getCommons().getDatabaseManager().getRedis().getClient().set("Name:" + uuid.toString(), name, event -> {
if(event1.failed()) event1.cause().printStackTrace(); 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() { public Language getLanguage() {
@ -416,6 +468,7 @@ public class DatabasePlayer {
res.cause().printStackTrace(); res.cause().printStackTrace();
} }
}); });
update();
} }

View File

@ -15,19 +15,21 @@ import lombok.Getter;
@Getter @Getter
public enum Group { public enum Group {
None("", "", "", ""), None(0, "", "", "", ""),
Developer("§3", "§8[§3Dev§8] §3", " §8»§7 ", "§3Dev | "), Developer(11, "§3", "§8[§3Dev§8] §3", " §8»§7 ", "§3Dev | "),
Moderator("§c", "§8[§cMod§8] §3", "§8»§7", "§cMod | "), Moderator(13, "§c", "§8[§cMod§8] §3", "§8»§7", "§cMod | "),
Supporter("§9", "§8[§9Sup§8] §9", " §8»§7 ", "§9Sup | "), Supporter(14, "§9", "§8[§9Sup§8] §9", " §8»§7 ", "§9Sup | "),
Builder("§2", "§8[§2Builder§8] §2", " §8»§7 ", "§2Builder | "), Builder(12, "§2", "§8[§2Builder§8] §2", " §8»§7 ", "§2Builder | "),
Creative_Director("§e", "§8[§eDesign§8] §e", " §8»§7 ", "§eDesign | "); Creative_Director(15, "§e", "§8[§eCreative Director§8] §e", " §8»§7 ", "§eDesign | ");
private final int ts;
private final String color; private final String color;
private final String prefix; private final String prefix;
private final String suffix; private final String suffix;
private final String tab; 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.color = color;
this.prefix = prefix; this.prefix = prefix;
this.suffix = suffix; this.suffix = suffix;

View File

@ -14,45 +14,44 @@ import lombok.Getter;
public enum Rank { 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"), SrDeveloper(11, 0, Group.Developer, "b"),
Developer(10, 0, 0, Group.Developer, "c"), Developer(10, 0, Group.Developer, "c"),
JrDeveloper(9, 0, 0, Group.Developer, "d"), JrDeveloper(9, 0, Group.Developer, "d"),
SrBuilder(8, 0, 0, Group.Builder, "e"), SrBuilder(8, 0, Group.Builder, "e"),
Builder(7, 0, 0, Group.Builder, "f"), Builder(7, 0, Group.Builder, "f"),
JrBuilder(6, 0, 0, Group.Builder, "g"), JrBuilder(6, 0, Group.Builder, "g"),
SrModerator(17, 0, 0, Group.Moderator, "h"), SrModerator(17, 0, Group.Moderator, "h"),
Moderator(16, 0, 0, Group.Moderator, "i"), Moderator(16, 0, Group.Moderator, "i"),
JrModerator(15, 0, 0, Group.Moderator, "j"), JrModerator(15, 0, Group.Moderator, "j"),
SrSupporter(14, 0, 0, Group.Supporter, "k"), SrSupporter(14, 0, Group.Supporter, "k"),
Supporter(13, 0, 0, Group.Supporter, "l"), Supporter(13, 0, Group.Supporter, "l"),
JrSupporter(12, 0, 0, Group.Supporter, "m"), JrSupporter(12, 0, Group.Supporter, "m"),
Graphic(5, 0, 0, Group.Creative_Director, "n"), Graphic(5, 0, Group.Creative_Director, "n"),
Sound(4, 0, 0, Group.Creative_Director, "o"), Sound(4, 0, Group.Creative_Director, "o"),
VIP(3, 0, 0, Group.None, "p", "§5", "§5", " §8»§7 ", "§5"), VIP(3, 16, 0, Group.None, "p", "§5", "§5", " §8»§7 ", "§5"),
Premium(2, 0, 0, Group.None, "q", "§6", "§6", " §8»§7 ", "§6"), Premium(2, 17, 0, Group.None, "q", "§6", "§6", " §8»§7 ", "§6"),
Player(1, 0, 0, Group.None, "r","§7", "§7", " §8»§7 ", "§7"); Player(1, 18, 0, Group.None, "r","§7", "§7", " §8»§7 ", "§7");
@Getter private final int value; @Getter private final int value;
@Getter private final int ts;
@Getter private final int board; @Getter private final int board;
@Getter private final Group group; @Getter private final Group group;
@Getter private final String team; @Getter private final String team;
private int ts;
private String color; private String color;
private String prefix; private String prefix;
private String suffix; private String suffix;
private String tab; 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.value = value;
this.ts = ts;
this.board = board; this.board = board;
this.group = group; this.group = group;
this.team = team; 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) { Rank(int value, int ts, int board, Group group, String team, String color, String prefix, String suffix, String tab) {
this.value = value; this.value = value;
this.ts = ts;
this.board = board; this.board = board;
this.group = group; this.group = group;
this.team = team; this.team = team;
this.ts = ts;
this.color = color; this.color = color;
this.prefix = prefix; this.prefix = prefix;
this.suffix = suffix; this.suffix = suffix;
this.tab = tab; this.tab = tab;
} }
public int getTs() {
if(group == Group.None) return ts;
return group.getTs();
}
public String getColor() { public String getColor() {
if(group == Group.None) return color; if(group == Group.None) return color;
return group.getColor(); return group.getColor();

View File

@ -30,7 +30,6 @@ public class UserInformation {
client.getAbs("https://mcapi.de/api/user/" + identifier).ssl(true).send(ar -> { client.getAbs("https://mcapi.de/api/user/" + identifier).ssl(true).send(ar -> {
if(ar.succeeded()) { if(ar.succeeded()) {
future.complete(ar.result().bodyAsJsonObject().mapTo(UserInformation.class)); future.complete(ar.result().bodyAsJsonObject().mapTo(UserInformation.class));
//future.complete(new UserInformation(response.bodyAsJsonObject()));
}else future.complete(null); }else future.complete(null);
}); });
return future; return future;