class GetListIdleUsers extends AdHocCommand {

    @Override
    protected void addStageInformation(@Nonnull final SessionData data, Element command) {
        final Locale preferredLocale = SessionManager.getInstance().getLocaleForSession(data.getOwner());

        DataForm form = new DataForm(DataForm.Type.form);
        form.setTitle(LocaleUtils.getLocalizedString("commands.admin.getlistidleusers.form.title", preferredLocale));
        form.addInstruction(LocaleUtils.getLocalizedString("commands.admin.getlistidleusers.form.instruction", preferredLocale));

        FormField field = form.addField();
        field.setType(FormField.Type.hidden);
        field.setVariable("FORM_TYPE");
        field.addValue("http://jabber.org/protocol/admin");

        field = form.addField();
        field.setType(FormField.Type.list_single);
        field.setLabel(LocaleUtils.getLocalizedString("commands.global.operation.pagination.max_items", preferredLocale));
        field.setVariable("max_items");
        field.addOption("25", "25");
        field.addOption("50", "50");
        field.addOption("75", "75");
        field.addOption("100", "100");
        field.addOption("150", "150");
        field.addOption("200", "200");
        field.addOption(LocaleUtils.getLocalizedString("commands.global.operation.pagination.none", preferredLocale), "none");

        // Add the form to the command
        command.add(form.getElement());
    }

    @Override
    public void execute(@Nonnull final SessionData data, Element command) {<FILL_FUNCTION_BODY>}

    @Override
    public String getCode() {
        return "http://jabber.org/protocol/admin#get-idle-users";
    }

    @Override
    public String getDefaultLabel() {
        return LocaleUtils.getLocalizedString("commands.admin.getlistidleusers.label");
    }

    @Override
    protected List<Action> getActions(@Nonnull final SessionData data) {
        return Collections.singletonList(Action.complete);
    }

    @Override
    protected Action getExecuteAction(@Nonnull final SessionData data) {
        return Action.complete;
    }

    @Override
    public int getMaxStages(@Nonnull final SessionData data) {
        return 1;
    }
}

        final Locale preferredLocale = SessionManager.getInstance().getLocaleForSession(data.getOwner());

        int maxItems = -1;
        final List<String> max_items_data = data.getData().get("max_items");
        if (max_items_data != null && !max_items_data.isEmpty()) {
            String max_items = max_items_data.get(0);
            if (max_items != null && !"none".equals(max_items)) {
                try {
                    maxItems = Integer.parseInt(max_items);
                } catch (NumberFormatException e) {
                    // Do nothing. Assume that all users are being requested
                }
            }
        }

        DataForm form = new DataForm(DataForm.Type.result);

        FormField field = form.addField();
        field.setType(FormField.Type.hidden);
        field.setVariable("FORM_TYPE");
        field.addValue("http://jabber.org/protocol/admin");

        field = form.addField();
        field.setType(FormField.Type.jid_multi);
        field.setLabel(LocaleUtils.getLocalizedString("commands.admin.getlistidleusers.form.field.activeuserjids.label", preferredLocale));
        field.setVariable("activeuserjids"); // The XEP uses this variable ('active') rather than something like 'idleuserjids'.

        // Make sure that we are only counting based on bareJIDs and not fullJIDs
        Collection<ClientSession> sessions = SessionManager.getInstance().getSessions();
        Set<String> users = new HashSet<>(sessions.size());
        for (ClientSession session : sessions) {
            if (!session.getPresence().isAvailable()) {
                users.add(session.getAddress().toBareJID());

                if (maxItems > 0 && users.size() >= maxItems) {
                    break;
                }
            }
        }

        // Add users to the result
        for (String user : users) {
            field.addValue(user);
        }
        command.add(form.getElement());
    
<methods>public void <init>() ,public void addNextStageInformation(org.jivesoftware.openfire.commands.SessionData, Element) ,public void addPreviousStageInformation(org.jivesoftware.openfire.commands.SessionData, Element) ,public abstract void execute(org.jivesoftware.openfire.commands.SessionData, Element) ,public abstract java.lang.String getCode() ,public abstract java.lang.String getDefaultLabel() ,public java.lang.String getLabel() ,public abstract int getMaxStages(org.jivesoftware.openfire.commands.SessionData) ,public boolean hasPermission(JID) ,public void setLabel(java.lang.String) <variables>private java.lang.String label