use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.
the class SQLDispatcherTest method listFixed.
private void listFixed(PartiesSQLDispatcher dispatcher, PartiesDao dao) {
PartyImpl party = initializeParty(mockPlugin, UUID.randomUUID());
party.setAccessible(true);
party.setup("test3", null);
party.setDescription("description");
party.setAccessible(false);
assertEquals(dao.countAll(), 1);
dispatcher.updateParty(party);
assertEquals(dao.countAll(), 2);
assertEquals(party, dispatcher.getParty(party.getId()));
assertEquals(party, dispatcher.getPartyByName(party.getName()));
Set<PartyImpl> list = dispatcher.getListFixed();
assertEquals(1, list.size());
assertEquals(party, list.iterator().next());
}
use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.
the class SQLDispatcherTest method insertOneParty.
private void insertOneParty(PartiesSQLDispatcher dispatcher, String partyName, int numberOfPlayers, int kills, double experience) {
PartyImpl mockParty = mock(PartyImpl.class);
doReturn(CompletableFuture.completedFuture(null)).when(mockParty).updateParty();
PartyPlayerImpl mockPlayer = mock(PartyPlayerImpl.class);
doReturn(CompletableFuture.completedFuture(null)).when(mockPlayer).updatePlayer();
PartyImpl party = initializeParty(mockPlugin, UUID.randomUUID());
Set<UUID> members = new HashSet<>();
for (int c = 0; c < numberOfPlayers; c++) {
PartyPlayerImpl player = initializePlayer(mockPlugin, UUID.randomUUID());
members.add(player.getPlayerUUID());
player.setAccessible(true);
player.setPartyId(party.getId());
player.setAccessible(false);
dispatcher.updatePlayer(player);
}
party.setAccessible(true);
party.setup(partyName, members.iterator().next().toString());
party.setKills(kills);
party.setExperience(experience);
party.setMembers(members);
party.setAccessible(false);
dispatcher.updateParty(party);
}
use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.
the class SQLDispatcherTest method listPartiesByName.
private void listPartiesByName(PartiesSQLDispatcher dispatcher) {
ConfigParties.ADDITIONAL_LIST_HIDDENPARTIES = Collections.singletonList("test2");
List<PartyImpl> list = new LinkedList<>(dispatcher.getListParties(PartiesDatabaseManager.ListOrder.NAME, 100, 0));
assertEquals(8, list.size());
assertEquals("test1", list.get(0).getName());
assertEquals("test3", list.get(1).getName());
assertEquals("test8", list.get(6).getName());
assertEquals("zlast", list.get(7).getName());
list = new LinkedList<>(dispatcher.getListParties(PartiesDatabaseManager.ListOrder.NAME, 1, 0));
assertEquals(1, list.size());
assertEquals("test1", list.get(0).getName());
list = new LinkedList<>(dispatcher.getListParties(PartiesDatabaseManager.ListOrder.NAME, 1, 1));
assertEquals(1, list.size());
assertEquals("test3", list.get(0).getName());
// Filter by id instead of name
PartyImpl firstParty = list.get(0);
ConfigParties.ADDITIONAL_LIST_HIDDENPARTIES = Arrays.asList("test2", firstParty.getId().toString());
list = new LinkedList<>(dispatcher.getListParties(PartiesDatabaseManager.ListOrder.NAME, 100, 0));
assertEquals(7, list.size());
assertNotEquals(firstParty, list.get(0));
}
use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.
the class PartyManager method loadParty.
public PartyImpl loadParty(UUID id, boolean syncServers) {
// Get the party and save it into the party list
PartyImpl ret = getParty(id);
addPartyToCache(ret);
return ret;
}
use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.
the class PartyInviteImpl method accept.
@Override
public void accept(boolean sendMessages) {
if (party.getInviteRequests().remove(this) && invitedPlayer.getPendingInvites().remove(this)) {
// Calling API Event
IPlayerPreJoinEvent partiesPreJoinEvent = plugin.getEventManager().preparePlayerPreJoinEvent(invitedPlayer, party, JoinCause.INVITE, inviter);
plugin.getEventManager().callEvent(partiesPreJoinEvent);
if (!partiesPreJoinEvent.isCancelled()) {
boolean success = ((PartyImpl) party).addMember(invitedPlayer, JoinCause.INVITE, ((PartyPlayerImpl) inviter));
if (success) {
if (sendMessages) {
((PartyPlayerImpl) invitedPlayer).sendMessage(Messages.MAINCMD_INVITE_ACCEPT_ACCEPTED, (PartyPlayerImpl) inviter, (PartyImpl) party);
if (inviter != null) {
((PartyPlayerImpl) inviter).sendMessage(Messages.MAINCMD_INVITE_ACCEPT_RECEIPT, (PartyPlayerImpl) invitedPlayer, (PartyImpl) party);
}
party.broadcastMessage(Messages.MAINCMD_INVITE_ACCEPT_BROADCAST, invitedPlayer);
}
} else {
if (sendMessages) {
((PartyPlayerImpl) invitedPlayer).sendMessage(Messages.PARTIES_COMMON_PARTYFULL, (PartyImpl) party);
if (inviter != null) {
((PartyPlayerImpl) inviter).sendMessage(Messages.PARTIES_COMMON_PARTYFULL, (PartyImpl) party);
}
}
}
}
}
}
Aggregations