@Override
    public Iterator<DiscoItem> getItems(String name, String node, JID senderJID) {
        List<DiscoItem> answer = new ArrayList<>();
        if (!NAMESPACE.equals(node)) {
            answer = Collections.emptyList();
        }
        else {
            for (AdHocCommand command : manager.getCommands()) {
                // Only include commands that the sender can invoke (i.e. has enough permissions)
                if (command.hasPermission(senderJID)) {
                    final DiscoItem item = new DiscoItem(new JID(serverName),
                            command.getLabel(), command.getCode(), null);
                    answer.add(item);
                }
            }
        }
        return answer.iterator();
    }
Manager that keeps the list of ad-hoc commands and processing command requests.
xmppserver/src/main/java/org/jivesoftware/openfire/commands/AdHocCommandHandler.java