use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.
the class CommonListener method handlePostPartyCreate.
public void handlePostPartyCreate(UUID partyId, UUID playerId, boolean load) {
PartyImpl party = load ? plugin.getPartyManager().loadParty(partyId) : plugin.getPartyManager().getParty(partyId);
if (party != null) {
if (load)
plugin.getPlayerManager().reloadPlayer(playerId);
PartyPlayerImpl leader = plugin.getPlayerManager().getPlayer(partyId);
IPartyPostCreateEvent partiesPostCreateEvent = plugin.getEventManager().preparePartyPostCreateEvent(leader, party);
plugin.getEventManager().callEvent(partiesPostCreateEvent);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_MESSAGING_LISTEN_CREATE_PARTY, partyId.toString(), playerId != null ? playerId.toString() : "none"), true);
}
}
use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.
the class PartyManager method loadParty.
public PartyImpl loadParty(String name) {
// Get the party and save it into the party list
PartyImpl ret = getParty(name);
addPartyToCache(ret);
return ret;
}
use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.
the class PartyManager method reloadParty.
public boolean reloadParty(UUID id) {
PartyImpl party = getPartyFromCache(id);
if (party != null) {
removePartyFromCache(party);
party = plugin.getDatabaseManager().getParty(id);
if (party != null) {
addPartyToCache(party);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_PARTY_RELOADED, party.getName() != null ? party.getName() : party.getId()), true);
} else
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_PARTY_RELOADED_DELETED, id), true);
return true;
}
return false;
}
use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.
the class CommandInvite method preRequisites.
@Override
public boolean preRequisites(@NotNull CommandData commandData) {
User sender = commandData.getSender();
PartyPlayerImpl partyPlayer = getPlugin().getPlayerManager().getPlayer(sender.getUUID());
// Checks for command prerequisites
if (!sender.hasPermission(permission)) {
sendNoPermissionMessage(partyPlayer, permission);
return false;
}
if (commandData.getArgs().length != 2) {
sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", syntax));
return false;
}
PartyImpl party = getPlugin().getPartyManager().getPartyOfPlayer(partyPlayer);
if (party == null) {
if (!ConfigParties.GENERAL_INVITE_AUTO_CREATE_PARTY_UPON_INVITE) {
sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_NOTINPARTY);
return false;
}
} else {
if (!getPlugin().getRankManager().checkPlayerRankAlerter(partyPlayer, RankPermission.INVITE))
return false;
if (party.isFull()) {
sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_PARTYFULL);
return false;
}
((PartiesCommandData) commandData).setParty(party);
}
((PartiesCommandData) commandData).setPartyPlayer(partyPlayer);
commandData.addPermission(PartiesPermission.ADMIN_COOLDOWN_INVITE_BYPASS);
return true;
}
use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.
the class CommandLeave method onCommand.
@Override
public void onCommand(@NotNull CommandData commandData) {
User sender = commandData.getSender();
PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
PartyImpl party = ((PartiesCommandData) commandData).getParty();
// Command handling
// Calling API event
IPlayerPreLeaveEvent partiesPreLeaveEvent = getPlugin().getEventManager().preparePlayerPreLeaveEvent(partyPlayer, party, LeaveCause.LEAVE, partyPlayer);
getPlugin().getEventManager().callEvent(partiesPreLeaveEvent);
if (!partiesPreLeaveEvent.isCancelled()) {
if (party.getLeader() != null && party.getLeader().equals(sender.getUUID())) {
// Is leader
boolean mustDelete = true;
// Check if leader can be changed
if (ConfigParties.GENERAL_MEMBERS_ON_PARTY_LEAVE_CHANGE_LEADER && party.getMembers().size() > 1) {
PartyPlayerImpl newLeader = party.findNewLeader();
if (newLeader != null) {
// Found a new leader
mustDelete = false;
party.changeLeader(newLeader);
party.removeMember(partyPlayer, LeaveCause.LEAVE, partyPlayer);
sendMessage(sender, partyPlayer, Messages.MAINCMD_LEAVE_LEFT, party);
party.broadcastMessage(Messages.MAINCMD_LEAVE_LEADER_CHANGED, newLeader);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_LEAVE_LEADER_CHANGE, partyPlayer.getName(), party.getName() != null ? party.getName() : "_", newLeader.getName()), true);
}
}
if (mustDelete) {
// Calling Pre API event
IPartyPreDeleteEvent partiesPreDeleteEvent = getPlugin().getEventManager().preparePartyPreDeleteEvent(party, DeleteCause.LEAVE, null, partyPlayer);
getPlugin().getEventManager().callEvent(partiesPreDeleteEvent);
if (!partiesPreDeleteEvent.isCancelled()) {
// Disbanding party
sendMessage(sender, partyPlayer, Messages.MAINCMD_LEAVE_LEFT, party);
party.broadcastMessage(Messages.MAINCMD_LEAVE_DISBANDED, partyPlayer);
// Remove player for execute event
party.removeMember(partyPlayer, LeaveCause.LEAVE, partyPlayer);
party.delete(DeleteCause.LEAVE, partyPlayer, partyPlayer);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_LEAVE, partyPlayer.getName(), party.getName() != null ? party.getName() : "_", true), true);
} else
plugin.getLoggerManager().log(String.format(PartiesConstants.DEBUG_API_DELETEEVENT_DENY, party.getId(), sender.getName(), sender.getUUID().toString()), true);
}
} else {
party.removeMember(partyPlayer, LeaveCause.LEAVE, partyPlayer);
sendMessage(sender, partyPlayer, Messages.MAINCMD_LEAVE_LEFT, party);
party.broadcastMessage(Messages.MAINCMD_LEAVE_BROADCAST, partyPlayer);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_LEAVE, partyPlayer.getName(), party.getId(), false), true);
}
} else
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_API_LEAVEEVENT_DENY, sender.getUUID().toString(), party.getId()), true);
}
Aggregations