Commons/src/main/java/eu/univento/commons/player/party/PartyManager.java

53 lines
2.2 KiB
Java
Raw Normal View History

2017-08-14 12:06:33 +02:00
/*
2018-01-15 12:23:58 +01:00
* Copyright (c) 2018 univento.eu - All rights reserved
2017-08-14 12:06:33 +02:00
* 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()) {
2018-01-15 12:23:58 +01:00
getParty(UUID.fromString(res.result().getString("id"))).whenComplete((party, throwable) -> future.complete(party));
2017-08-14 12:06:33 +02:00
}
});
return future;
}
public CompletableFuture<Boolean> isInParty(DatabasePlayer player) {
CompletableFuture<Boolean> future = new CompletableFuture<>();
getParty(player).whenComplete((party, throwable) -> future.complete(party != null));
return future;
}
}