~changed a few things here and there
This commit is contained in:
parent
1de1adb47c
commit
bb8a615ca7
10
Commons.iml
10
Commons.iml
@ -35,6 +35,7 @@
|
||||
<orderEntry type="library" name="Maven: org.scala-lang:scala-library:2.12.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.mauricio:postgresql-async_2.12:0.2.21" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.mauricio:db-async-common_2.12:0.2.21" level="project" />
|
||||
<orderEntry type="library" name="Maven: joda-time:joda-time:2.9.7" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.joda:joda-convert:1.8.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.javassist:javassist:3.21.0-GA" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.mauricio:mysql-async_2.12:0.2.21" level="project" />
|
||||
@ -44,23 +45,26 @@
|
||||
<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: io.vertx:vertx-web-client:3.4.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.vertx:vertx-web-common:3.4.2" 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: io.sentry:sentry:1.2.2" 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: 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" />
|
||||
<orderEntry type="library" name="Maven: org.ejml:dense64:0.28" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.gitlab:java-gitlab-api:1.2.7" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.awaitility:awaitility:3.0.0" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-library:1.3" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.objenesis:objenesis:2.5.1" level="project" />
|
||||
</component>
|
||||
</module>
|
34
pom.xml
34
pom.xml
@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>eu.univento</groupId>
|
||||
<artifactId>Commons</artifactId>
|
||||
<artifactId>commons</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<name>univento.eu Common Code</name>
|
||||
@ -51,7 +51,7 @@
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>univentoEU</id>
|
||||
<url>http://play.univento.eu:8081/repository/univento/</url>
|
||||
<url>http://nexus.unit.univento.eu/repository/univento/</url>
|
||||
</repository>
|
||||
<!--
|
||||
<site>
|
||||
@ -161,6 +161,11 @@
|
||||
<artifactId>vertx-rabbitmq-client</artifactId>
|
||||
<version>3.4.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.vertx</groupId>
|
||||
<artifactId>vertx-web-client</artifactId>
|
||||
<version>3.4.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
@ -177,6 +182,11 @@
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.25</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.sentry</groupId>
|
||||
<artifactId>sentry</artifactId>
|
||||
<version>1.2.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
@ -211,22 +221,12 @@
|
||||
<version>2.5</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>joda-time</groupId>
|
||||
<artifactId>joda-time</artifactId>
|
||||
<version>2.9.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.TheHolyWaffle</groupId>
|
||||
<artifactId>TeamSpeak-3-Java-API</artifactId>
|
||||
<version>v1.0.13</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.nsp</groupId>
|
||||
<artifactId>JSkills</artifactId>
|
||||
<version>master-0.9.0-g8b333ec-15</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
@ -234,9 +234,11 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gitlab</groupId>
|
||||
<artifactId>java-gitlab-api</artifactId>
|
||||
<version>1.2.7</version>
|
||||
<groupId>org.awaitility</groupId>
|
||||
<artifactId>awaitility</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
@ -7,13 +7,20 @@ 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.party.PartyManager;
|
||||
import eu.univento.commons.player.statistics.GameStatistics;
|
||||
import io.sentry.Sentry;
|
||||
import io.sentry.SentryClient;
|
||||
import io.sentry.jul.SentryHandler;
|
||||
import io.vertx.core.Vertx;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 1.1
|
||||
@ -24,27 +31,47 @@ public class Commons {
|
||||
|
||||
private static Commons commons;
|
||||
|
||||
private Logger logger;
|
||||
|
||||
private DatabaseManager databaseManager;
|
||||
private MessagingManager messagingManager;
|
||||
private ConfigurationHandler configurationHandler;
|
||||
private LoggingHandler loggingHandler;
|
||||
private Vertx vertx;
|
||||
private GameStatistics gameStatistics;
|
||||
private PartyManager partyManager;
|
||||
|
||||
public Commons() {
|
||||
commons = this;
|
||||
vertx = Vertx.vertx();
|
||||
configurationHandler = new ConfigurationHandler();
|
||||
logger = Logger.getLogger("Commons");
|
||||
|
||||
SentryClient sentryClient = Sentry.init(configurationHandler.getString("Sentry.DSN.Commons"));
|
||||
try {
|
||||
sentryClient.setServerName(InetAddress.getLocalHost().getHostName());
|
||||
sentryClient.setEnvironment("");
|
||||
sentryClient.setDist("Commons");
|
||||
sentryClient.setRelease("1.0.0");
|
||||
} catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
SentryHandler logHandler = new SentryHandler();
|
||||
logHandler.setLevel(Level.INFO);
|
||||
|
||||
logger.addHandler(logHandler);
|
||||
|
||||
vertx = Vertx.vertx();
|
||||
messagingManager = new MessagingManager();
|
||||
databaseManager = new DatabaseManager();
|
||||
loggingHandler = new LoggingHandler();
|
||||
gameStatistics = new GameStatistics();
|
||||
partyManager = new PartyManager();
|
||||
|
||||
Thread.setDefaultUncaughtExceptionHandler((t, e) -> MessageHandler.sendMessage("log.Exceptions", e.getMessage()));
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
databaseManager.close();
|
||||
messagingManager.close();
|
||||
vertx.close();
|
||||
Sentry.close();
|
||||
}
|
||||
|
||||
public static Commons getCommons() {
|
||||
|
@ -28,4 +28,12 @@ public class DatabaseManager {
|
||||
redis = new Redis(config.getString("Redis.Hostname"), config.getInteger("Redis.Port"), config.getString("Redis.Password"));
|
||||
}
|
||||
|
||||
public void close() {
|
||||
mongoDB.getClient().close();
|
||||
mySQL.getClient().close();
|
||||
redis.getClient().close(voidAsyncResult -> {
|
||||
if(voidAsyncResult.failed()) voidAsyncResult.cause().printStackTrace();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -1,23 +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.logging;
|
||||
|
||||
import eu.univento.commons.messaging.MessageHandler;
|
||||
import eu.univento.commons.server.ServerType;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public class LoggingHandler {
|
||||
|
||||
public LoggingHandler() {}
|
||||
|
||||
public void log(String message) {
|
||||
MessageHandler.sendMessage("log." + ServerType.getServerType().getName(), message);
|
||||
}
|
||||
}
|
@ -36,4 +36,11 @@ public class MessagingManager {
|
||||
return future;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
if(rabbitMQ.getClient().isConnected()) {
|
||||
rabbitMQ.getClient().stop(voidAsyncResult -> {
|
||||
if(voidAsyncResult.failed()) voidAsyncResult.cause().printStackTrace();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -8,7 +8,7 @@ package eu.univento.commons.player;
|
||||
import eu.univento.commons.Commons;
|
||||
import eu.univento.commons.player.ban.BanData;
|
||||
import eu.univento.commons.player.ban.BanReason;
|
||||
import eu.univento.commons.player.friend.FriendData;
|
||||
import eu.univento.commons.player.currency.CurrencyType;
|
||||
import eu.univento.commons.player.kick.KickData;
|
||||
import eu.univento.commons.player.kick.KickReason;
|
||||
import eu.univento.commons.player.language.Language;
|
||||
@ -18,6 +18,7 @@ import eu.univento.commons.player.rank.Group;
|
||||
import eu.univento.commons.player.rank.Rank;
|
||||
import eu.univento.commons.player.ranking.Ranking;
|
||||
import eu.univento.commons.player.settings.PlayerSettings;
|
||||
import eu.univento.commons.player.user.UserInformation;
|
||||
import eu.univento.commons.player.warn.WarnData;
|
||||
import eu.univento.commons.player.warn.WarnReason;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
@ -25,9 +26,11 @@ import io.vertx.ext.mongo.MongoClient;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
@ -45,9 +48,8 @@ public class DatabasePlayer {
|
||||
private Language language;
|
||||
private boolean muted;
|
||||
|
||||
public DatabasePlayer(UUID uuid, String name) {
|
||||
public DatabasePlayer(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void load() {
|
||||
@ -55,6 +57,20 @@ public class DatabasePlayer {
|
||||
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();
|
||||
}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();
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public Language getLanguage() {
|
||||
@ -67,17 +83,16 @@ public class DatabasePlayer {
|
||||
return future;
|
||||
}
|
||||
|
||||
|
||||
public CompletableFuture<PlayerSettings> getSettingsAsync() {
|
||||
CompletableFuture<PlayerSettings> future = new CompletableFuture<>();
|
||||
getObjectFromDatabase("Settings").whenComplete((entries, throwable) ->
|
||||
getObjectFromDatabase().whenComplete((entries, throwable) ->
|
||||
future.complete(new PlayerSettings(this, entries.getJsonObject("Settings"))));
|
||||
return future;
|
||||
}
|
||||
|
||||
public CompletableFuture<Ranking> getRanking() {
|
||||
CompletableFuture<Ranking> future = new CompletableFuture<>();
|
||||
getObjectFromDatabase("ranking").whenComplete((entries, throwable) ->
|
||||
getObjectFromDatabase().whenComplete((entries, throwable) ->
|
||||
future.complete(Ranking.valueOf(entries.getString("ranking"))));
|
||||
return future;
|
||||
}
|
||||
@ -112,6 +127,7 @@ public class DatabasePlayer {
|
||||
MongoClient client = Commons.getCommons().getDatabaseManager().getMongoDB().getClient();
|
||||
client.findOne("bans", new JsonObject().put("uuid", uuid.toString()), null, res -> {
|
||||
if(res.failed()) future.complete(null);
|
||||
if(res.result() == null) future.complete(null);
|
||||
JsonObject result = res.result();
|
||||
if(result.isEmpty()) future.complete(null);
|
||||
BanData data = new BanData(BanReason.valueOf(result.getString("reason")),
|
||||
@ -126,7 +142,12 @@ public class DatabasePlayer {
|
||||
|
||||
public CompletableFuture<Boolean> isBanned() {
|
||||
CompletableFuture<Boolean> future = new CompletableFuture<>();
|
||||
Commons.getCommons().getDatabaseManager().getMongoDB().getClient().find("bans", new JsonObject().put("uuid", uuid.toString()), res -> {
|
||||
if(res.succeeded()) {
|
||||
getBan().whenComplete((banData, throwable) -> future.complete(banData != null && !Instant.now().isAfter(banData.getUnbanDate())));
|
||||
|
||||
}else future.complete(false);
|
||||
});
|
||||
return future;
|
||||
}
|
||||
|
||||
@ -287,15 +308,7 @@ public class DatabasePlayer {
|
||||
|
||||
public CompletableFuture<Rank> getRankAsync() {
|
||||
CompletableFuture<Rank> future = new CompletableFuture<>();
|
||||
MongoClient client = Commons.getCommons().getDatabaseManager().getMongoDB().getClient();
|
||||
client.findOne("players", new JsonObject().put("uuid", uuid.toString()), null, res -> {
|
||||
if(res.succeeded()) {
|
||||
future.complete(Rank.valueOf(res.result().getString("rank")));
|
||||
}else{
|
||||
res.cause().printStackTrace();
|
||||
future.complete(Rank.Player);
|
||||
}
|
||||
});
|
||||
getStringFromDatabase("rank").whenComplete((s, throwable) -> future.complete(Rank.valueOf(s)));
|
||||
return future;
|
||||
}
|
||||
|
||||
@ -323,6 +336,10 @@ public class DatabasePlayer {
|
||||
return future;
|
||||
}
|
||||
|
||||
public boolean isTeamMember() {
|
||||
return isAllowed(Rank.Sound);
|
||||
}
|
||||
|
||||
public CompletableFuture<Boolean> hasPlayedBefore() {
|
||||
CompletableFuture<Boolean> future = new CompletableFuture<>();
|
||||
MongoClient client = Commons.getCommons().getDatabaseManager().getMongoDB().getClient();
|
||||
@ -331,136 +348,61 @@ public class DatabasePlayer {
|
||||
return future;
|
||||
}
|
||||
|
||||
public void buy(CurrencyType type, int price) {
|
||||
getCurrency(type).whenComplete((integer, throwable) -> setCurrency(type, integer - price));
|
||||
}
|
||||
|
||||
private void setCurrency(CurrencyType type, int currency) {
|
||||
setInDatabase(type.getName(), currency);
|
||||
}
|
||||
|
||||
public CompletableFuture<Integer> getCurrency(CurrencyType type) {
|
||||
return getIntegerFromDatabase(type.getName());
|
||||
}
|
||||
|
||||
public void addCurrency(CurrencyType type, int amount) {
|
||||
getCurrency(type).whenComplete((integer, throwable) -> setCurrency(type, integer + amount));
|
||||
}
|
||||
|
||||
public void setTSID(String id) {
|
||||
setInDatabase("tsid", id);
|
||||
}
|
||||
|
||||
public void setCoins(int coins) {
|
||||
setInDatabase("coins", coins);
|
||||
}
|
||||
|
||||
public void setExperience(int experience) {
|
||||
setInDatabase("experience", experience);
|
||||
}
|
||||
|
||||
public CompletableFuture<Instant> getFirstLogin() {
|
||||
CompletableFuture<Instant> future = new CompletableFuture<>();
|
||||
getObjectFromDatabase("firstLogin").whenComplete((entries, throwable) -> future.complete(entries.getInstant("firstLogin")));
|
||||
return future;
|
||||
return getInstantFromDatabase("firstLogin");
|
||||
}
|
||||
|
||||
public CompletableFuture<Instant> getLastLogin() {
|
||||
CompletableFuture<Instant> future = new CompletableFuture<>();
|
||||
getObjectFromDatabase("lastLogin").whenComplete((entries, throwable) -> future.complete(entries.getInstant("lastLogin")));
|
||||
return future;
|
||||
return getInstantFromDatabase("lastLogin");
|
||||
}
|
||||
|
||||
public CompletableFuture<Instant> getLastOnline() {
|
||||
CompletableFuture<Instant> future = new CompletableFuture<>();
|
||||
getObjectFromDatabase("lastOnline").whenComplete((entries, throwable) -> future.complete(entries.getInstant("lastOnline")));
|
||||
return future;
|
||||
return getInstantFromDatabase("lastOnline");
|
||||
}
|
||||
|
||||
public CompletableFuture<String> getLastIP() {
|
||||
CompletableFuture<String> future = new CompletableFuture<>();
|
||||
getObjectFromDatabase("lastIP").whenComplete((entries, throwable) -> future.complete(entries.getString("lastIP")));
|
||||
return future;
|
||||
return getStringFromDatabase("lastIP");
|
||||
}
|
||||
|
||||
public CompletableFuture<String> getTSID() {
|
||||
CompletableFuture<String> future = new CompletableFuture<>();
|
||||
getObjectFromDatabase("tsid").whenComplete((entries, throwable) -> future.complete(entries.getString("tsid")));
|
||||
return future;
|
||||
return getStringFromDatabase("tsID");
|
||||
}
|
||||
|
||||
public CompletableFuture<Integer> getTimesJoined() {
|
||||
CompletableFuture<Integer> future = new CompletableFuture<>();
|
||||
getObjectFromDatabase("timesJoined").whenComplete((entries, throwable) -> future.complete(entries.getInteger("TimesJoined")));
|
||||
return future;
|
||||
return getIntegerFromDatabase("timesJoined");
|
||||
}
|
||||
|
||||
public CompletableFuture<Integer> getCoins() {
|
||||
CompletableFuture<Integer> future = new CompletableFuture<>();
|
||||
getObjectFromDatabase("coins").whenComplete((entries, throwable) -> future.complete(entries.getInteger("coins")));
|
||||
return future;
|
||||
public CompletableFuture<Long> getOnlineTime() {
|
||||
return getLongFromDatabase("OnlineTime");
|
||||
}
|
||||
|
||||
public CompletableFuture<Integer> getExperience() {
|
||||
CompletableFuture<Integer> future = new CompletableFuture<>();
|
||||
getObjectFromDatabase("experience").whenComplete((entries, throwable) -> future.complete(entries.getInteger("experience")));
|
||||
return future;
|
||||
public void setOnlineTime(long time) {
|
||||
setInDatabase("onlineTime", time);
|
||||
}
|
||||
|
||||
private void setFriends(Collection<FriendData> friends) {
|
||||
List<UUID> list = friends.stream().map(FriendData::getUuid).collect(Collectors.toCollection(LinkedList::new));
|
||||
|
||||
MongoClient client = Commons.getCommons().getDatabaseManager().getMongoDB().getClient();
|
||||
client.findOneAndUpdate("friends", new JsonObject().put("uuid", uuid.toString()),
|
||||
new JsonObject().put("$set", new JsonObject().put("friends", list)), res -> {
|
||||
if (res.failed()) {
|
||||
try {
|
||||
throw res.cause();
|
||||
} catch (Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public CompletableFuture<Collection<FriendData>> getFriends() {
|
||||
CompletableFuture<Collection<FriendData>> future = new CompletableFuture<>();
|
||||
Collection<FriendData> data = new LinkedList<>();
|
||||
MongoClient client = Commons.getCommons().getDatabaseManager().getMongoDB().getClient();
|
||||
client.findOne("friends", new JsonObject().put("uuid", uuid.toString()), null, res -> {
|
||||
if (res.succeeded()) {
|
||||
for (Object uuid : res.result().getJsonArray("friends")) {
|
||||
data.add(new FriendData(UUID.fromString(String.valueOf(uuid))));
|
||||
}
|
||||
future.complete(data);
|
||||
}
|
||||
});
|
||||
return future;
|
||||
}
|
||||
|
||||
public CompletableFuture<Boolean> isFriend(UUID uuid) {
|
||||
CompletableFuture<Boolean> future = new CompletableFuture<>();
|
||||
getFriends().whenComplete((friendData, throwable) -> {
|
||||
for (FriendData data : friendData) {
|
||||
if (data.getUuid() == uuid) future.complete(true);
|
||||
}
|
||||
future.complete(false);
|
||||
});
|
||||
|
||||
return future;
|
||||
}
|
||||
|
||||
public void addFriend(UUID uuid) {
|
||||
getFriends().whenComplete((friendData, throwable) -> {
|
||||
friendData.add(new FriendData(uuid));
|
||||
setFriends(friendData);
|
||||
});
|
||||
}
|
||||
|
||||
public void removeFriend(UUID uuid) {
|
||||
getFriends().whenComplete((friendData, throwable) -> {
|
||||
friendData.remove(new FriendData(uuid));
|
||||
setFriends(friendData);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public void addCoins(int coins) {
|
||||
getCoins().whenComplete((integer, throwable) -> setCoins(integer + coins));
|
||||
}
|
||||
|
||||
public void substractCoins(int coins) {
|
||||
getCoins().whenComplete((integer, throwable) -> setCoins(integer - coins));
|
||||
}
|
||||
|
||||
public CompletableFuture<Integer> getBoardID() {
|
||||
CompletableFuture<Integer> future = new CompletableFuture<>();
|
||||
getObjectFromDatabase("boardID").whenComplete((entries, throwable) -> future.complete(entries.getInteger("boardID")));
|
||||
return future;
|
||||
return getIntegerFromDatabase("boardID");
|
||||
}
|
||||
|
||||
public void setBoardID(int id) {
|
||||
@ -469,19 +411,45 @@ public class DatabasePlayer {
|
||||
|
||||
public void setInDatabase(String name, Object obj) {
|
||||
MongoClient client = Commons.getCommons().getDatabaseManager().getMongoDB().getClient();
|
||||
client.update("players", new JsonObject().put("uuid", uuid.toString()),
|
||||
new JsonObject().put("$set", new JsonObject().put(name, obj)), res -> {
|
||||
client.updateCollection("players", new JsonObject().put("uuid", uuid.toString()), new JsonObject().put("$set", new JsonObject().put(name, obj)), res -> {
|
||||
if(res.failed()) {
|
||||
try {
|
||||
throw res.cause();
|
||||
} catch (Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
res.cause().printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public CompletableFuture<JsonObject> getObjectFromDatabase(String name) {
|
||||
|
||||
private CompletableFuture<String> getStringFromDatabase(String key) {
|
||||
CompletableFuture<String> future = new CompletableFuture<>();
|
||||
getObjectFromDatabase().whenComplete((entries, throwable) -> future.complete(entries.getString(key)));
|
||||
return future;
|
||||
}
|
||||
|
||||
private CompletableFuture<Long> getLongFromDatabase(String key) {
|
||||
CompletableFuture<Long> future = new CompletableFuture<>();
|
||||
getObjectFromDatabase().whenComplete((entries, throwable) -> future.complete(entries.getLong(key)));
|
||||
return future;
|
||||
}
|
||||
|
||||
private CompletableFuture<Integer> getIntegerFromDatabase(String key) {
|
||||
CompletableFuture<Integer> future = new CompletableFuture<>();
|
||||
getObjectFromDatabase().whenComplete((entries, throwable) -> future.complete(entries.getInteger(key)));
|
||||
return future;
|
||||
}
|
||||
|
||||
private CompletableFuture<Boolean> getBooleanFromDatabase(String key) {
|
||||
CompletableFuture<Boolean> future = new CompletableFuture<>();
|
||||
getObjectFromDatabase().whenComplete((entries, throwable) -> future.complete(entries.getBoolean(key)));
|
||||
return future;
|
||||
}
|
||||
|
||||
public CompletableFuture<Instant> getInstantFromDatabase(String key) {
|
||||
CompletableFuture<Instant> future = new CompletableFuture<>();
|
||||
getObjectFromDatabase().whenComplete((entries, throwable) -> future.complete(entries.getInstant(key)));
|
||||
return future;
|
||||
}
|
||||
|
||||
public CompletableFuture<JsonObject> getObjectFromDatabase() {
|
||||
CompletableFuture<JsonObject> future = new CompletableFuture<>();
|
||||
MongoClient client = Commons.getCommons().getDatabaseManager().getMongoDB().getClient();
|
||||
client.findOne("players", new JsonObject().put("uuid", uuid.toString()), null, res -> future.complete(res.result()));
|
||||
|
@ -5,10 +5,14 @@
|
||||
|
||||
package eu.univento.commons.player.ban;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
@Getter
|
||||
public enum BanReason {
|
||||
|
||||
HACK_CRITICALS("Ban.Reason.Hack.Criticals", 10),
|
||||
@ -36,12 +40,4 @@ public enum BanReason {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (c) 2017 univento.eu - All rights reserved
|
||||
* You are not allowed to use, distribute or modify this code
|
||||
*/
|
||||
|
||||
package eu.univento.commons.player.currency;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 0.1
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum CurrencyType {
|
||||
Vents("Vents", "⨈");
|
||||
|
||||
private String name;
|
||||
private String symbol;
|
||||
}
|
@ -5,10 +5,14 @@
|
||||
|
||||
package eu.univento.commons.player.kick;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 0.1
|
||||
*/
|
||||
|
||||
@Getter
|
||||
public enum KickReason {
|
||||
|
||||
INSULT("Insult", 10);
|
||||
@ -21,12 +25,4 @@ public enum KickReason {
|
||||
this.points = points;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getPoints() {
|
||||
return points;
|
||||
}
|
||||
|
||||
}
|
@ -7,12 +7,10 @@ package eu.univento.commons.player.language;
|
||||
|
||||
import eu.univento.commons.Commons;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.ext.sql.ResultSet;
|
||||
import io.vertx.ext.sql.SQLConnection;
|
||||
import io.vertx.ext.web.client.WebClient;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
@ -23,30 +21,26 @@ public class Language {
|
||||
|
||||
private static ArrayList<Language> languages = new ArrayList<>();
|
||||
|
||||
/*
|
||||
static {
|
||||
languages.add(new Language(Locale.GERMAN));
|
||||
languages.add(new Language(Locale.ENGLISH));
|
||||
languages.add(new Language(Locale.ITALIAN));
|
||||
}
|
||||
*/
|
||||
|
||||
@Getter private Locale locale;
|
||||
private LinkedHashMap<String, String> translations = new LinkedHashMap<>();
|
||||
private JsonObject json;
|
||||
|
||||
private Language(Locale locale) {
|
||||
this.locale = locale;
|
||||
Commons.getCommons().getDatabaseManager().getMySQL().getClient().getConnection(res -> {
|
||||
if(res.succeeded()) {
|
||||
SQLConnection connection = res.result();
|
||||
connection.query("SELECT identifier, " + locale.getLanguage() + " FROM translations;", result -> {
|
||||
if(result.succeeded()) {
|
||||
ResultSet rs = result.result();
|
||||
for(JsonObject json : rs.getRows()) {
|
||||
translations.put(json.getString("identifier"), json.getString(locale.getLanguage()));
|
||||
}
|
||||
|
||||
}else result.cause().printStackTrace();
|
||||
});
|
||||
}else res.cause().printStackTrace();
|
||||
WebClient webClient = WebClient.create(Commons.getCommons().getVertx());
|
||||
webClient.get("download.unit.univento.eu", "/config/languages/" + locale.getLanguage() + ".json").send(ar -> {
|
||||
if(ar.succeeded()) {
|
||||
this.json = ar.result().bodyAsJsonObject();
|
||||
|
||||
}else Commons.getCommons().getLogger().severe(ar.cause().getMessage());
|
||||
});
|
||||
}
|
||||
|
||||
@ -61,7 +55,7 @@ public class Language {
|
||||
return getWord(constant.getName());
|
||||
}
|
||||
|
||||
public String getWord(String identifier) {
|
||||
return translations.get(identifier);
|
||||
public String getWord(String key) {
|
||||
return json.getString(key);
|
||||
}
|
||||
}
|
@ -5,10 +5,14 @@
|
||||
|
||||
package eu.univento.commons.player.mute;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
@Getter
|
||||
public enum MuteReason {
|
||||
|
||||
SPAM("Mute.Reason.Spam", 1),
|
||||
@ -27,12 +31,4 @@ public enum MuteReason {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
57
src/main/java/eu/univento/commons/player/party/Party.java
Normal file
57
src/main/java/eu/univento/commons/player/party/Party.java
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2017 univento.eu - All rights reserved
|
||||
* You are not allowed to use, distribute or modify this code
|
||||
*/
|
||||
|
||||
package eu.univento.commons.player.party;
|
||||
|
||||
import eu.univento.commons.player.DatabasePlayer;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
@Getter
|
||||
public class Party {
|
||||
|
||||
//TODO: more stuff to add here
|
||||
|
||||
private DatabasePlayer owner;
|
||||
private List<DatabasePlayer> members;
|
||||
private List<DatabasePlayer> invitations;
|
||||
|
||||
public Party(DatabasePlayer owner, List<DatabasePlayer> members, List<DatabasePlayer> invitations) {
|
||||
this.owner = owner;
|
||||
|
||||
if(members == null) this.members = new ArrayList<>();
|
||||
else this.members = members;
|
||||
|
||||
if(invitations == null )this.invitations = new ArrayList<>();
|
||||
else this.invitations = invitations;
|
||||
}
|
||||
|
||||
public boolean addMember(DatabasePlayer player) {
|
||||
return !members.contains(player) && members.add(player);
|
||||
}
|
||||
|
||||
public boolean removeMember(DatabasePlayer player) {
|
||||
return members.contains(player) && members.remove(player);
|
||||
}
|
||||
|
||||
public boolean addInvite(DatabasePlayer player) {
|
||||
return !invitations.contains(player) && invitations.add(player);
|
||||
}
|
||||
|
||||
public boolean removeInvite(DatabasePlayer player) {
|
||||
return invitations.contains(player) && invitations.remove(player);
|
||||
}
|
||||
|
||||
public void leave(DatabasePlayer player) {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2017 univento.eu - All rights reserved
|
||||
* You are not allowed to use, distribute or modify this code
|
||||
*/
|
||||
|
||||
package eu.univento.commons.player.party;
|
||||
|
||||
import eu.univento.commons.Commons;
|
||||
import eu.univento.commons.player.DatabasePlayer;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class PartyManager {
|
||||
|
||||
public PartyManager() {}
|
||||
|
||||
public CompletableFuture<Party> getParty(UUID id) {
|
||||
CompletableFuture<Party> future = new CompletableFuture<>();
|
||||
List<DatabasePlayer> members = new LinkedList<>();
|
||||
List<DatabasePlayer> invitations = new LinkedList<>();
|
||||
Commons.getCommons().getDatabaseManager().getMongoDB().getClient().findOne("partys", new JsonObject().put("id", id), null, res -> {
|
||||
if(res.failed()) future.complete(null);
|
||||
res.result().getJsonArray("members").forEach(obj -> members.add(new DatabasePlayer(UUID.fromString(String.valueOf(obj)))));
|
||||
res.result().getJsonArray("invitations").forEach(obj -> invitations.add(new DatabasePlayer(UUID.fromString(String.valueOf(obj)))));
|
||||
future.complete(new Party(new DatabasePlayer(UUID.fromString(res.result().getString("owner"))), members, invitations));
|
||||
});
|
||||
return future;
|
||||
}
|
||||
|
||||
public CompletableFuture<Party> getParty(DatabasePlayer player) {
|
||||
CompletableFuture<Party> future = new CompletableFuture<>();
|
||||
Commons.getCommons().getDatabaseManager().getMongoDB().getClient().findOne("partys", new JsonObject().put("owner", player.getUuid().toString()), null, res -> {
|
||||
if(res.succeeded()) {
|
||||
getParty(UUID.fromString(res.result().getString("id"))).whenComplete((party, throwable) -> {
|
||||
future.complete(party);
|
||||
});
|
||||
}
|
||||
});
|
||||
return future;
|
||||
}
|
||||
|
||||
public CompletableFuture<Boolean> isInParty(DatabasePlayer player) {
|
||||
CompletableFuture<Boolean> future = new CompletableFuture<>();
|
||||
getParty(player).whenComplete((party, throwable) -> future.complete(party != null));
|
||||
return future;
|
||||
}
|
||||
}
|
@ -20,7 +20,7 @@ public enum Group {
|
||||
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 | "),
|
||||
Design("§e", "§8[§eDesign§8] §e", " §8»§7 ", "§eDesign | ");
|
||||
Creative_Director("§e", "§8[§eDesign§8] §e", " §8»§7 ", "§eDesign | ");
|
||||
|
||||
private final String color;
|
||||
private final String prefix;
|
||||
|
@ -32,8 +32,8 @@ public enum Rank {
|
||||
Supporter(13, 0, 0, Group.Supporter, "l"),
|
||||
JrSupporter(12, 0, 0, Group.Supporter, "m"),
|
||||
|
||||
Graphic(5, 0, 0, Group.Design, "n"),
|
||||
Sound(4, 0, 0, Group.Design, "o"),
|
||||
Graphic(5, 0, 0, Group.Creative_Director, "n"),
|
||||
Sound(4, 0, 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"),
|
||||
|
31
src/main/java/eu/univento/commons/player/user/Decoded.java
Normal file
31
src/main/java/eu/univento/commons/player/user/Decoded.java
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2017 univento.eu - All rights reserved
|
||||
* You are not allowed to use, distribute or modify this code
|
||||
*/
|
||||
|
||||
package eu.univento.commons.player.user;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor(suppressConstructorProperties = true)
|
||||
public class Decoded {
|
||||
private String name;
|
||||
private Value value;
|
||||
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor(suppressConstructorProperties = true)
|
||||
public class Value {
|
||||
private Timestamp timestamp;
|
||||
private String profileId;
|
||||
private String profileName;
|
||||
private boolean signatureRequired;
|
||||
private Textures textures;
|
||||
}
|
||||
}
|
24
src/main/java/eu/univento/commons/player/user/History.java
Normal file
24
src/main/java/eu/univento/commons/player/user/History.java
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (c) 2017 univento.eu - All rights reserved
|
||||
* You are not allowed to use, distribute or modify this code
|
||||
*/
|
||||
|
||||
package eu.univento.commons.player.user;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 0.1
|
||||
*/
|
||||
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor(suppressConstructorProperties = true)
|
||||
public class History {
|
||||
|
||||
private String name;
|
||||
private int changedToAt = 0;
|
||||
}
|
20
src/main/java/eu/univento/commons/player/user/Raw.java
Normal file
20
src/main/java/eu/univento/commons/player/user/Raw.java
Normal file
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright (c) 2017 univento.eu - All rights reserved
|
||||
* You are not allowed to use, distribute or modify this code
|
||||
*/
|
||||
|
||||
package eu.univento.commons.player.user;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor(suppressConstructorProperties = true)
|
||||
public class Raw {
|
||||
|
||||
private String name;
|
||||
private String value;
|
||||
private String signature;
|
||||
}
|
24
src/main/java/eu/univento/commons/player/user/Result.java
Normal file
24
src/main/java/eu/univento/commons/player/user/Result.java
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (c) 2017 univento.eu - All rights reserved
|
||||
* You are not allowed to use, distribute or modify this code
|
||||
*/
|
||||
|
||||
package eu.univento.commons.player.user;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 0.1
|
||||
*/
|
||||
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor(suppressConstructorProperties = true)
|
||||
public class Result {
|
||||
|
||||
private String status;
|
||||
private String message;
|
||||
}
|
34
src/main/java/eu/univento/commons/player/user/Textures.java
Normal file
34
src/main/java/eu/univento/commons/player/user/Textures.java
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2017 univento.eu - All rights reserved
|
||||
* You are not allowed to use, distribute or modify this code
|
||||
*/
|
||||
|
||||
package eu.univento.commons.player.user;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor(suppressConstructorProperties = true)
|
||||
public class Textures {
|
||||
|
||||
@JsonProperty("SKIN") private Skin skin;
|
||||
@JsonProperty("CAPE") private Cape cape;
|
||||
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor(suppressConstructorProperties = true)
|
||||
public class Skin {
|
||||
private String url;
|
||||
}
|
||||
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor(suppressConstructorProperties = true)
|
||||
public class Cape {
|
||||
private String url;
|
||||
}
|
||||
}
|
19
src/main/java/eu/univento/commons/player/user/Updated.java
Normal file
19
src/main/java/eu/univento/commons/player/user/Updated.java
Normal file
@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright (c) 2017 univento.eu - All rights reserved
|
||||
* You are not allowed to use, distribute or modify this code
|
||||
*/
|
||||
|
||||
package eu.univento.commons.player.user;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor(suppressConstructorProperties = true)
|
||||
public class Updated {
|
||||
private String time;
|
||||
private String expires;
|
||||
private String zone;
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2017 univento.eu - All rights reserved
|
||||
* You are not allowed to use, distribute or modify this code
|
||||
*/
|
||||
|
||||
package eu.univento.commons.player.user;
|
||||
|
||||
import eu.univento.commons.Commons;
|
||||
import io.vertx.ext.web.client.WebClient;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class UserInformation {
|
||||
|
||||
private static WebClient client;
|
||||
|
||||
public static CompletableFuture<UserInformation> get(String identifier) {
|
||||
CompletableFuture<UserInformation> future = new CompletableFuture<>();
|
||||
if(client == null) client = WebClient.create(Commons.getCommons().getVertx());
|
||||
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;
|
||||
}
|
||||
|
||||
private Result result;
|
||||
private String uuid;
|
||||
private String username;
|
||||
private boolean premium;
|
||||
private List<History> history;
|
||||
|
||||
private UserProperties properties;
|
||||
private Updated updated;
|
||||
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) 2017 univento.eu - All rights reserved
|
||||
* You are not allowed to use, distribute or modify this code
|
||||
*/
|
||||
|
||||
package eu.univento.commons.player.user;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 0.1
|
||||
*/
|
||||
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor(suppressConstructorProperties = true)
|
||||
public class UserProperties {
|
||||
|
||||
private List<Raw> raw;
|
||||
private List<Decoded> decoded;
|
||||
|
||||
}
|
@ -10,12 +10,14 @@ import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* @author codebucketdev
|
||||
*/
|
||||
|
||||
public class NameFetcher {
|
||||
|
||||
private static final JSONParser jsonParser = new JSONParser();
|
||||
private static final String REQUEST_URL = "https://mcapi.de/api/user/";
|
||||
private static final String PROFILE_URL = "https://sessionserver.mojang.com/session/minecraft/profile/";
|
||||
@ -27,7 +29,7 @@ public class NameFetcher {
|
||||
|
||||
String uniqueId = (String) response.get("uuid");
|
||||
if (uniqueId.length() == 0)
|
||||
Commons.getCommons().getLoggingHandler().log("A Username for UUID '" + uuid.toString() + "' was not found in the database! Is the account not premium?");
|
||||
Commons.getCommons().getLogger().log(Level.INFO, "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) {
|
||||
@ -42,12 +44,12 @@ public class NameFetcher {
|
||||
|
||||
String name = (String) response.get("name");
|
||||
if (name == null)
|
||||
Commons.getCommons().getLoggingHandler().log("A Username for UUID '" + uuid.toString() + "' was not found in the database! Is the account not premium?");
|
||||
Commons.getCommons().getLogger().log(Level.INFO, "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(errorMessage);
|
||||
Commons.getCommons().getLogger().log(Level.INFO, errorMessage);
|
||||
}
|
||||
return name;
|
||||
} catch (IOException | ParseException e) {
|
||||
|
@ -44,7 +44,6 @@ public class ServerInfo {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
return future;
|
||||
}
|
||||
|
||||
|
@ -3,29 +3,25 @@ MySQL.Port = 3306
|
||||
MySQL.Username = custo_univento
|
||||
MySQL.Database = customer1479_univento
|
||||
MySQL.Password = zlp7E0#2
|
||||
MongoDB.Host = vps.joethei.de
|
||||
MongoDB.Host = k9.univento.eu
|
||||
MongoDB.Port = 27017
|
||||
MongoDB.Username = univento
|
||||
MongoDB.Password = 8UWUpJt5*v2np&SaR^c&4JjX4@K9WtH3w*#Wb*n3zwQdxA6NR&gV628NuSsJ%y8kwg*r*Ep5VfdZ3dR@Kp7j^@2d4mGdcz!3WtyD
|
||||
MongoDB.Database = univento
|
||||
Redis.Hostname = vps.joethei.de
|
||||
Redis.Hostname = k9.univento.eu
|
||||
Redis.Port = 6379
|
||||
Redis.Password = wVDfDSqay8xyYrMq#QSFnE9Zd@TK7#BT3g&GrE#3vXVa!wG4mEWFguP!b#2@QJPDZHU5Ywdfxwc5sK3Gp35ZZ3AWPUGw@m85FPWU
|
||||
BoardSQL.Host = univento.eu
|
||||
BoardSQL.Port = 3306
|
||||
BoardSQL.Username = forum
|
||||
BoardSQL.Password = 2Ogxk6$5Yvsr4*24
|
||||
BoardSQL.Database = forum
|
||||
TS3.Hostname = vps.joethei.de
|
||||
Redis.Password = h4hAegVn8hBAfRK9Hzp8YHmcJNA7kkbJwKw6Xtm2N9B7QUeZcpZ7XNJhpMsxFHnKcVVNKm9Gvmkz5VGBjsDJ3xFCWMu3b72vCdgv
|
||||
TS3.Hostname = k9.univento.eu
|
||||
TS3.ID = 1
|
||||
TS3.Username = serveradmin
|
||||
TS3.Password = Wb69cypb499CTP4vtaJPKpKZELUbPD
|
||||
Slack.hook_url = https://hooks.slack.com/services/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
|
||||
RabbitMQ.Host = vps.joethei.de
|
||||
RabbitMQ.Port = 5673
|
||||
TS3.Password = PpDDODaq
|
||||
RabbitMQ.Host = k9.univento.eu
|
||||
RabbitMQ.Port = 5672
|
||||
RabbitMQ.Username = univento
|
||||
RabbitMQ.Password = tYRHXZNm4exW@QB6rMm72pHnafrT8wQ5ebGPEetJDBVU2mj25kTVXuYeQavb#EYr
|
||||
RabbitMQ.VirtualHost = univento
|
||||
Gitlab.Host = https://gitlab.com/
|
||||
Gitlab.token = add token here
|
||||
Slack.hook_url = https://hooks.slack.com/services/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
|
||||
api.ai.token = e1c97924577a4743800b3fefb16dd527
|
||||
Sentry.DSN.Commons = http://6b35ae68e540439da1a9b51ab3b2928e:0afbbeccc1a14ae4a10f9ba1775c93b7@sentry.dev.univento.eu/3
|
||||
Sentry.DSN.Core = http://f5b6c0945a334f9398fc5baf89893c00:481956843e3c45b3be9a899f3e5fccb7@sentry.dev.univento.eu/4
|
||||
Sentry.DSN.BungeeCore = http://5e48cd49a4124515aae49dac2b42a317:7c123d87046f47c987c0e2f5adadfd48@sentry.dev.univento.eu/5
|
@ -6,57 +6,71 @@
|
||||
package eu.univento.commons;
|
||||
|
||||
import eu.univento.commons.database.DatabaseManager;
|
||||
import eu.univento.commons.player.user.UserInformation;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.awaitility.Awaitility.await;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 0.1
|
||||
* @version 1.0
|
||||
*/
|
||||
public class CommonsTest {
|
||||
|
||||
/*
|
||||
private Commons commons;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
commons = new Commons();
|
||||
}
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
commons.shutdown();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserInformationName() {
|
||||
try {
|
||||
assertTrue(UserInformation.get("069a79f444e94726a5befca90e38aaf5").get().getUsername().equals("Notch"));
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommons() {
|
||||
Commons commons = new Commons();
|
||||
|
||||
assertNotNull(commons);
|
||||
assertNotNull(commons.getDatabaseManager());
|
||||
assertNotNull(commons.getConfigurationHandler());
|
||||
assertNotNull(commons.getSecurityHandler());
|
||||
assertNotNull(commons.getLoggingHandler());
|
||||
assertNotNull(commons.getSlackHandler());
|
||||
|
||||
commons.shutdown();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDatabaseManager() {
|
||||
Commons commons = new Commons();
|
||||
DatabaseManager db = commons.getDatabaseManager();
|
||||
|
||||
assertNotNull(db.getAsyncMongoDB());
|
||||
assertNotNull(db.getAsyncMySQL());
|
||||
assertNotNull(db.getMongoDB());
|
||||
assertNotNull(db.getMySQL());
|
||||
|
||||
commons.shutdown();
|
||||
assertNotNull(db.getRedis());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSecurityHandler() {
|
||||
Commons commons = new Commons();
|
||||
SecurityHandler security = commons.getSecurityHandler();
|
||||
public void testRedis() {
|
||||
AtomicReference<String> result = new AtomicReference<>();
|
||||
|
||||
assertFalse(security.isValidServer(""));
|
||||
assertFalse(security.isValidServer("8.8.8.8"));
|
||||
assertTrue(security.isValidServer("79.133.48.84"));
|
||||
commons.getDatabaseManager().getRedis().getClient().get("test", event -> {
|
||||
if(event.failed()) event.cause().printStackTrace();
|
||||
result.set(event.result());
|
||||
});
|
||||
|
||||
commons.shutdown();
|
||||
await().until(() -> result.get() != null);
|
||||
assertTrue(result.get().equals("nope"));
|
||||
}
|
||||
*/
|
||||
}
|
Loading…
Reference in New Issue
Block a user