use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.
the class ChatListener method onPlayerChat.
protected boolean onPlayerChat(User sender, String message) {
boolean eventCancelled = false;
PartyPlayerImpl partyPlayer = plugin.getPlayerManager().getPlayer(sender.getUUID());
String parsedMessage = message;
boolean partyChat = false;
PartyImpl party = plugin.getPartyManager().getParty(partyPlayer.getPartyId());
if (party != null) {
if (partyPlayer.isChatParty()) {
partyChat = true;
} else if (ConfigParties.GENERAL_CHAT_DIRECT_ENABLED && parsedMessage.startsWith(ConfigParties.GENERAL_CHAT_DIRECT_PREFIX)) {
partyChat = true;
parsedMessage = parsedMessage.substring(// Remove direct prefix
ConfigParties.GENERAL_CHAT_DIRECT_PREFIX.length()).replaceAll("^\\s+|\\s+$", // Trim the string
"");
}
}
if (partyChat) {
final String finalMessage = parsedMessage;
// Make it async
plugin.getScheduler().runAsync(() -> {
if (plugin.getRankManager().checkPlayerRankAlerter(partyPlayer, RankPermission.SENDMESSAGE)) {
// Chat allowed
boolean mustWait = false;
if (partyPlayer.isChatMuted()) {
partyPlayer.sendMessage(Messages.MAINCMD_P_MUTED);
return;
}
if (CensorUtils.checkCensor(ConfigParties.GENERAL_CHAT_CENSORREGEX, finalMessage, PartiesConstants.DEBUG_CMD_P_REGEXERROR)) {
partyPlayer.sendMessage(Messages.MAINCMD_P_CENSORED);
return;
}
boolean mustStartCooldown = false;
if (ConfigParties.GENERAL_CHAT_COOLDOWN > 0 && !sender.hasPermission(PartiesPermission.ADMIN_COOLDOWN_CHAT_BYPASS)) {
mustStartCooldown = true;
long remainingCooldown = plugin.getCooldownManager().canAction(CooldownManager.Action.CHAT, partyPlayer.getPlayerUUID(), ConfigParties.GENERAL_CHAT_COOLDOWN);
if (remainingCooldown > 0) {
partyPlayer.sendMessage(Messages.MAINCMD_P_COOLDOWN.replace("%seconds%", String.valueOf(remainingCooldown)));
mustWait = true;
}
}
if (!mustWait && partyPlayer.performPartyMessage(finalMessage)) {
if (mustStartCooldown)
plugin.getCooldownManager().startAction(CooldownManager.Action.CHAT, partyPlayer.getPlayerUUID(), ConfigParties.GENERAL_CHAT_COOLDOWN);
if (ConfigMain.PARTIES_LOGGING_PARTY_CHAT) {
plugin.getLoggerManager().log(String.format(PartiesConstants.DEBUG_CMD_P, partyPlayer.getName(), party.getName() != null ? party.getName() : "_", finalMessage), true);
}
}
} else
partyPlayer.sendMessage(Messages.PARTIES_PERM_NOPERM.replace("%permission%", RankPermission.SENDMESSAGE.toString()));
});
eventCancelled = true;
}
return eventCancelled;
}
use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.
the class JoinLeaveListener method onPlayerQuit.
/**
* Used by Bukkit, Bungeecord
*/
protected void onPlayerQuit(User player) {
// Make it async
plugin.getScheduler().runAsync(() -> {
PartyPlayerImpl partyPlayer = plugin.getPlayerManager().getPlayer(player.getUUID());
// Party checking
PartyImpl party = plugin.getPartyManager().getParty(partyPlayer.getPartyId());
if (party != null) {
party.removeOnlineMember(partyPlayer);
if (ConfigParties.GENERAL_JOIN_LEAVE_MESSAGES) {
party.broadcastMessage(Messages.OTHER_JOINLEAVE_SERVERLEAVE, partyPlayer);
}
if (!plugin.isBungeeCordEnabled()) {
// If Bukkit non-sync or BungeeCord
if (!party.memberLeftTimeout(partyPlayer) && party.getOnlineMembers(true).size() == 0) {
// If the party won't gonna be deleted on timeout, unload it
plugin.getPartyManager().unloadParty(party);
}
}
}
plugin.getPlayerManager().unloadPlayer(partyPlayer.getPlayerUUID());
// Reset pending delays
partyPlayer.resetPendingDelays();
// Check if banned
if (player.isBanned() && ConfigMain.ADDITIONAL_MODERATION_ENABLE && ConfigMain.ADDITIONAL_MODERATION_AUTOKICK && moderationOnServerBan()) {
plugin.getPartyManager().kickBannedPlayer(partyPlayer);
}
onLeaveComplete(partyPlayer);
});
}
use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.
the class CommonListener method handlePostPartyRename.
public void handlePostPartyRename(UUID partyId, String oldName, String newName, UUID playerId, boolean isAdmin) {
plugin.getPartyManager().reloadPartyIfCached(partyId);
PartyImpl party = plugin.getPartyManager().getParty(partyId);
if (party != null) {
PartyPlayerImpl player = playerId != null ? plugin.getPlayerManager().getPlayer(playerId) : null;
IPartyPostRenameEvent event = plugin.getEventManager().preparePartyPostRenameEvent(party, oldName, newName, player, isAdmin);
plugin.getEventManager().callEvent(event);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_MESSAGING_LISTEN_RENAME_PARTY, party.getId(), oldName, newName, player != null ? player.getPlayerUUID().toString() : "none"), true);
}
}
use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.
the class CommonListener method handlePostPartyAddMember.
public void handlePostPartyAddMember(UUID partyId, UUID playerId, JoinCause cause, UUID inviterId) {
plugin.getPartyManager().reloadPartyIfCached(partyId);
PartyImpl party = plugin.getPartyManager().getParty(partyId);
if (party != null) {
PartyPlayerImpl player = plugin.getPlayerManager().getPlayer(playerId);
PartyPlayerImpl inviter = inviterId != null ? plugin.getPlayerManager().getPlayer(inviterId) : null;
IPlayerPostJoinEvent event = plugin.getEventManager().preparePlayerPostJoinEvent(player, party, cause, inviter);
plugin.getEventManager().callEvent(event);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_MESSAGING_LISTEN_ADD_MEMBER_PARTY, playerId.toString(), partyId.toString(), cause.name(), inviterId != null ? inviterId.toString() : "none"), true);
}
}
use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.
the class CommonListener method handleInvitePlayer.
public void handleInvitePlayer(UUID partyId, UUID invitedId, UUID inviterId) {
PartyImpl party = plugin.getPartyManager().getParty(partyId);
if (party != null) {
try {
PartyPlayerImpl invitedPlayer = plugin.getPlayerManager().getPlayer(invitedId);
PartyPlayerImpl inviter = plugin.getPlayerManager().getPlayer(inviterId);
party.invitePlayer(invitedPlayer, inviter);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_MESSAGING_LISTEN_INVITE_PARTY, invitedId.toString(), partyId.toString(), inviterId != null ? inviterId.toString() : "none"), true);
} catch (Exception ex) {
plugin.getLoggerManager().logError(PartiesConstants.DEBUG_MESSAGING_LISTEN_INVITE_PARTY_ERROR, ex);
}
}
}
Aggregations