+ new way to get information about other servers in the network
~ refactoring
This commit is contained in:
parent
3782ee31b5
commit
5db8688a1e
@ -1,7 +1,7 @@
|
|||||||
image: maven:3-jdk-8
|
image: maven:3-jdk-8
|
||||||
|
|
||||||
build:
|
build:
|
||||||
script: "mvn clean install deploy --settings .gitlab/settings.xml"
|
script: "mvn clean --settings .gitlab/settings.xml"
|
||||||
artifacts:
|
artifacts:
|
||||||
name: "Commons"
|
name: "Commons"
|
||||||
paths:
|
paths:
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="library" name="Maven: ai.api:libai:1.4.8" level="project" />
|
||||||
<orderEntry type="library" name="Maven: org.projectlombok:lombok:1.14.8" level="project" />
|
<orderEntry type="library" name="Maven: org.projectlombok:lombok:1.14.8" level="project" />
|
||||||
<orderEntry type="library" name="Maven: io.vertx:vertx-core:3.4.1" level="project" />
|
<orderEntry type="library" name="Maven: io.vertx:vertx-core:3.4.1" level="project" />
|
||||||
<orderEntry type="library" name="Maven: io.netty:netty-common:4.1.8.Final" level="project" />
|
<orderEntry type="library" name="Maven: io.netty:netty-common:4.1.8.Final" level="project" />
|
||||||
@ -43,6 +44,7 @@
|
|||||||
<orderEntry type="library" name="Maven: org.mongodb:bson:3.4.1" level="project" />
|
<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: 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: com.rabbitmq:amqp-client:3.6.5" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
|
||||||
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.3.1" level="project" />
|
<orderEntry type="library" name="Maven: com.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.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.google.guava:guava:19.0" level="project" />
|
||||||
@ -53,6 +55,9 @@
|
|||||||
<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-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.apache.logging.log4j:log4j-core:2.6.2" level="project" />
|
||||||
<orderEntry type="library" name="Maven: com.github.nsp:JSkills:master-0.9.0-g8b333ec-15" level="project" />
|
<orderEntry type="library" name="Maven: 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: junit:junit:4.12" level="project" />
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" 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" name="Maven: org.gitlab:java-gitlab-api:1.2.7" level="project" />
|
||||||
|
17
pom.xml
17
pom.xml
@ -11,6 +11,10 @@
|
|||||||
<description>Das Commons Modul stellt alles zur Verfügung was von allen anderen Modulen benötigt wird, wie etwa Datenbank Zugriffe</description>
|
<description>Das Commons Modul stellt alles zur Verfügung was von allen anderen Modulen benötigt wird, wie etwa Datenbank Zugriffe</description>
|
||||||
<url>https://development.univento.eu/docs/Commons</url>
|
<url>https://development.univento.eu/docs/Commons</url>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
<organization>
|
<organization>
|
||||||
<name>univentoEU</name>
|
<name>univentoEU</name>
|
||||||
<url>https://univento.eu</url>
|
<url>https://univento.eu</url>
|
||||||
@ -120,6 +124,12 @@
|
|||||||
</build>
|
</build>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>ai.api</groupId>
|
||||||
|
<artifactId>libai</artifactId>
|
||||||
|
<version>1.4.8</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
@ -150,6 +160,13 @@
|
|||||||
<artifactId>vertx-rabbitmq-client</artifactId>
|
<artifactId>vertx-rabbitmq-client</artifactId>
|
||||||
<version>3.4.1</version>
|
<version>3.4.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-api</artifactId>
|
||||||
|
<version>1.7.25</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.code.gson</groupId>
|
<groupId>com.google.code.gson</groupId>
|
||||||
<artifactId>gson</artifactId>
|
<artifactId>gson</artifactId>
|
||||||
|
@ -27,8 +27,8 @@ public class Commons {
|
|||||||
commons = this;
|
commons = this;
|
||||||
vertx = Vertx.vertx();
|
vertx = Vertx.vertx();
|
||||||
configurationHandler = new ConfigurationHandler();
|
configurationHandler = new ConfigurationHandler();
|
||||||
databaseManager = new DatabaseManager();
|
|
||||||
messagingManager = new MessagingManager();
|
messagingManager = new MessagingManager();
|
||||||
|
databaseManager = new DatabaseManager();
|
||||||
loggingHandler = new LoggingHandler();
|
loggingHandler = new LoggingHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,8 +12,6 @@ import lombok.Data;
|
|||||||
@Data
|
@Data
|
||||||
public class DatabaseManager {
|
public class DatabaseManager {
|
||||||
|
|
||||||
//TODO: add board sql back, when forum is online.
|
|
||||||
|
|
||||||
private MongoDB mongoDB;
|
private MongoDB mongoDB;
|
||||||
private MySQL mySQL;
|
private MySQL mySQL;
|
||||||
private Redis redis;
|
private Redis redis;
|
||||||
|
@ -17,5 +17,4 @@ public class MongoDB {
|
|||||||
client = MongoClient.createShared(Commons.getCommons().getVertx(),
|
client = MongoClient.createShared(Commons.getCommons().getVertx(),
|
||||||
new JsonObject().put("host", host).put("port", port).put("username", username).put("password", password).put("db_name", databaseName));
|
new JsonObject().put("host", host).put("port", port).put("username", username).put("password", password).put("db_name", databaseName));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,10 +1,13 @@
|
|||||||
package eu.univento.commons.helpers;
|
package eu.univento.commons.helpers;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author joethei
|
* @author joethei
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@Getter
|
||||||
public class Location {
|
public class Location {
|
||||||
|
|
||||||
private final String world;
|
private final String world;
|
||||||
@ -22,28 +25,4 @@ public class Location {
|
|||||||
this.pitch = pitch;
|
this.pitch = pitch;
|
||||||
this.yaw = yaw;
|
this.yaw = yaw;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getWorld() {
|
|
||||||
return world;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getX() {
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getY() {
|
|
||||||
return y;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getZ() {
|
|
||||||
return z;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getPitch() {
|
|
||||||
return pitch;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getYaw() {
|
|
||||||
return yaw;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
package eu.univento.commons.logging;
|
package eu.univento.commons.logging;
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import eu.univento.commons.messaging.MessageHandler;
|
||||||
import org.apache.logging.log4j.Logger;
|
import eu.univento.commons.server.ServerType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author joethei
|
* @author joethei
|
||||||
@ -10,36 +10,9 @@ import org.apache.logging.log4j.Logger;
|
|||||||
|
|
||||||
public class LoggingHandler {
|
public class LoggingHandler {
|
||||||
|
|
||||||
public Logger getCommons() {
|
public LoggingHandler() {}
|
||||||
return LogManager.getLogger("Commons");
|
|
||||||
}
|
|
||||||
|
|
||||||
public Logger getCore() {
|
public void log(ServerType type, String message) {
|
||||||
return LogManager.getLogger("Core");
|
MessageHandler.sendMessage("log." + type.getName(), message);
|
||||||
}
|
|
||||||
|
|
||||||
public Logger getBungeeCore() {
|
|
||||||
return LogManager.getLogger("BungeeCore");
|
|
||||||
}
|
|
||||||
|
|
||||||
public Logger getLobby() {
|
|
||||||
return LogManager.getLogger("Lobby");
|
|
||||||
}
|
|
||||||
|
|
||||||
public Logger getTrashGames() {
|
|
||||||
return LogManager.getLogger("TrashGames");
|
|
||||||
}
|
|
||||||
|
|
||||||
public Logger getTeamVento() {
|
|
||||||
return LogManager.getLogger("TeamVento");
|
|
||||||
}
|
|
||||||
|
|
||||||
public Logger getCloudCommons() {return LogManager.getLogger("CloudCommons");}
|
|
||||||
|
|
||||||
public Logger getCloudDaemon() {return LogManager.getLogger("CloudDaemon");}
|
|
||||||
|
|
||||||
public Logger getCloudMaster() {return LogManager.getLogger("CloudMaster");}
|
|
||||||
|
|
||||||
public LoggingHandler() {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -22,23 +22,23 @@ public class MessageHandler {
|
|||||||
|
|
||||||
public static void registerListener(String queue, MessageEvent event) {
|
public static void registerListener(String queue, MessageEvent event) {
|
||||||
events.add(event);
|
events.add(event);
|
||||||
Commons.getCommons().getMessagingManager().getRabbitMQ().getClient().basicConsume(queue, "univento." + queue, res -> {
|
Commons.getCommons().getVertx().eventBus().consumer(queue, msg -> {
|
||||||
if(!res.succeeded()) res.cause().printStackTrace();
|
JsonObject json = (JsonObject) msg.body();
|
||||||
|
event.onMessageReceived(queue, json.getString("body"));
|
||||||
});
|
});
|
||||||
|
|
||||||
Commons.getCommons().getVertx().eventBus().consumer(queue, msg -> {
|
Commons.getCommons().getMessagingManager().start().whenComplete((rabbitMQ, throwable) -> rabbitMQ.getClient().basicConsume(queue, queue, res -> {
|
||||||
JsonObject json = (JsonObject) msg.body();
|
if(!res.succeeded()) res.cause().printStackTrace();
|
||||||
event.onMessageReceived(queue, json.getString("body"));
|
}));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendMessage(String queue, String message) {
|
public static void sendMessage(String queue, String message) {
|
||||||
Commons.getCommons().getMessagingManager().getRabbitMQ().getClient().basicPublish("", queue, new JsonObject().put("body", message), res -> {
|
Commons.getCommons().getMessagingManager().start().whenComplete((rabbitMQ, throwable) -> rabbitMQ.getClient().basicPublish("", queue, new JsonObject().put("body", message), res -> {
|
||||||
if(res.succeeded()) {
|
if(res.succeeded()) {
|
||||||
for(MessageEvent event : events) {
|
for(MessageEvent event : events) {
|
||||||
event.onMessageSend(queue, message);
|
event.onMessageSend(queue, message);
|
||||||
}
|
}
|
||||||
}else res.cause().printStackTrace();
|
}else res.cause().printStackTrace();
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,7 +7,8 @@ package eu.univento.commons.messaging;
|
|||||||
|
|
||||||
import eu.univento.commons.Commons;
|
import eu.univento.commons.Commons;
|
||||||
import eu.univento.commons.configuration.ConfigurationHandler;
|
import eu.univento.commons.configuration.ConfigurationHandler;
|
||||||
import lombok.Getter;
|
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author joethei
|
* @author joethei
|
||||||
@ -15,7 +16,6 @@ import lombok.Getter;
|
|||||||
*/
|
*/
|
||||||
public class MessagingManager {
|
public class MessagingManager {
|
||||||
|
|
||||||
@Getter
|
|
||||||
private RabbitMQ rabbitMQ;
|
private RabbitMQ rabbitMQ;
|
||||||
|
|
||||||
public MessagingManager() {
|
public MessagingManager() {
|
||||||
@ -23,4 +23,17 @@ public class MessagingManager {
|
|||||||
rabbitMQ = new RabbitMQ(config.getString("RabbitMQ.Host"), config.getInteger("RabbitMQ.Port"),
|
rabbitMQ = new RabbitMQ(config.getString("RabbitMQ.Host"), config.getInteger("RabbitMQ.Port"),
|
||||||
config.getString("RabbitMQ.Username"), config.getString("RabbitMQ.Password"), config.getString("RabbitMQ.VirtualHost"));
|
config.getString("RabbitMQ.Username"), config.getString("RabbitMQ.Password"), config.getString("RabbitMQ.VirtualHost"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CompletableFuture<RabbitMQ> start() {
|
||||||
|
CompletableFuture<RabbitMQ> future = new CompletableFuture<>();
|
||||||
|
if(rabbitMQ.getClient().isConnected()) future.complete(rabbitMQ);
|
||||||
|
|
||||||
|
rabbitMQ.getClient().start(res -> {
|
||||||
|
if(res.failed()) res.cause().printStackTrace();
|
||||||
|
else future.complete(rabbitMQ);
|
||||||
|
});
|
||||||
|
|
||||||
|
return future;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -19,8 +19,8 @@ public class RabbitMQ {
|
|||||||
@Getter private RabbitMQClient client;
|
@Getter private RabbitMQClient client;
|
||||||
|
|
||||||
public RabbitMQ(String host, int port, String user, String password, String virtualHost) {
|
public RabbitMQ(String host, int port, String user, String password, String virtualHost) {
|
||||||
JsonObject config = new JsonObject().put("host", host).put("port", port).put("user", user).put("password", password).put("virtualHost", virtualHost).put("connectionTimeout", 60)
|
JsonObject config = new JsonObject().put("host", host).put("port", port).put("user", user).put("password", password).put("virtualHost", virtualHost).put("connectionTimeout", 600)
|
||||||
.put("requestedHeartbeat", 60).put("handshakeTimeout", 60).put("requestedChannelMax", 5).put("networkRecoveryInterval", 5).put("automaticRecoveryEnabled", true);
|
.put("requestedHeartbeat", 60).put("handshakeTimeout", 600).put("requestedChannelMax", 5).put("networkRecoveryInterval", 5).put("automaticRecoveryEnabled", true);
|
||||||
client = RabbitMQClient.create(Commons.getCommons().getVertx(), config);
|
client = RabbitMQClient.create(Commons.getCommons().getVertx(), config);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -37,6 +37,7 @@ public class DatabasePlayer {
|
|||||||
|
|
||||||
private Rank rank;
|
private Rank rank;
|
||||||
private PlayerSettings settings;
|
private PlayerSettings settings;
|
||||||
|
private Language language;
|
||||||
private boolean muted;
|
private boolean muted;
|
||||||
|
|
||||||
public DatabasePlayer(UUID uuid, String name) {
|
public DatabasePlayer(UUID uuid, String name) {
|
||||||
@ -48,22 +49,24 @@ public class DatabasePlayer {
|
|||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Language getLanguage() {
|
public Language getLanguage() {
|
||||||
return Language.getLanguage(Locale.forLanguageTag(getSettings().getLanguage()));
|
return Language.getLanguage(getSettings().getLanguage());
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompletableFuture<Language> getLanguageAsync() {
|
public CompletableFuture<Language> getLanguageAsync() {
|
||||||
CompletableFuture<Language> future = new CompletableFuture<>();
|
CompletableFuture<Language> future = new CompletableFuture<>();
|
||||||
getSettingsAsync().whenComplete((playerSettings, throwable) -> future.complete(Language.getLanguage(Locale.forLanguageTag(playerSettings.getLanguage()))));
|
getSettingsAsync().whenComplete((playerSettings, throwable) -> future.complete(Language.getLanguage(playerSettings.getLanguage())));
|
||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public CompletableFuture<PlayerSettings> getSettingsAsync() {
|
public CompletableFuture<PlayerSettings> getSettingsAsync() {
|
||||||
CompletableFuture<PlayerSettings> future = new CompletableFuture<>();
|
CompletableFuture<PlayerSettings> future = new CompletableFuture<>();
|
||||||
getObjectFromDatabase("Settings").whenComplete((entries, throwable) -> future.complete(new PlayerSettings(this, entries)));
|
getObjectFromDatabase("Settings").whenComplete((entries, throwable) ->
|
||||||
|
future.complete(new PlayerSettings(this, entries.getJsonObject("Settings"))));
|
||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,13 +97,7 @@ public class DatabasePlayer {
|
|||||||
|
|
||||||
MongoClient client = Commons.getCommons().getDatabaseManager().getMongoDB().getClient();
|
MongoClient client = Commons.getCommons().getDatabaseManager().getMongoDB().getClient();
|
||||||
client.insert("bans", obj, res -> {
|
client.insert("bans", obj, res -> {
|
||||||
if (res.failed()) {
|
if (res.failed()) res.cause().printStackTrace();
|
||||||
try {
|
|
||||||
throw res.cause();
|
|
||||||
} catch (Throwable throwable1) {
|
|
||||||
throwable1.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -110,7 +107,9 @@ public class DatabasePlayer {
|
|||||||
CompletableFuture<BanData> future = new CompletableFuture<>();
|
CompletableFuture<BanData> future = new CompletableFuture<>();
|
||||||
MongoClient client = Commons.getCommons().getDatabaseManager().getMongoDB().getClient();
|
MongoClient client = Commons.getCommons().getDatabaseManager().getMongoDB().getClient();
|
||||||
client.findOne("bans", new JsonObject().put("uuid", uuid.toString()), null, res -> {
|
client.findOne("bans", new JsonObject().put("uuid", uuid.toString()), null, res -> {
|
||||||
|
if(res.failed()) future.complete(null);
|
||||||
JsonObject result = res.result();
|
JsonObject result = res.result();
|
||||||
|
if(result.isEmpty()) future.complete(null);
|
||||||
BanData data = new BanData(BanReason.valueOf(result.getString("reason")),
|
BanData data = new BanData(BanReason.valueOf(result.getString("reason")),
|
||||||
UUID.fromString(result.getString("banner")),
|
UUID.fromString(result.getString("banner")),
|
||||||
result.getString("customMessage"),
|
result.getString("customMessage"),
|
||||||
@ -323,7 +322,7 @@ public class DatabasePlayer {
|
|||||||
public CompletableFuture<Boolean> hasPlayedBefore() {
|
public CompletableFuture<Boolean> hasPlayedBefore() {
|
||||||
CompletableFuture<Boolean> future = new CompletableFuture<>();
|
CompletableFuture<Boolean> future = new CompletableFuture<>();
|
||||||
MongoClient client = Commons.getCommons().getDatabaseManager().getMongoDB().getClient();
|
MongoClient client = Commons.getCommons().getDatabaseManager().getMongoDB().getClient();
|
||||||
client.findOne("players", new JsonObject().put("uuid", uuid.toString()), new JsonObject("uuid"), res -> future.complete(res.succeeded()));
|
client.findOne("players", new JsonObject().put("uuid", uuid.toString()), null, res -> future.complete(res.succeeded()));
|
||||||
|
|
||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
@ -342,65 +341,49 @@ public class DatabasePlayer {
|
|||||||
|
|
||||||
public CompletableFuture<Instant> getFirstLogin() {
|
public CompletableFuture<Instant> getFirstLogin() {
|
||||||
CompletableFuture<Instant> future = new CompletableFuture<>();
|
CompletableFuture<Instant> future = new CompletableFuture<>();
|
||||||
getObjectFromDatabase("firstLogin").whenComplete((entries, throwable) -> {
|
getObjectFromDatabase("firstLogin").whenComplete((entries, throwable) -> future.complete(entries.getInstant("firstLogin")));
|
||||||
future.complete(entries.getInstant("firstLogin"));
|
|
||||||
});
|
|
||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompletableFuture<Instant> getLastLogin() {
|
public CompletableFuture<Instant> getLastLogin() {
|
||||||
CompletableFuture<Instant> future = new CompletableFuture<>();
|
CompletableFuture<Instant> future = new CompletableFuture<>();
|
||||||
getObjectFromDatabase("lastLogin").whenComplete((entries, throwable) -> {
|
getObjectFromDatabase("lastLogin").whenComplete((entries, throwable) -> future.complete(entries.getInstant("lastLogin")));
|
||||||
future.complete(entries.getInstant("lastLogin"));
|
|
||||||
});
|
|
||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompletableFuture<Instant> getLastOnline() {
|
public CompletableFuture<Instant> getLastOnline() {
|
||||||
CompletableFuture<Instant> future = new CompletableFuture<>();
|
CompletableFuture<Instant> future = new CompletableFuture<>();
|
||||||
getObjectFromDatabase("lastOnline").whenComplete((entries, throwable) -> {
|
getObjectFromDatabase("lastOnline").whenComplete((entries, throwable) -> future.complete(entries.getInstant("lastOnline")));
|
||||||
future.complete(entries.getInstant("lastOnline"));
|
|
||||||
});
|
|
||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompletableFuture<String> getLastIP() {
|
public CompletableFuture<String> getLastIP() {
|
||||||
CompletableFuture<String> future = new CompletableFuture<>();
|
CompletableFuture<String> future = new CompletableFuture<>();
|
||||||
getObjectFromDatabase("lastIP").whenComplete((entries, throwable) -> {
|
getObjectFromDatabase("lastIP").whenComplete((entries, throwable) -> future.complete(entries.getString("lastIP")));
|
||||||
future.complete(entries.getString("lastIP"));
|
|
||||||
});
|
|
||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompletableFuture<String> getTSID() {
|
public CompletableFuture<String> getTSID() {
|
||||||
CompletableFuture<String> future = new CompletableFuture<>();
|
CompletableFuture<String> future = new CompletableFuture<>();
|
||||||
getObjectFromDatabase("tsid").whenComplete((entries, throwable) -> {
|
getObjectFromDatabase("tsid").whenComplete((entries, throwable) -> future.complete(entries.getString("tsid")));
|
||||||
future.complete(entries.getString("tsid"));
|
|
||||||
});
|
|
||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompletableFuture<Integer> getTimesJoined() {
|
public CompletableFuture<Integer> getTimesJoined() {
|
||||||
CompletableFuture<Integer> future = new CompletableFuture<>();
|
CompletableFuture<Integer> future = new CompletableFuture<>();
|
||||||
getObjectFromDatabase("timesJoined").whenComplete((entries, throwable) -> {
|
getObjectFromDatabase("timesJoined").whenComplete((entries, throwable) -> future.complete(entries.getInteger("TimesJoined")));
|
||||||
future.complete(entries.getInteger("TimesJoined"));
|
|
||||||
});
|
|
||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompletableFuture<Integer> getCoins() {
|
public CompletableFuture<Integer> getCoins() {
|
||||||
CompletableFuture<Integer> future = new CompletableFuture<>();
|
CompletableFuture<Integer> future = new CompletableFuture<>();
|
||||||
getObjectFromDatabase("coins").whenComplete((entries, throwable) -> {
|
getObjectFromDatabase("coins").whenComplete((entries, throwable) -> future.complete(entries.getInteger("coins")));
|
||||||
future.complete(entries.getInteger("coins"));
|
|
||||||
});
|
|
||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompletableFuture<Integer> getExperience() {
|
public CompletableFuture<Integer> getExperience() {
|
||||||
CompletableFuture<Integer> future = new CompletableFuture<>();
|
CompletableFuture<Integer> future = new CompletableFuture<>();
|
||||||
getObjectFromDatabase("experience").whenComplete((entries, throwable) -> {
|
getObjectFromDatabase("experience").whenComplete((entries, throwable) -> future.complete(entries.getInteger("experience")));
|
||||||
future.complete(entries.getInteger("experience"));
|
|
||||||
});
|
|
||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -482,7 +465,7 @@ public class DatabasePlayer {
|
|||||||
|
|
||||||
public void setInDatabase(String name, Object obj) {
|
public void setInDatabase(String name, Object obj) {
|
||||||
MongoClient client = Commons.getCommons().getDatabaseManager().getMongoDB().getClient();
|
MongoClient client = Commons.getCommons().getDatabaseManager().getMongoDB().getClient();
|
||||||
client.findOneAndUpdate("players", new JsonObject().put("uuid", uuid.toString()),
|
client.update("players", new JsonObject().put("uuid", uuid.toString()),
|
||||||
new JsonObject().put("$set", new JsonObject().put(name, obj)), res -> {
|
new JsonObject().put("$set", new JsonObject().put(name, obj)), res -> {
|
||||||
if (res.failed()) {
|
if (res.failed()) {
|
||||||
try {
|
try {
|
||||||
|
@ -37,11 +37,11 @@ public class Language {
|
|||||||
Commons.getCommons().getDatabaseManager().getMySQL().getClient().getConnection(res -> {
|
Commons.getCommons().getDatabaseManager().getMySQL().getClient().getConnection(res -> {
|
||||||
if(res.succeeded()) {
|
if(res.succeeded()) {
|
||||||
SQLConnection connection = res.result();
|
SQLConnection connection = res.result();
|
||||||
connection.query("SELECT identifier, " + locale.getISO3Language() + " FROM translations;", result -> {
|
connection.query("SELECT identifier, " + locale.getLanguage() + " FROM translations;", result -> {
|
||||||
if(result.succeeded()) {
|
if(result.succeeded()) {
|
||||||
ResultSet rs = result.result();
|
ResultSet rs = result.result();
|
||||||
for(JsonObject json : rs.getRows()) {
|
for(JsonObject json : rs.getRows()) {
|
||||||
translations.put(json.getString("translations"), json.getString(locale.getISO3Language()));
|
translations.put(json.getString("identifier"), json.getString(locale.getLanguage()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}else result.cause().printStackTrace();
|
}else result.cause().printStackTrace();
|
||||||
@ -50,9 +50,9 @@ public class Language {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Language getLanguage(Locale locale) {
|
public static Language getLanguage(String locale) {
|
||||||
for(Language language : languages) {
|
for(Language language : languages) {
|
||||||
if(language.getLocale().equals(locale)) return language;
|
if(language.getLocale().getLanguage().equals(locale)) return language;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -61,7 +61,7 @@ public class Language {
|
|||||||
return getWord(constant.getName());
|
return getWord(constant.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getWord(String constant) {
|
public String getWord(String identifier) {
|
||||||
return translations.get(constant);
|
return translations.get(identifier);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -69,8 +69,6 @@ public class PlayerSettings {
|
|||||||
return json.getBoolean("nicked");
|
return json.getBoolean("nicked");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void setPlayerVisibility(String visibility) {
|
public void setPlayerVisibility(String visibility) {
|
||||||
json.put("playerVisibility", visibility);
|
json.put("playerVisibility", visibility);
|
||||||
update();
|
update();
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package eu.univento.commons.player.uuid;
|
package eu.univento.commons.player.uuid;
|
||||||
|
|
||||||
import eu.univento.commons.Commons;
|
import eu.univento.commons.Commons;
|
||||||
|
import eu.univento.commons.server.ServerType;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
import org.json.simple.parser.JSONParser;
|
import org.json.simple.parser.JSONParser;
|
||||||
import org.json.simple.parser.ParseException;
|
import org.json.simple.parser.ParseException;
|
||||||
@ -27,7 +28,7 @@ public class NameFetcher {
|
|||||||
|
|
||||||
String uniqueId = (String) response.get("uuid");
|
String uniqueId = (String) response.get("uuid");
|
||||||
if (uniqueId.length() == 0)
|
if (uniqueId.length() == 0)
|
||||||
Commons.getCommons().getLoggingHandler().getCommons().error("A Username for UUID '" + uuid.toString() + "' was not found in the database! Is the account not premium?");
|
Commons.getCommons().getLoggingHandler().log(ServerType.getServerType() ,"A Username for UUID '" + uuid.toString() + "' was not found in the database! Is the account not premium?");
|
||||||
|
|
||||||
return (String) response.get("username");
|
return (String) response.get("username");
|
||||||
} catch (IOException |ParseException e) {
|
} catch (IOException |ParseException e) {
|
||||||
@ -42,17 +43,17 @@ public class NameFetcher {
|
|||||||
|
|
||||||
String name = (String) response.get("name");
|
String name = (String) response.get("name");
|
||||||
if (name == null)
|
if (name == null)
|
||||||
Commons.getCommons().getLoggingHandler().getCommons().error("A Username for UUID '" + uuid.toString() + "' was not found in the database! Is the account not premium?");
|
Commons.getCommons().getLoggingHandler().log(ServerType.getServerType(),"A Username for UUID '" + uuid.toString() + "' was not found in the database! Is the account not premium?");
|
||||||
|
|
||||||
String cause = (String) response.get("cause");
|
String cause = (String) response.get("cause");
|
||||||
String errorMessage = (String) response.get("errorMessage");
|
String errorMessage = (String) response.get("errorMessage");
|
||||||
if (cause != null && cause.length() > 0) {
|
if (cause != null && cause.length() > 0) {
|
||||||
Commons.getCommons().getLoggingHandler().getCommons().error(errorMessage);
|
Commons.getCommons().getLoggingHandler().log(ServerType.getServerType(), errorMessage);
|
||||||
}
|
}
|
||||||
return name;
|
return name;
|
||||||
} catch (IOException | ParseException e) {
|
} catch (IOException | ParseException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Commons.getCommons().getLoggingHandler().getCommons().error("A Username for UUID '" + uuid.toString() + "' was not found in the database! Is the account not premium?");
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
46
src/main/java/eu/univento/commons/server/ServerInfo.java
Normal file
46
src/main/java/eu/univento/commons/server/ServerInfo.java
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
package eu.univento.commons.server;
|
||||||
|
|
||||||
|
import eu.univento.commons.event.MessageEvent;
|
||||||
|
import eu.univento.commons.messaging.MessageHandler;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author joethei
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Getter
|
||||||
|
public class ServerInfo {
|
||||||
|
|
||||||
|
public static CompletableFuture<ServerInfo> getServerInfo(String server) {
|
||||||
|
CompletableFuture<ServerInfo> future = new CompletableFuture<>();
|
||||||
|
UUID uuid = UUID.randomUUID();
|
||||||
|
MessageHandler.sendMessage("cloud.servers", uuid.toString() + "|INFO|" + server);
|
||||||
|
MessageHandler.registerListener("cloud.servers", new MessageEvent() {
|
||||||
|
@Override
|
||||||
|
public void onMessageReceived(String queue, String message) {
|
||||||
|
String[] info = message.split(Pattern.quote("|"));
|
||||||
|
if(info[0].equals(uuid.toString())) {
|
||||||
|
future.complete(new ServerInfo(info[1], ServerType.valueOf(info[2]), Integer.getInteger(info[3])));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onMessageSend(String queue, String message) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return future;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
private ServerType type;
|
||||||
|
private int players;
|
||||||
|
|
||||||
|
}
|
@ -1,16 +1,24 @@
|
|||||||
package eu.univento.commons.server;
|
package eu.univento.commons.server;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author joethei
|
* @author joethei
|
||||||
* @version 0.1
|
* @version 1.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@Getter
|
||||||
public enum ServerType {
|
public enum ServerType {
|
||||||
LOBBY(0, "Lobby", "§6Lobby"),
|
NONE(0, "None", "None"),
|
||||||
SECRET_GAME_FREE4ALL(1, "Free4All", "§6Free4All"),
|
PROXY(1, "Proxy", "§6Proxy"),
|
||||||
SECRET_GAME_TRASHGAMES(2, "TrashGames", "§6TrashGames"),
|
LOBBY(2, "Lobby", "§6Lobby"),
|
||||||
GAME_WOOLGET(3, "WoolGet", "§6WoolGet"),
|
TEAM_BUILD(3, "TeamVento", "§6TeamVento"),
|
||||||
GAME_MAYA(4, "Maya", "§6Maya");
|
SECRET_GAME_FREE4ALL(4, "Free4All", "§6Free4All"),
|
||||||
|
SECRET_GAME_TRASHGAMES(5, "TrashGames", "§6TrashGames"),
|
||||||
|
GAME_WOOLGET(6, "WoolGet", "§6WoolGet"),
|
||||||
|
GAME_MAYA(7, "Maya", "§6Maya"),
|
||||||
|
GAME_IMPACT(8, "Impact", "§6Impact");
|
||||||
|
|
||||||
private int id;
|
private int id;
|
||||||
private String name;
|
private String name;
|
||||||
@ -21,16 +29,5 @@ public enum ServerType {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
this.prefix = prefix;
|
this.prefix = prefix;
|
||||||
}
|
}
|
||||||
|
@Getter @Setter private static ServerType serverType;
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPrefix() {
|
|
||||||
return prefix;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getID() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
}
|
}
|
12
src/main/main.iml
Normal file
12
src/main/main.iml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/java" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="library" name="target" level="project" />
|
||||||
|
</component>
|
||||||
|
</module>
|
@ -22,9 +22,10 @@ TS3.Username = serveradmin
|
|||||||
TS3.Password = Wb69cypb499CTP4vtaJPKpKZELUbPD
|
TS3.Password = Wb69cypb499CTP4vtaJPKpKZELUbPD
|
||||||
Slack.hook_url = https://hooks.slack.com/services/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
|
Slack.hook_url = https://hooks.slack.com/services/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
|
||||||
RabbitMQ.Host = vps.joethei.de
|
RabbitMQ.Host = vps.joethei.de
|
||||||
RabbitMQ.Port = 5672
|
RabbitMQ.Port = 5673
|
||||||
RabbitMQ.Username = univento
|
RabbitMQ.Username = univento
|
||||||
RabbitMQ.Password = tYRHXZNm4exW@QB6rMm72pHnafrT8wQ5ebGPEetJDBVU2mj25kTVXuYeQavb#EYr
|
RabbitMQ.Password = tYRHXZNm4exW@QB6rMm72pHnafrT8wQ5ebGPEetJDBVU2mj25kTVXuYeQavb#EYr
|
||||||
RabbitMQ.VirtualHost = univento
|
RabbitMQ.VirtualHost = univento
|
||||||
Gitlab.Host = https://gitlab.com/
|
Gitlab.Host = https://gitlab.com/
|
||||||
Gitlab.token = add token here
|
Gitlab.token = add token here
|
||||||
|
api.ai.token = e1c97924577a4743800b3fefb16dd527
|
13
src/test/test.iml
Normal file
13
src/test/test.iml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/java" isTestSource="true" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="library" name="target" level="project" />
|
||||||
|
<orderEntry type="module" module-name="main" />
|
||||||
|
</component>
|
||||||
|
</module>
|
Loading…
x
Reference in New Issue
Block a user