@Override
    public void execute(@Nonnull SessionData sessionData, Element command) {
        final Locale preferredLocale = SessionManager.getInstance().getLocaleForSession(sessionData.getOwner());

        Element note = command.addElement("note");
        Collection<JID> admins = XMPPServer.getInstance().getAdmins();
        if (admins.size() <= 0) {
            note.addAttribute("type", "error");
            note.setText(LocaleUtils.getLocalizedString("commands.admin.muc.createmucroom.note.server-needs-admin", preferredLocale));
            return;
        }
        Map<String, List<String>> data = sessionData.getData();

        // Let's find the requested MUC service to create the room in
        String servicehostname = get(data, "servicename", 0);
        if (servicehostname == null) {
            note.addAttribute("type", "error");
            note.setText(LocaleUtils.getLocalizedString("commands.admin.muc.createmucroom.note.servicename-missing", preferredLocale));
            return;
        }
        // Remove the server's domain name from the passed hostname
        String servicename = servicehostname.replace("."+XMPPServer.getInstance().getServerInfo().getXMPPDomain(), "");
        MultiUserChatService mucService;
        mucService = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(servicename);
        if (mucService == null) {
            note.addAttribute("type", "error");
            note.setText(LocaleUtils.getLocalizedString("commands.admin.muc.createmucroom.note.servicename-invalid", preferredLocale));
            return;
        }
        if (!mucService.isServiceEnabled()) {
            note.addAttribute("type", "error");
            note.setText(LocaleUtils.getLocalizedString("commands.admin.muc.createmucroom.note.service-disabled", preferredLocale));
            return;
        }
        // Let's create the jid and check that they are a local user
        String roomname = get(data, "roomname", 0);
        if (roomname == null) {
            note.addAttribute("type", "error");
            note.setText(LocaleUtils.getLocalizedString("commands.admin.muc.createmucroom.note.roomname-missing", preferredLocale));
            return;
        }
        roomname = JID.nodeprep(roomname);
        JID admin = admins.iterator().next();

        boolean isPersistent;
        try {
            final String value = get( data, "persistent", 0 );
            if ( value == null ) { // this field is not required.
                isPersistent = false;
            } else {
                isPersistent = DataForm.parseBoolean( value );
            }
        } catch ( ParseException e ) {
            note.addAttribute("type", "error");
            note.setText(LocaleUtils.getLocalizedString("commands.admin.muc.createmucroom.note.persistent-invalid", preferredLocale));
            return;
        }

        boolean isPublic;
        try {
            final String value = get( data, "public", 0 );
            if ( value == null ) { // this field is not required.
                isPublic = false;
            } else {
                isPublic = DataForm.parseBoolean( value );
            }
        } catch ( ParseException e ) {
            note.addAttribute("type", "error");
            note.setText(LocaleUtils.getLocalizedString("commands.admin.muc.createmucroom.note.public-invalid", preferredLocale));
            return;
        }

        final Lock lock = mucService.getChatRoomLock(roomname);
        lock.lock();
        try {
            MUCRoom room;
            try {
                room = mucService.getChatRoom(roomname, admin);
            }
            catch (NotAllowedException e) {
                note.addAttribute("type", "error");
                String localeKey = switch(e.getReason()) {
                    case ROOM_RETIRED -> "commands.admin.muc.createmucroom.note.retired";
                    case INSUFFICIENT_PERMISSIONS -> "commands.admin.muc.createmucroom.note.no-permission";
                };
                note.setText(LocaleUtils.getLocalizedString(localeKey, preferredLocale));
                return;
            }

            room.setPersistent(isPersistent);
            room.setPublicRoom(isPublic);

            String password = get(data, "password", 0);
            if (password != null) {
                room.setPassword(password);
            }

            // Make sure that other cluster nodes see the changes made here.
            mucService.syncChatRoom(room);
        } finally {
            lock.unlock();
        }
    }
Allows via AdHoc commands the creation of a Multi-User Chat room.

@author Alexander Wenckus
xmppserver/src/main/java/org/jivesoftware/openfire/commands/admin/muc/CreateMUCRoom.java