Search in sources :

Example 6 with PartyImpl

use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.

the class MigrationsTest method database2_6_X_SQL.

private void database2_6_X_SQL(PartiesSQLDispatcher dispatcher) {
    dispatcher.init();
    dispatcher.getConnectionFactory().getJdbi().useHandle(handle -> {
        handle.execute("SELECT 1 FROM <prefix>parties");
        handle.execute("SELECT 1 FROM <prefix>players");
    });
    PartyImpl party = dispatcher.getPartyByName("test");
    assertNotNull(party);
    assertEquals("test description", party.getDescription());
    assertEquals(2, party.getMembers().size());
    // Leader check
    assertNotNull(party.getLeader());
    PartyPlayerImpl leader = dispatcher.getPlayer(party.getLeader());
    assertNotNull(leader);
    assertEquals(party.getId(), leader.getPartyId());
    // Home check
    assertEquals(1, party.getHomes().size());
    assertTrue(party.getHomes().stream().findFirst().isPresent());
    assertEquals("default", party.getHomes().stream().findFirst().get().getName());
    // Another party
    assertNotNull(dispatcher.getPartyByName("test2"));
    dispatcher.stop();
}
Also used : PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 7 with PartyImpl

use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.

the class SQLDispatcherTest method party.

private void party(PartiesSQLDispatcher dispatcher, PartiesDao dao, boolean remove) {
    PartyImpl party = initializeParty(mockPlugin, UUID.randomUUID());
    PartyPlayerImpl player = initializePlayer(mockPlugin, UUID.randomUUID());
    PartyImpl mockParty = mock(PartyImpl.class);
    doReturn(CompletableFuture.completedFuture(null)).when(mockParty).updateParty();
    PartyPlayerImpl mockPlayer = mock(PartyPlayerImpl.class);
    doReturn(CompletableFuture.completedFuture(null)).when(mockPlayer).updatePlayer();
    PartyManager mockPartyManager = mock(PartyManager.class);
    when(mockPlugin.getPartyManager()).thenReturn(mockPartyManager);
    when(mockPartyManager.initializeParty(any())).thenAnswer((mock) -> initializeParty(mockPlugin, mock.getArgument(0)));
    PlayerManager mockPlayerManager = mock(PlayerManager.class);
    when(mockPlugin.getPlayerManager()).thenReturn(mockPlayerManager);
    when(mockPlayerManager.initializePlayer(any())).thenAnswer((mock) -> initializePlayer(mockPlugin, mock.getArgument(0)));
    party.setAccessible(true);
    party.setup("test", player.getPlayerUUID().toString());
    party.setDescription("description");
    party.setKills(10);
    party.setMembers(Collections.singleton(player.getPlayerUUID()));
    party.setAccessible(false);
    player.setAccessible(true);
    player.setPartyId(party.getId());
    player.setAccessible(false);
    dispatcher.updatePlayer(player);
    assertEquals(dao.countAll(), 0);
    dispatcher.updateParty(party);
    assertEquals(dao.countAll(), 1);
    assertEquals(party, dispatcher.getParty(party.getId()));
    assertEquals(party, dispatcher.getPartyByName(party.getName()));
    // Party remove
    if (remove) {
        dispatcher.removeParty(party);
        assertEquals(dao.countAll(), 0);
    }
}
Also used : PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) PlayerManager(com.alessiodp.parties.common.players.PlayerManager) PartyManager(com.alessiodp.parties.common.parties.PartyManager) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 8 with PartyImpl

use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.

the class PlayerManager method setupOnlinePlayer.

public void setupOnlinePlayer(User player) {
    PartyPlayerImpl pp = loadPlayer(player.getUUID());
    PartyImpl party = plugin.getPartyManager().loadParty(pp.getPartyId());
    if (party != null)
        party.addOnlineMember(pp);
    plugin.getLoginAlertsManager().sendAlerts(player);
}
Also used : PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 9 with PartyImpl

use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.

the class PartyAskRequestImpl method accept.

@Override
public void accept(boolean sendMessages, PartyPlayer accepter) {
    if (party.getAskRequests().remove(this) && asker.getPendingAskRequests().remove(this)) {
        // Calling API Event
        IPlayerPreJoinEvent partiesPreJoinEvent = plugin.getEventManager().preparePlayerPreJoinEvent(asker, party, JoinCause.ASK, accepter);
        plugin.getEventManager().callEvent(partiesPreJoinEvent);
        if (!partiesPreJoinEvent.isCancelled()) {
            boolean success = ((PartyImpl) party).addMember(asker, JoinCause.ASK, (PartyPlayerImpl) accepter);
            if (success) {
                if (sendMessages) {
                    ((PartyPlayerImpl) asker).sendMessage(Messages.ADDCMD_ASK_ACCEPT_ACCEPTED, (PartyPlayerImpl) accepter, (PartyImpl) party);
                    if (accepter != null)
                        ((PartyPlayerImpl) accepter).sendMessage(Messages.ADDCMD_ASK_ACCEPT_RECEIPT, (PartyPlayerImpl) asker, (PartyImpl) party);
                    party.broadcastMessage(Messages.ADDCMD_ASK_ACCEPT_BROADCAST, asker);
                }
            } else {
                if (sendMessages) {
                    ((PartyPlayerImpl) asker).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)

Example 10 with PartyImpl

use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.

the class PartyPlayerImpl method performPartyMessage.

/**
 * Perform a party message
 */
public boolean performPartyMessage(String message) {
    if (!message.isEmpty()) {
        PartyImpl party = plugin.getPartyManager().getPartyOfPlayer(this);
        if (party != null) {
            String formattedMessage = plugin.getMessageUtils().convertPlaceholders(Messages.PARTIES_FORMATS_PARTY_CHAT, this, party);
            String chatMessage = message;
            if (ConfigParties.GENERAL_CHAT_ALLOWCOLORS) {
                User user = plugin.getPlayer(getPlayerUUID());
                if (user != null && user.hasPermission(PartiesPermission.USER_CHAT_COLOR) && plugin.getRankManager().checkPlayerRank(this, RankPermission.SENDMESSAGE_COLOR)) {
                    chatMessage = Color.translateAlternateColorCodes(chatMessage);
                }
            }
            formattedMessage = Color.translateAlternateColorCodes(formattedMessage);
            if (party.dispatchChatMessage(this, formattedMessage, chatMessage, true)) {
                plugin.getPlayerManager().sendSpyMessage(new SpyMessage(plugin).setType(SpyMessage.SpyType.MESSAGE).setMessage(plugin.getJsonHandler().removeJson(chatMessage)).setParty(party).setPlayer(this));
                return true;
            }
        }
    }
    return false;
}
Also used : User(com.alessiodp.core.common.user.User) OfflineUser(com.alessiodp.core.common.user.OfflineUser) ToString(lombok.ToString) 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