use of com.alessiodp.parties.common.parties.objects.PartyImpl 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.parties.objects.PartyImpl in project Parties by AlessioDP.
the class CommandOpen method onCommand.
@Override
public void onCommand(@NotNull CommandData commandData) {
User sender = commandData.getSender();
PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
PartyImpl party;
// Command handling
if (commandData.getArgs().length == 1 && sender.isPlayer()) {
party = getPlugin().getPartyManager().getPartyOfPlayer(partyPlayer);
} else if (commandData.getArgs().length == 2 && commandData.havePermission(PartiesPermission.ADMIN_OPEN_OTHERS)) {
party = getPlugin().getPartyManager().getParty(commandData.getArgs()[1]);
} else {
sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", getSyntaxForUser(sender)));
return;
}
if (party == null) {
if (commandData.getArgs().length > 1)
sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_PARTYNOTFOUND.replace("%party%", commandData.getArgs()[1]));
else
sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_NOTINPARTY);
return;
}
if (party.isOpen()) {
sendMessage(sender, partyPlayer, Messages.ADDCMD_JOIN_OPENCLOSE_ALREADY_OPEN);
return;
}
boolean mustStartCooldown = false;
if (ConfigParties.ADDITIONAL_JOIN_OPENCLOSE_COOLDOWN_OPEN > 0 && !commandData.havePermission(PartiesPermission.ADMIN_COOLDOWN_OPEN_BYPASS)) {
mustStartCooldown = true;
long remainingCooldown = getPlugin().getCooldownManager().canAction(CooldownManager.Action.OPEN, sender.getUUID(), ConfigParties.ADDITIONAL_JOIN_OPENCLOSE_COOLDOWN_OPEN);
if (remainingCooldown > 0) {
sendMessage(sender, partyPlayer, Messages.ADDCMD_JOIN_OPENCLOSE_COOLDOWN.replace("%seconds%", String.valueOf(remainingCooldown)));
return;
}
}
if (getPlugin().getEconomyManager().payCommand(EconomyManager.PaidCommand.OPEN, partyPlayer, commandData.getCommandLabel(), commandData.getArgs()))
return;
if (mustStartCooldown)
getPlugin().getCooldownManager().startAction(CooldownManager.Action.OPEN, sender.getUUID(), ConfigParties.ADDITIONAL_JOIN_OPENCLOSE_COOLDOWN_OPEN);
// Command starts
party.setOpen(true);
sendMessage(sender, partyPlayer, Messages.ADDCMD_JOIN_OPENCLOSE_OPENED);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_OPENCLOSE, partyPlayer.getName(), party.getName() != null ? party.getName() : "_", true), true);
}
use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.
the class CommandProtection 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
Boolean protection = plugin.getCommandManager().getCommandUtils().handleOnOffCommand(partyPlayer.isChatParty(), commandData.getArgs());
if (protection == null) {
sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", syntax));
return;
}
if (protection && getPlugin().getEconomyManager().payCommand(EconomyManager.PaidCommand.PROTECTION, partyPlayer, commandData.getCommandLabel(), commandData.getArgs()))
return;
// Command starts
party.setProtection(protection);
sendMessage(sender, partyPlayer, protection ? Messages.ADDCMD_PROTECTION_ON : Messages.ADDCMD_PROTECTION_OFF);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_PROTECTION, partyPlayer.getName(), party.getName() != null ? party.getName() : "_", protection), true);
}
use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.
the class CommandRank method onCommand.
@Override
public void onCommand(@NotNull CommandData commandData) {
User sender = commandData.getSender();
PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
// Command handling
String playerName = commandData.getArgs()[1];
UUID playerUUID = null;
Set<UUID> matchingPlayers;
if (LLAPIHandler.isEnabled()) {
// Use LastLoginAPI to get a list of players with the same name
matchingPlayers = LLAPIHandler.getPlayerByName(playerName);
} else {
// Get only the online player with the same name
matchingPlayers = new HashSet<>();
User user = plugin.getPlayerByName(playerName);
if (user != null)
matchingPlayers.add(user.getUUID());
}
List<UUID> listPlayers = new LinkedList<>(matchingPlayers);
listPlayers.removeIf((uuid) -> !getPlugin().getPlayerManager().getPlayer(uuid).isInParty());
Collections.sort(listPlayers);
if (listPlayers.size() > 1) {
// Check if the player have selected someone
if (commandData.getArgs().length > 2) {
try {
int sel = Integer.parseInt(commandData.getArgs()[3]);
playerUUID = listPlayers.get(sel - 1);
} catch (Exception ignored) {
}
}
// The player didn't select a player
if (playerUUID == null) {
for (String str : Messages.MAINCMD_RANK_CONFLICT_CONTENT) {
if (str.contains("%list_players%")) {
int i = 1;
for (UUID uuid : listPlayers) {
PartyPlayerImpl pp = getPlugin().getPlayerManager().getPlayer(uuid);
if (pp.isInParty()) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_RANK_CONFLICT_PLAYER.replace("%number%", Integer.toString(i)).replace("%username%", playerName), pp, getPlugin().getPartyManager().getPartyOfPlayer(pp));
i++;
}
}
} else {
sendMessage(sender, partyPlayer, str);
}
}
return;
}
} else if (listPlayers.size() == 1) {
// Player found
playerUUID = listPlayers.get(0);
} else {
// Not found
sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_PLAYER_NOT_FOUND.replace("%player%", playerName));
return;
}
OfflineUser promotedPlayer = plugin.getOfflinePlayer(playerUUID);
Objects.requireNonNull(promotedPlayer);
PartyPlayerImpl promotedPp = getPlugin().getPlayerManager().getPlayer(playerUUID);
PartyRankImpl rank = getPlugin().getRankManager().searchRankByName(commandData.getArgs()[2]);
if (rank == null) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_RANK_WRONGRANK.replace("%rank_name%", commandData.getArgs()[2]).replace("%rank_chat%", commandData.getArgs()[2]));
return;
}
if (sender.isPlayer() && promotedPlayer.getUUID().equals(sender.getUUID()) && !(promotedPlayer.isOnline() && commandData.havePermission(PartiesPermission.ADMIN_RANK_BYPASS))) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_RANK_CHANGINGYOURSELF);
return;
}
PartyImpl party = partyPlayer != null ? getPlugin().getPartyManager().getPartyOfPlayer(partyPlayer) : null;
boolean otherParty = (party == null || !party.getMembers().contains(promotedPlayer.getUUID()));
if (otherParty) {
// Other party
party = getPlugin().getPartyManager().getPartyOfPlayer(promotedPp);
if (sender.isPlayer() && !commandData.havePermission(PartiesPermission.ADMIN_RANK_OTHERS)) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_RANK_PLAYERNOTINPARTY, promotedPp);
return;
}
if (party == null) {
sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_PLAYER_NOT_IN_PARTY, promotedPp);
return;
}
} else if (sender.isPlayer() && !commandData.havePermission(PartiesPermission.ADMIN_RANK_OTHERS)) {
// Do not bypass rank restrictions
if (rank.getLevel() == promotedPp.getRank()) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_RANK_SAMERANK.replace("%rank_name%", rank.getName()).replace("%rank_chat%", rank.getChat()).replace("%player%", promotedPlayer.getName()));
return;
}
if (partyPlayer.getRank() <= promotedPp.getRank()) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_RANK_LOWRANK.replace("%rank_name%", rank.getName()).replace("%rank_chat%", rank.getChat()).replace("%player%", promotedPlayer.getName()));
return;
}
if ((rank.getLevel() != ConfigParties.RANK_SET_HIGHER) && (rank.getLevel() >= partyPlayer.getRank())) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_RANK_TOHIGHERRANK.replace("%rank_name%", rank.getName()).replace("%rank_chat%", rank.getChat()));
return;
}
}
if (party.isFixed() && rank.getLevel() == ConfigParties.RANK_SET_HIGHER) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_RANK_FIXEDLEADER);
return;
}
if (promotedPp.getRank() == ConfigParties.RANK_SET_HIGHER) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_RANK_DEMOTELEADER);
return;
}
if (rank.getSlot() > 0 && countMembersWithRank((PartiesPlugin) plugin, party, rank) >= rank.getSlot()) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_RANK_FULL.replace("%rank_name%", rank.getName()).replace("%rank_chat%", rank.getChat()));
return;
}
// Command start
int oldRank = promotedPp.getRank();
if (rank.getLevel() == ConfigParties.RANK_SET_HIGHER) {
party.changeLeader(promotedPp);
} else {
promotedPp.setRank(rank.getLevel());
}
sendMessage(sender, partyPlayer, Messages.MAINCMD_RANK_CHANGED.replace("%rank_name%", rank.getName()).replace("%rank_chat%", rank.getChat()), promotedPp);
party.broadcastMessage(Messages.MAINCMD_RANK_BROADCAST.replace("%rank_name%", rank.getName()).replace("%rank_chat%", rank.getChat()), promotedPp);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_RANK, sender.getName(), promotedPp.getName(), party.getName() != null ? party.getName() : "_", oldRank, rank.getLevel(), otherParty), true);
}
use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.
the class CommandRename method onCommand.
@Override
public void onCommand(CommandData commandData) {
User sender = commandData.getSender();
PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
// Command handling
PartyImpl party = null;
String partyName;
if (commandData.getArgs().length == 2) {
// 2 arguments - own party
if (partyPlayer.isInParty())
party = getPlugin().getPartyManager().getParty(partyPlayer.getPartyId());
if (party == null) {
sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_NOTINPARTY);
return;
}
if (!getPlugin().getRankManager().checkPlayerRankAlerter(partyPlayer, RankPermission.ADMIN_RENAME))
return;
partyName = commandData.getArgs()[1];
} else {
// 3 arguments - another party
if (!sender.isPlayer() || commandData.havePermission(PartiesPermission.ADMIN_RENAME_OTHERS)) {
party = getPlugin().getPartyManager().getParty(commandData.getArgs()[1]);
}
if (party == null) {
sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_PARTYNOTFOUND.replace("%party%", commandData.getArgs()[1]));
return;
}
partyName = commandData.getArgs()[2];
}
if (partyName.length() > ConfigParties.GENERAL_NAME_MAXLENGTH) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_CREATE_NAMETOOLONG);
return;
}
if (partyName.length() < ConfigParties.GENERAL_NAME_MINLENGTH) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_CREATE_NAMETOOSHORT);
return;
}
if (!CensorUtils.checkAllowedCharacters(ConfigParties.GENERAL_NAME_ALLOWEDCHARS, partyName, PartiesConstants.DEBUG_CMD_CREATE_REGEXERROR_ALLOWEDCHARS)) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_CREATE_INVALIDNAME);
return;
}
if (CensorUtils.checkCensor(ConfigParties.GENERAL_NAME_CENSORREGEX, partyName, PartiesConstants.DEBUG_CMD_CREATE_REGEXERROR_CENSORED)) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_CREATE_CENSORED);
return;
}
if (getPlugin().getPartyManager().existsParty(partyName)) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_CREATE_NAMEEXISTS.replace("%party%", partyName));
return;
}
boolean mustStartCooldown = false;
if (ConfigParties.GENERAL_NAME_RENAME_COOLDOWN > 0 && !commandData.havePermission(PartiesPermission.ADMIN_COOLDOWN_RENAME_BYPASS)) {
mustStartCooldown = true;
long remainingCooldown = getPlugin().getCooldownManager().canAction(CooldownManager.Action.RENAME, party.getId(), ConfigParties.GENERAL_NAME_RENAME_COOLDOWN);
if (remainingCooldown > 0) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_RENAME_COOLDOWN.replace("%seconds%", String.valueOf(remainingCooldown)));
return;
}
}
if (partyPlayer != null && getPlugin().getEconomyManager().payCommand(EconomyManager.PaidCommand.RENAME, partyPlayer, commandData.getCommandLabel(), commandData.getArgs()))
return;
if (mustStartCooldown) {
getPlugin().getCooldownManager().startAction(CooldownManager.Action.RENAME, party.getId(), ConfigParties.GENERAL_NAME_RENAME_COOLDOWN);
}
// Command starts
String oldPartyName = party.getName();
// Calling API event
IPartyPreRenameEvent partiesPreRenameEvent = getPlugin().getEventManager().preparePartyPreRenameEvent(party, party.getName(), partyName, partyPlayer, commandData.getArgs().length > 2);
getPlugin().getEventManager().callEvent(partiesPreRenameEvent);
partyName = partiesPreRenameEvent.getNewPartyName();
if (!partiesPreRenameEvent.isCancelled()) {
party.rename(partyName, partyPlayer, commandData.getArgs().length > 2);
sendMessage(sender, partyPlayer, Messages.MAINCMD_RENAME_RENAMED.replace("%old%", CommonUtils.getOr(oldPartyName, "null")), party);
party.broadcastMessage(Messages.MAINCMD_RENAME_BROADCAST.replace("%old%", CommonUtils.getOr(oldPartyName, "null")), partyPlayer);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_RENAME, sender.getName(), oldPartyName, party.getName()), true);
} else {
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_API_RENAMEEVENT_DENY, party.getName(), oldPartyName, sender.getUUID().toString()), true);
}
}
Aggregations