use of com.alessiodp.core.common.commands.utils.CommandData 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.core.common.commands.utils.CommandData in project Parties by AlessioDP.
the class CommandSetHome 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
String selectedHome;
boolean isRemove = commandData.getArgs().length > 1 && commandData.getArgs()[1].equalsIgnoreCase(ConfigMain.COMMANDS_MISC_REMOVE);
if (ConfigParties.ADDITIONAL_HOME_MAX_HOMES > 1) {
if (commandData.getArgs().length == 1) {
// Home not selected
sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", getSyntax()));
return;
} else if (commandData.getArgs().length == 2) {
if (isRemove) {
// Home not selected
sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", getSyntax()));
return;
} else {
selectedHome = commandData.getArgs()[1];
}
} else if (commandData.getArgs().length == 3 && isRemove) {
selectedHome = commandData.getArgs()[2];
} else {
sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", getSyntax()));
return;
}
} else {
if (commandData.getArgs().length == 1 || (commandData.getArgs().length == 2 && isRemove)) {
selectedHome = "default";
} else {
sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", getSyntax()));
return;
}
}
if (!isRemove && party.getHomes().size() >= ConfigParties.ADDITIONAL_HOME_MAX_HOMES) {
final String finalSelectedHome = selectedHome;
if (finalSelectedHome == null || party.getHomes().stream().noneMatch((h) -> finalSelectedHome.equalsIgnoreCase(h.getName()))) {
sendMessage(sender, partyPlayer, Messages.ADDCMD_SETHOME_MAXHOMES);
return;
}
}
if (!isRemove) {
boolean mustStartCooldown = false;
if (ConfigParties.ADDITIONAL_HOME_COOLDOWN_SETHOME > 0 && !commandData.havePermission(PartiesPermission.ADMIN_COOLDOWN_SETHOME_BYPASS)) {
mustStartCooldown = true;
long remainingCooldown = getPlugin().getCooldownManager().canAction(CooldownManager.Action.SETHOME, sender.getUUID(), ConfigParties.ADDITIONAL_HOME_COOLDOWN_SETHOME);
if (remainingCooldown > 0) {
sendMessage(sender, partyPlayer, Messages.ADDCMD_SETHOME_COOLDOWN.replace("%seconds%", String.valueOf(remainingCooldown)));
return;
}
}
if (getPlugin().getEconomyManager().payCommand(EconomyManager.PaidCommand.SETHOME, partyPlayer, commandData.getCommandLabel(), commandData.getArgs()))
return;
if (mustStartCooldown) {
getPlugin().getCooldownManager().startAction(CooldownManager.Action.SETHOME, sender.getUUID(), ConfigParties.ADDITIONAL_HOME_COOLDOWN_SETHOME);
}
}
// Command starts
if (isRemove) {
boolean removed;
if (selectedHome == null || ConfigParties.ADDITIONAL_HOME_MAX_HOMES <= 1) {
party.getHomes().clear();
removed = true;
} else {
final String finalSelectedHome = selectedHome;
removed = party.getHomes().removeIf(h -> h.getName() != null && h.getName().equalsIgnoreCase(finalSelectedHome));
}
if (removed) {
party.updateParty();
sendMessage(sender, partyPlayer, Messages.ADDCMD_SETHOME_REMOVED);
} else {
sendMessage(sender, partyPlayer, Messages.ADDCMD_SETHOME_REMOVED_NONE);
}
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_SETHOME_REM, partyPlayer.getName(), party.getName() != null ? party.getName() : "_", CommonUtils.getNoEmptyOr(selectedHome, "default")), true);
} else {
getLocationAndSave(partyPlayer, party, selectedHome);
sendMessage(sender, partyPlayer, Messages.ADDCMD_SETHOME_CHANGED);
party.broadcastMessage(Messages.ADDCMD_SETHOME_BROADCAST, partyPlayer);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_SETHOME, partyPlayer.getName(), party.getName() != null ? party.getName() : "_", CommonUtils.getNoEmptyOr(selectedHome, "default")), true);
}
}
use of com.alessiodp.core.common.commands.utils.CommandData in project Parties by AlessioDP.
the class CommandInvite 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
User invitedPlayer = plugin.getPlayerByName(commandData.getArgs()[1]);
if (invitedPlayer == null) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_INVITE_PLAYEROFFLINE);
return;
}
PartyPlayerImpl invitedPartyPlayer = getPlugin().getPlayerManager().getPlayer(invitedPlayer.getUUID());
if (invitedPartyPlayer.isVanished()) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_INVITE_PLAYEROFFLINE);
return;
}
if (invitedPartyPlayer.getPlayerUUID().equals(sender.getUUID())) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_INVITE_INVITE_YOURSELF);
return;
}
if (invitedPartyPlayer.isInParty()) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_INVITE_PLAYERINPARTY, invitedPartyPlayer);
return;
}
if (ConfigParties.GENERAL_INVITE_PREVENTINVITEPERM && // Check if the user is inside the network (skip if Redis)
invitedPlayer.isInsideNetwork() && !invitedPlayer.hasPermission(PartiesPermission.USER_ACCEPT)) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_INVITE_PLAYERNOPERM, invitedPartyPlayer);
return;
}
// Check for party, create one if option enabled
if (party == null) {
if (ConfigParties.GENERAL_INVITE_AUTO_CREATE_PARTY_UPON_INVITE && ConfigParties.GENERAL_NAME_DYNAMIC_ENABLE) {
String partyName = CommandCreate.generateDynamicName(getPlugin(), partyPlayer);
party = CommandCreate.createParty((PartiesPlugin) plugin, this, sender, partyPlayer, partyName, false);
if (party == null || party.isFixed()) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_INVITE_FAILED, invitedPartyPlayer);
return;
}
} else {
sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_NOTINPARTY);
return;
}
}
if (invitedPartyPlayer.getIgnoredParties().contains(party.getId())) {
// Invited player ignoring the party, fake sent
sendMessage(sender, partyPlayer, Messages.MAINCMD_INVITE_SENT, invitedPartyPlayer);
return;
}
if (invitedPartyPlayer.isMuted() && ConfigMain.ADDITIONAL_MUTE_ENABLE && ConfigMain.ADDITIONAL_MUTE_BLOCK_INVITE) {
// Invited player has disabled notifications, fake sent
sendMessage(sender, partyPlayer, Messages.MAINCMD_INVITE_SENT, invitedPartyPlayer);
return;
}
boolean isRevoke = false;
final PartyImpl finalParty = party;
Optional<PartyInvite> revokeInvite = invitedPartyPlayer.getPendingInvites().stream().filter(pv -> pv.getParty().getId().equals(finalParty.getId())).findAny();
if (revokeInvite.isPresent()) {
isRevoke = true;
if (!ConfigParties.GENERAL_INVITE_REVOKE) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_INVITE_ALREADYINVITED, invitedPartyPlayer);
return;
}
}
boolean mustStartCooldown = false;
if (!isRevoke && ConfigParties.GENERAL_INVITE_COOLDOWN_ENABLE && !commandData.havePermission(PartiesPermission.ADMIN_COOLDOWN_INVITE_BYPASS)) {
// Check invited player cooldown
RequestCooldown inviteAfterLeaveCooldown = getPlugin().getCooldownManager().canMultiAction(CooldownManager.MultiAction.INVITE_AFTER_LEAVE, invitedPlayer.getUUID(), party.getId());
if (inviteAfterLeaveCooldown != null) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_INVITE_COOLDOWN_ON_LEAVE.replace("%seconds%", String.valueOf(inviteAfterLeaveCooldown.getWaitTime())));
return;
}
// Check invite cooldown
mustStartCooldown = true;
RequestCooldown inviteCooldown = getPlugin().getCooldownManager().canMultiAction(CooldownManager.MultiAction.INVITE, partyPlayer.getPlayerUUID(), invitedPlayer.getUUID());
if (inviteCooldown != null) {
sendMessage(sender, partyPlayer, (inviteCooldown.isGlobal() ? Messages.MAINCMD_INVITE_COOLDOWN_GLOBAL : Messages.MAINCMD_INVITE_COOLDOWN_INDIVIDUAL).replace("%seconds%", String.valueOf(inviteCooldown.getCooldown() - inviteCooldown.getDiffTime())));
return;
}
}
// Command starts
if (isRevoke) {
// Revoke invite
revokeInvite.get().revoke();
} else {
// Send invite
party.invitePlayer(invitedPartyPlayer, partyPlayer);
if (mustStartCooldown) {
getPlugin().getCooldownManager().startMultiAction(CooldownManager.MultiAction.INVITE, partyPlayer.getPlayerUUID(), null, ConfigParties.GENERAL_INVITE_COOLDOWN_GLOBAL);
getPlugin().getCooldownManager().startMultiAction(CooldownManager.MultiAction.INVITE, partyPlayer.getPlayerUUID(), invitedPartyPlayer.getPlayerUUID(), ConfigParties.GENERAL_INVITE_COOLDOWN_INDIVIDUAL);
}
}
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_INVITE, partyPlayer.getName(), invitedPartyPlayer.getName(), party.getName() != null ? party.getName() : party.getId(), isRevoke), true);
}
use of com.alessiodp.core.common.commands.utils.CommandData in project Parties by AlessioDP.
the class CommandDeny method onCommand.
@Override
public void onCommand(@NotNull CommandData commandData) {
User sender = commandData.getSender();
PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
// Command handling
if (partyPlayer.isInParty()) {
boolean noPendingRequests = false;
if (ConfigParties.ADDITIONAL_ASK_ENABLE) {
// Deny ask request
PartyImpl party = ((PartiesCommandData) commandData).getParty();
HashMap<String, PartyAskRequest> pendingAskRequests = new HashMap<>();
party.getAskRequests().forEach(pv -> pendingAskRequests.put(CommonUtils.toLowerCase(pv.getAsker().getName()), pv));
if (commandData.getArgs().length > 1 && !pendingAskRequests.containsKey(CommonUtils.toLowerCase(commandData.getArgs()[1]))) {
noPendingRequests = true;
} else {
PartyAskRequest partyAskRequest = null;
if (pendingAskRequests.size() > 0) {
if (pendingAskRequests.size() == 1) {
partyAskRequest = pendingAskRequests.values().iterator().next();
} else if (commandData.getArgs().length > 1) {
partyAskRequest = pendingAskRequests.get(CommonUtils.toLowerCase(commandData.getArgs()[1]));
} else {
// Missing player
sendMessage(sender, partyPlayer, Messages.MAINCMD_DENY_MULTIPLEREQUESTS);
for (Map.Entry<String, PartyAskRequest> entry : pendingAskRequests.entrySet()) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_DENY_MULTIPLEREQUESTS_PLAYER.replace("%player%", entry.getValue().getAsker().getName()), (PartyImpl) entry.getValue().getParty());
}
return;
}
} else {
noPendingRequests = true;
}
if (partyAskRequest != null) {
// Command starts
partyAskRequest.deny(partyPlayer);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_DENY_ASK, partyPlayer.getName(), partyAskRequest.getAsker().getName(), partyAskRequest.getParty().getName() != null ? partyAskRequest.getParty().getName() : "_"), true);
return;
}
}
}
if (ConfigParties.ADDITIONAL_TELEPORT_ENABLE && ConfigParties.ADDITIONAL_TELEPORT_ACCEPT_REQUEST_ENABLE) {
// Accept teleport request
HashMap<String, PartyTeleportRequest> pendingTeleportRequests = new HashMap<>();
partyPlayer.getPendingTeleportRequests().forEach(pv -> pendingTeleportRequests.put(CommonUtils.toLowerCase(pv.getRequester().getName()), pv));
if (commandData.getArgs().length > 1 && !pendingTeleportRequests.containsKey(CommonUtils.toLowerCase(commandData.getArgs()[1]))) {
noPendingRequests = true;
} else {
PartyTeleportRequest partyTeleportRequest = null;
if (pendingTeleportRequests.size() > 0) {
if (pendingTeleportRequests.size() == 1) {
partyTeleportRequest = pendingTeleportRequests.values().iterator().next();
} else if (commandData.getArgs().length > 1) {
partyTeleportRequest = pendingTeleportRequests.get(CommonUtils.toLowerCase(commandData.getArgs()[1]));
} else {
// Missing player
sendMessage(sender, partyPlayer, Messages.MAINCMD_DENY_MULTIPLEREQUESTS);
for (Map.Entry<String, PartyTeleportRequest> entry : pendingTeleportRequests.entrySet()) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_DENY_MULTIPLEREQUESTS_PLAYER.replace("%player%", entry.getValue().getRequester().getName()));
}
return;
}
} else {
noPendingRequests = true;
}
if (partyTeleportRequest != null) {
// Command starts
partyTeleportRequest.deny();
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_DENY_TELEPORT, partyPlayer.getName(), partyTeleportRequest.getRequester().getName()), true);
return;
}
}
}
if (noPendingRequests) {
if (commandData.getArgs().length > 1) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_DENY_NOEXISTS);
} else {
sendMessage(sender, partyPlayer, Messages.MAINCMD_DENY_NOREQUEST);
}
return;
}
// No ask and no teleport - already in party
sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_ALREADYINPARTY);
} else {
// Deny invite request
HashMap<String, PartyInvite> pendingInvites = new HashMap<>();
partyPlayer.getPendingInvites().stream().filter(pv -> pv.getParty().getName() != null).forEach(pv -> pendingInvites.put(CommonUtils.toLowerCase(pv.getParty().getName()), pv));
if (commandData.getArgs().length > 1 && !pendingInvites.containsKey(CommonUtils.toLowerCase(commandData.getArgs()[1]))) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_DENY_NOEXISTS);
return;
}
PartyInvite partyInvite;
if (pendingInvites.size() > 0) {
if (pendingInvites.size() == 1) {
partyInvite = pendingInvites.values().iterator().next();
} else if (commandData.getArgs().length > 1) {
partyInvite = pendingInvites.get(CommonUtils.toLowerCase(commandData.getArgs()[1]));
} else {
// Missing party
sendMessage(sender, partyPlayer, Messages.MAINCMD_DENY_MULTIPLEREQUESTS);
for (Map.Entry<String, PartyInvite> entry : pendingInvites.entrySet()) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_DENY_MULTIPLEREQUESTS_PARTY.replace("%party%", entry.getKey()), (PartyImpl) entry.getValue().getParty());
}
return;
}
} else {
sendMessage(sender, partyPlayer, Messages.MAINCMD_DENY_NOREQUEST);
return;
}
if (partyInvite == null) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_DENY_NOEXISTS);
return;
}
// Command starts
partyInvite.deny();
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_DENY_INVITE, partyPlayer.getName(), partyInvite.getParty().getName() != null ? partyInvite.getParty().getName() : "_"), true);
}
}
use of com.alessiodp.core.common.commands.utils.CommandData in project Parties by AlessioDP.
the class CommandHome method onCommand.
@Override
public void onCommand(@NotNull CommandData commandData) {
User sender = commandData.getSender();
PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
PartyImpl party = getPlugin().getPartyManager().getPartyOfPlayer(partyPlayer);
// Command handling
PartyHomeImpl partyHome = null;
if (commandData.getArgs().length == 1) {
if (party == null) {
sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_NOTINPARTY);
return;
}
if (party.getHomes().size() == 0) {
sendMessage(sender, partyPlayer, Messages.ADDCMD_HOME_NOHOME, party);
return;
}
}
if (ConfigParties.ADDITIONAL_HOME_MAX_HOMES > 1) {
// Multiple home
if (commandData.getArgs().length == 1) {
if (party.getHomes().size() > 1) {
sendMessage(sender, partyPlayer, Messages.ADDCMD_HOME_MUST_SELECT_HOME, party);
printValidHomes(sender, partyPlayer, party);
return;
}
Optional<PartyHome> opt = party.getHomes().stream().findFirst();
if (opt.isPresent())
partyHome = (PartyHomeImpl) opt.get();
else {
sendMessage(sender, partyPlayer, Messages.ADDCMD_HOME_NOHOME, party);
printValidHomes(sender, partyPlayer, party);
return;
}
} else if (commandData.getArgs().length == 2) {
// Not admin - Not in party
if (!commandData.havePermission(PartiesPermission.ADMIN_HOME_OTHERS) && party == null) {
sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_NOTINPARTY);
return;
}
// Get the partyHome of the current party
if (party != null) {
Optional<PartyHome> opt = party.getHomes().stream().filter((ph) -> ph.getName() != null && ph.getName().equalsIgnoreCase(commandData.getArgs()[1])).findAny();
if (opt.isPresent())
partyHome = (PartyHomeImpl) opt.get();
}
// If no home but home.others permission
if (partyHome == null && commandData.havePermission(PartiesPermission.ADMIN_HOME_OTHERS)) {
party = getPlugin().getPartyManager().getParty(commandData.getArgs()[1]);
if (party != null) {
if (party.getHomes().size() > 1) {
sendMessage(sender, partyPlayer, Messages.ADDCMD_HOME_MUST_SELECT_HOME, party);
printValidHomes(sender, partyPlayer, party);
return;
}
Optional<PartyHome> opt = party.getHomes().stream().findFirst();
if (opt.isPresent())
partyHome = (PartyHomeImpl) opt.get();
}
}
// Not in party
if (party == null) {
sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_NOTINPARTY);
return;
}
// No party home found
if (partyHome == null) {
sendMessage(sender, partyPlayer, Messages.ADDCMD_HOME_INVALID_HOME, party);
printValidHomes(sender, partyPlayer, party);
return;
}
} else if (commandData.getArgs().length == 3 && commandData.havePermission(PartiesPermission.ADMIN_HOME_OTHERS)) {
party = getPlugin().getPartyManager().getParty(commandData.getArgs()[1]);
if (party != null) {
Optional<PartyHome> opt = party.getHomes().stream().filter((ph) -> ph.getName() != null && ph.getName().equalsIgnoreCase(commandData.getArgs()[1])).findAny();
if (opt.isPresent())
partyHome = (PartyHomeImpl) opt.get();
else {
sendMessage(sender, partyPlayer, Messages.ADDCMD_HOME_NOHOME, party);
printValidHomes(sender, partyPlayer, party);
return;
}
} else {
sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_PARTYNOTFOUND.replace("%party%", commandData.getArgs()[1]));
return;
}
} else {
sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", getSyntaxForUser(sender)));
return;
}
} else {
// Single home
if (commandData.getArgs().length == 1) {
Optional<PartyHome> opt = party.getHomes().stream().findFirst();
if (opt.isPresent())
partyHome = (PartyHomeImpl) opt.get();
else {
sendMessage(sender, partyPlayer, Messages.ADDCMD_HOME_NOHOME, party);
return;
}
} else if (commandData.getArgs().length == 2 && commandData.havePermission(PartiesPermission.ADMIN_HOME_OTHERS)) {
party = getPlugin().getPartyManager().getParty(commandData.getArgs()[1]);
if (party != null) {
Optional<PartyHome> opt = party.getHomes().stream().findFirst();
if (opt.isPresent())
partyHome = (PartyHomeImpl) opt.get();
else {
sendMessage(sender, partyPlayer, Messages.ADDCMD_HOME_NOHOME, party);
return;
}
} else {
sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_PARTYNOTFOUND.replace("%party%", commandData.getArgs()[1]));
return;
}
} else {
sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", getSyntaxForUser(sender)));
return;
}
}
if (!commandData.havePermission(PartiesPermission.ADMIN_HOME_OTHERS) && !getPlugin().getRankManager().checkPlayerRankAlerter(partyPlayer, RankPermission.HOME))
return;
if (partyPlayer.getPendingHomeDelay() != null) {
sendMessage(sender, partyPlayer, Messages.ADDCMD_HOME_TELEPORTWAITING, party);
return;
}
boolean mustStartCooldown = false;
if (ConfigParties.ADDITIONAL_HOME_COOLDOWN_HOME > 0 && !commandData.havePermission(PartiesPermission.ADMIN_COOLDOWN_HOME_BYPASS)) {
mustStartCooldown = true;
long remainingCooldown = getPlugin().getCooldownManager().canAction(CooldownManager.Action.HOME, sender.getUUID(), ConfigParties.ADDITIONAL_HOME_COOLDOWN_HOME);
if (remainingCooldown > 0) {
sendMessage(sender, partyPlayer, Messages.ADDCMD_HOME_COOLDOWN.replace("%seconds%", String.valueOf(remainingCooldown)));
return;
}
}
if (getPlugin().getEconomyManager().payCommand(EconomyManager.PaidCommand.HOME, partyPlayer, commandData.getCommandLabel(), commandData.getArgs()))
return;
if (mustStartCooldown)
getPlugin().getCooldownManager().startAction(CooldownManager.Action.HOME, sender.getUUID(), ConfigParties.ADDITIONAL_HOME_COOLDOWN_HOME);
// Command starts
int delay = ConfigParties.ADDITIONAL_HOME_DELAY;
String homeDelayPermission = sender.getDynamicPermission(PartiesPermission.USER_HOME + ".");
if (homeDelayPermission != null) {
try {
delay = Integer.parseInt(homeDelayPermission);
} catch (Exception ignored) {
}
}
if (delay > 0) {
HomeDelayTask homeDelayTask = teleportPlayerWithDelay(partyPlayer, partyHome, delay);
CancellableTask task = plugin.getScheduler().scheduleAsyncRepeating(homeDelayTask, 0, 300, TimeUnit.MILLISECONDS);
partyPlayer.setPendingHomeDelay(task);
sendMessage(sender, partyPlayer, Messages.ADDCMD_HOME_TELEPORTIN.replace("%seconds%", Integer.toString(delay)));
} else {
teleportPlayer(sender, partyPlayer, partyHome);
}
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_HOME, partyPlayer.getName(), party.getName() != null ? party.getName() : "_", CommonUtils.getNoEmptyOr(partyHome.getName(), "default")), true);
}
Aggregations