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();
}
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);
}
}
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);
}
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);
}
}
}
}
}
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;
}
Aggregations