code: public Listener<CopycatServer.State> onStateChange(Consumer<CopycatServer.State> listener) {
      return stateChangeListeners.add(listener);
    }
docs: Registers a state change listener.
  
  @param listener The state change listener.
  @return The listener context.