53 lines
2.2 KiB
Java
53 lines
2.2 KiB
Java
/*
|
|
* Copyright (c) 2018 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;
|
|
}
|
|
} |