50 lines
1.4 KiB
Java
50 lines
1.4 KiB
Java
/*
|
|
* Copyright (c) 2017 univento.eu - All rights reserved
|
|
* You are not allowed to use, distribute or modify this code
|
|
*/
|
|
|
|
package eu.univento.commons.server;
|
|
|
|
import eu.univento.commons.event.MessageEvent;
|
|
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 {
|
|
|
|
private String name;
|
|
private ServerType type;
|
|
private int players;
|
|
|
|
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;
|
|
}
|
|
|
|
} |