use of com.alessiodp.core.common.commands.utils.ADPExecutableCommand in project Parties by AlessioDP.
the class CommandHelp method onCommand.
@Override
public void onCommand(@NotNull CommandData commandData) {
User sender = commandData.getSender();
PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
// Command starts
// Get all allowed commands
LinkedList<String> list = new LinkedList<>();
Set<ADPCommand> allowedCommands = partyPlayer.getAllowedCommands();
for (Map.Entry<ADPCommand, ADPExecutableCommand> e : plugin.getCommandManager().getOrderedCommands().entrySet()) {
if (allowedCommands.contains(e.getKey()) && e.getValue().isListedInHelp()) {
list.add(e.getValue().getHelp().replace("%syntax%", e.getValue().getSyntaxForUser(sender)).replace("%description%", e.getValue().getDescription() != null ? e.getValue().getDescription() : "").replace("%run_command%", e.getValue().getRunCommand()).replace("%perform_command%", Messages.HELP_PERFORM_COMMAND));
}
}
// Split commands per page
int page = 1;
int maxpages;
if (list.size() == 0)
maxpages = 1;
else if ((list.size() % ConfigMain.COMMANDS_HELP_PERPAGE) == 0)
maxpages = list.size() / ConfigMain.COMMANDS_HELP_PERPAGE;
else
maxpages = (list.size() / ConfigMain.COMMANDS_HELP_PERPAGE) + 1;
if (commandData.getArgs().length > 1) {
try {
page = Integer.parseInt(commandData.getArgs()[1]);
} catch (NumberFormatException ignored) {
}
if (page > maxpages || page < 1)
page = maxpages;
}
// Start printing
int commandNumber = 0;
sendMessage(sender, partyPlayer, Messages.HELP_HEADER.replace("%page%", Integer.toString(page)).replace("%maxpages%", Integer.toString(maxpages)));
for (String string : list) {
int currentChoosenPage = (page - 1) * ConfigMain.COMMANDS_HELP_PERPAGE;
if (commandNumber >= currentChoosenPage && commandNumber < currentChoosenPage + ConfigMain.COMMANDS_HELP_PERPAGE) {
sendMessage(sender, partyPlayer, string);
}
commandNumber++;
}
sendMessage(sender, partyPlayer, Messages.HELP_FOOTER.replace("%page%", Integer.toString(page)).replace("%maxpages%", Integer.toString(maxpages)));
}
Aggregations