Search in sources :

Example 56 with PartyImpl

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());
}
Also used : PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 57 with PartyImpl

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);
}
Also used : PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) UUID(java.util.UUID) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl) HashSet(java.util.HashSet)

Example 58 with PartyImpl

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));
}
Also used : LinkedList(java.util.LinkedList) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 59 with PartyImpl

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;
}
Also used : PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 60 with PartyImpl

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);
                    }
                }
            }
        }
    }
}
Also used : IPlayerPreJoinEvent(com.alessiodp.parties.api.events.common.player.IPlayerPreJoinEvent) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Aggregations

PartyImpl (com.alessiodp.parties.common.parties.objects.PartyImpl)106 PartyPlayerImpl (com.alessiodp.parties.common.players.objects.PartyPlayerImpl)75 User (com.alessiodp.core.common.user.User)39 PartiesCommandData (com.alessiodp.parties.common.commands.utils.PartiesCommandData)31 ADPPlugin (com.alessiodp.core.common.ADPPlugin)11 UUID (java.util.UUID)11 ConfigMain (com.alessiodp.parties.common.configuration.data.ConfigMain)10 ConfigParties (com.alessiodp.parties.common.configuration.data.ConfigParties)10 PartiesPlugin (com.alessiodp.parties.common.PartiesPlugin)9 PartiesConstants (com.alessiodp.parties.common.configuration.PartiesConstants)9 PartyHomeImpl (com.alessiodp.parties.common.parties.objects.PartyHomeImpl)8 LinkedList (java.util.LinkedList)8 LinkedHashSet (java.util.LinkedHashSet)7 List (java.util.List)7 HashMap (java.util.HashMap)6 ADPMainCommand (com.alessiodp.core.common.commands.utils.ADPMainCommand)5 CommandData (com.alessiodp.core.common.commands.utils.CommandData)5 OfflineUser (com.alessiodp.core.common.user.OfflineUser)5 CommonCommands (com.alessiodp.parties.common.commands.list.CommonCommands)5 PartiesSubCommand (com.alessiodp.parties.common.commands.utils.PartiesSubCommand)5