public synchronized void changeNickname(Resourcepart nickname) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, MucNotJoinedException  {
        Objects.requireNonNull(nickname, "Nickname must not be null or blank.");
        // Check that we already have joined the room before attempting to change the
        // nickname.
        if (!joined) {
            throw new MucNotJoinedException(this);
        }
        final EntityFullJid jid = JidCreate.entityFullFrom(room, nickname);
        // We change the nickname by sending a presence packet where the "to"
        // field is in the form "roomName@service/nickname"
        // We don't have to signal the MUC support again
        Presence joinPresence = new Presence(Presence.Type.available);
        joinPresence.setTo(jid);

        // Wait for a presence packet back from the server.
        StanzaFilter responseFilter =
            new AndFilter(
                FromMatchesFilter.createFull(jid),
                new StanzaTypeFilter(Presence.class));
        StanzaCollector response = connection.createStanzaCollectorAndSend(responseFilter, joinPresence);
        // Wait up to a certain number of seconds for a reply. If there is a negative reply, an
        // exception will be thrown
        response.nextResultOrThrow();

        // TODO: Shouldn't this handle nickname rewriting by the MUC service?
        setNickname(nickname);
    }
public synchronized void changeNickname ( Resourcepart nickname ) throws NoResponseException , XMPPErrorException , NotConnectedException , InterruptedException , MucNotJoinedException { Objects . requireNonNull ( nickname , "Nickname must not be null or blank." ) ; if ( ! joined ) { throw new MucNotJoinedException ( this ) ; } final EntityFullJid jid = JidCreate . entityFullFrom ( room , nickname ) ; Presence joinPresence = new Presence ( Presence . Type . available ) ; joinPresence . setTo ( jid ) ; StanzaFilter responseFilter = new AndFilter ( FromMatchesFilter . createFull ( jid ) , new StanzaTypeFilter ( Presence . class ) ) ; StanzaCollector response = connection . createStanzaCollectorAndSend ( responseFilter , joinPresence ) ; response . nextResultOrThrow ( ) ; setNickname ( nickname ) ; }
Changes the occupant's nickname to a new nickname within the room. Each room occupant
will receive two presence packets. One of type "unavailable" for the old nickname and one
indicating availability for the new nickname. The unavailable presence will contain the new
nickname and an appropriate status code (namely 303) as extended presence information. The
status code 303 indicates that the occupant is changing his/her nickname.

@param nickname the new nickname within the room.
@throws XMPPErrorException if the new nickname is already in use by another occupant.
@throws NoResponseException if there was no response from the server.
@throws NotConnectedException
@throws InterruptedException
@throws MucNotJoinedException