use of com.alessiodp.parties.common.commands.utils.PartiesCommandData 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.commands.utils.PartiesCommandData 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);
}
use of com.alessiodp.parties.common.commands.utils.PartiesCommandData in project Parties by AlessioDP.
the class CommandList method onCommand.
@Override
public void onCommand(CommandData commandData) {
User sender = commandData.getSender();
PartyPlayerImpl player = ((PartiesCommandData) commandData).getPartyPlayer();
// Command handling
int selectedPage = 1;
PartiesDatabaseManager.ListOrder orderBy = null;
if (commandData.getArgs().length > 1) {
if (commandData.getArgs().length == 2) {
try {
selectedPage = Integer.parseInt(commandData.getArgs()[1]);
} catch (NumberFormatException ignored) {
orderBy = PartiesDatabaseManager.ListOrder.parse(commandData.getArgs()[1]);
if (orderBy == null) {
sendMessage(sender, player, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", getSyntaxForUser(sender)));
return;
}
}
} else if (commandData.getArgs().length == 3 && ConfigParties.ADDITIONAL_LIST_CHANGE_ORDER) {
orderBy = PartiesDatabaseManager.ListOrder.parse(commandData.getArgs()[1]);
if (orderBy == null) {
sendMessage(sender, player, Messages.ADDCMD_LIST_INVALID_ORDER);
return;
}
try {
selectedPage = Integer.parseInt(commandData.getArgs()[2]);
} catch (NumberFormatException ignored) {
sendMessage(sender, player, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", getSyntaxForUser(sender)));
return;
}
} else {
sendMessage(sender, player, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", getSyntaxForUser(sender)));
return;
}
}
if (orderBy != null) {
if (!commandData.havePermission(permission) && ((orderBy == PartiesDatabaseManager.ListOrder.NAME && !commandData.havePermission(PartiesPermission.USER_LIST_NAME)) || (orderBy == PartiesDatabaseManager.ListOrder.ONLINE_MEMBERS && !commandData.havePermission(PartiesPermission.USER_LIST_ONLINE_MEMBERS)) || (orderBy == PartiesDatabaseManager.ListOrder.MEMBERS && !commandData.havePermission(PartiesPermission.USER_LIST_MEMBERS)) || (orderBy == PartiesDatabaseManager.ListOrder.KILLS && !commandData.havePermission(PartiesPermission.USER_LIST_KILLS)) || (orderBy == PartiesDatabaseManager.ListOrder.EXPERIENCE && !commandData.havePermission(PartiesPermission.USER_LIST_EXPERIENCE)))) {
sendMessage(sender, player, Messages.ADDCMD_LIST_INVALID_ORDER);
return;
}
} else {
if (commandData.havePermission(permission))
orderBy = PartiesDatabaseManager.ListOrder.getType(ConfigParties.ADDITIONAL_LIST_ORDERBY);
else if (commandData.havePermission(PartiesPermission.USER_LIST_NAME))
orderBy = PartiesDatabaseManager.ListOrder.NAME;
else if (commandData.havePermission(PartiesPermission.USER_LIST_ONLINE_MEMBERS))
orderBy = PartiesDatabaseManager.ListOrder.ONLINE_MEMBERS;
else if (commandData.havePermission(PartiesPermission.USER_LIST_MEMBERS))
orderBy = PartiesDatabaseManager.ListOrder.MEMBERS;
else if (commandData.havePermission(PartiesPermission.USER_LIST_KILLS))
orderBy = PartiesDatabaseManager.ListOrder.KILLS;
else if (commandData.havePermission(PartiesPermission.USER_LIST_EXPERIENCE))
orderBy = PartiesDatabaseManager.ListOrder.EXPERIENCE;
if (orderBy == null)
orderBy = PartiesDatabaseManager.ListOrder.ONLINE_MEMBERS;
}
// Command starts
int numberPlayers = Math.min(orderBy == PartiesDatabaseManager.ListOrder.ONLINE_MEMBERS ? getPlugin().getPartyManager().getCacheParties().size() : getPlugin().getDatabaseManager().getListPartiesNumber(), ConfigParties.ADDITIONAL_LIST_LIMITPARTIES);
int limit = Math.max(1, ConfigParties.ADDITIONAL_LIST_PERPAGE);
int maxPages;
if (numberPlayers == 0)
maxPages = 1;
else if (numberPlayers % ConfigParties.ADDITIONAL_LIST_PERPAGE == 0)
maxPages = numberPlayers / ConfigParties.ADDITIONAL_LIST_PERPAGE;
else
maxPages = (numberPlayers / ConfigParties.ADDITIONAL_LIST_PERPAGE) + 1;
if (selectedPage > maxPages)
selectedPage = maxPages;
int offset = selectedPage > 1 ? limit * (selectedPage - 1) : 0;
LinkedHashSet<Pair<Integer, PartyImpl>> parties = new LinkedHashSet<>();
if (orderBy == PartiesDatabaseManager.ListOrder.ONLINE_MEMBERS) {
Set<PartyImpl> onlineParties = new TreeSet<>(Comparator.comparing(p -> ((PartyImpl) p).getOnlineMembers(false).size()).reversed().thenComparing(p -> ((PartyImpl) p).getName()).thenComparing(p -> ((PartyImpl) p).getId()));
getPlugin().getPartyManager().getCacheParties().values().forEach((party) -> {
if (party.getName() != null && !ConfigParties.ADDITIONAL_LIST_HIDDENPARTIES.contains(party.getName()) && !ConfigParties.ADDITIONAL_LIST_HIDDENPARTIES.contains(party.getId().toString())) {
onlineParties.add(party);
}
});
// Limit and offset
Iterator<PartyImpl> iterator = onlineParties.iterator();
int n = 0;
for (int c = 0; iterator.hasNext() && n < limit; c++) {
PartyImpl p = iterator.next();
if (c >= offset) {
parties.add(new Pair<>(c + 1, p));
n++;
}
}
} else {
int index = 1;
for (PartyImpl party : getPlugin().getDatabaseManager().getListParties(orderBy, limit, offset)) {
parties.add(new Pair<>(index, party));
index++;
}
}
sendMessage(sender, player, Messages.ADDCMD_LIST_HEADER.replace("%total%", Integer.toString(numberPlayers)).replace("%page%", Integer.toString(selectedPage)).replace("%maxpages%", Integer.toString(maxPages)));
if (parties.size() > 0) {
parties.forEach((pair) -> {
pair.getValue().refresh();
sendMessage(sender, player, Messages.ADDCMD_LIST_FORMATPARTY.replace("%index%", pair.getKey().toString()), pair.getValue());
});
} else {
sendMessage(sender, player, Messages.ADDCMD_LIST_NOONE);
}
sendMessage(sender, player, Messages.ADDCMD_LIST_FOOTER.replace("%total%", Integer.toString(numberPlayers)).replace("%page%", Integer.toString(selectedPage)).replace("%maxpages%", Integer.toString(maxPages)));
}
use of com.alessiodp.parties.common.commands.utils.PartiesCommandData in project Parties by AlessioDP.
the class CommandMute method onCommand.
@Override
public void onCommand(@NotNull CommandData commandData) {
User sender = commandData.getSender();
PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
// Command handling
Boolean mute = plugin.getCommandManager().getCommandUtils().handleOnOffCommand(partyPlayer.isMuted(), commandData.getArgs());
if (mute == null) {
sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", syntax));
return;
}
// Command starts
partyPlayer.setMuted(mute);
if (mute) {
sendMessage(sender, partyPlayer, Messages.ADDCMD_MUTE_ON);
} else {
sendMessage(sender, partyPlayer, Messages.ADDCMD_MUTE_OFF);
}
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_MUTE, partyPlayer.getName(), mute), true);
}
use of com.alessiodp.parties.common.commands.utils.PartiesCommandData in project Parties by AlessioDP.
the class CommandNickname method preRequisites.
@Override
public boolean preRequisites(@NotNull CommandData commandData) {
User sender = commandData.getSender();
PartyPlayerImpl partyPlayer = null;
if (sender.isPlayer()) {
partyPlayer = getPlugin().getPlayerManager().getPlayer(sender.getUUID());
// Checks for command prerequisites
if (!sender.hasPermission(permission)) {
sendNoPermissionMessage(partyPlayer, permission);
return false;
}
if (!sender.hasPermission(PartiesPermission.ADMIN_NICKNAME_OTHERS)) {
if (!partyPlayer.isInParty()) {
sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_NOTINPARTY);
return false;
}
if (!getPlugin().getRankManager().checkPlayerRank(partyPlayer, RankPermission.EDIT_NICKNAME_OWN) && !getPlugin().getRankManager().checkPlayerRank(partyPlayer, RankPermission.EDIT_NICKNAME_OTHERS)) {
sendMessage(sender, partyPlayer, Messages.PARTIES_PERM_NORANK_GENERAL);
return false;
}
}
((PartiesCommandData) commandData).setPartyPlayer(partyPlayer);
commandData.addPermission(PartiesPermission.ADMIN_NICKNAME_OTHERS);
}
if (commandData.getArgs().length < 2 || commandData.getArgs().length > 4) {
sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", syntax));
return false;
}
return true;
}
Aggregations