Edit

ObservableString Class

An observable that holds a string value. Listeners are notified whenever the value changes.

Methods

constructor

new ObservableString(data: string, options?: ObservableOptions)

Creates a new ObservableString with the provided initial string value.

Parameters

  • data: string

    The initial string value for this observable.

  • options?: ObservableOptions = null

    Optional configuration for the observable, such as whether the value can be written by the client.

Returns ObservableString

Notes:

  • This function can't be called in restricted-execution mode.
  • This function can be called in early-execution mode.

getData

getData(): string

Returns the current string value held by this observable.

Returns string

Notes:

  • This function can't be called in restricted-execution mode.
  • This function can be called in early-execution mode.

getFilteredText

getFilteredText(player: minecraftserver.Player): Promise<TextFilteringError[] | string>

Gets filtered data from the Observable (only available for strings). In case of failure, it will return an array of TextFilteringError that can provide more context about the filtering process. For testing purposes, the options are available under 'Creator -> Text Filtering' settings menu. This delay is only applied to the getFilteredText function and can be used to simulate network latency when testing.

Parameters

Returns Promise<TextFilteringError[] | string>

Notes:

setData

setData(data: string): void

Updates the string value held by this observable. If the new value differs from the current value, all subscribed listeners are notified with the new value.

Parameters

  • data: string

    The new string value to set.

Notes:

  • This function can't be called in restricted-execution mode.
  • This function can be called in early-execution mode.

subscribe

subscribe(callback: (arg0: string) => void): (arg0: string) => void

Registers a callback to be invoked whenever the observable's value changes. Returns the callback, which can be passed to unsubscribe to remove the listener.

Parameters

  • callback: (arg0: string) => void

    A function that receives the new string value each time the observable changes.

Returns (arg0: string) => void

Notes:

  • This function can't be called in restricted-execution mode.
  • This function can be called in early-execution mode.

unsubscribe

unsubscribe(callback: (arg0: string) => void): boolean

Removes a previously registered listener from this observable. Returns true if the listener was found and removed, false if it was not found.

Parameters

  • callback: (arg0: string) => void

    The callback handle previously returned by subscribe.

Returns boolean

Notes:

  • This function can't be called in restricted-execution mode.
  • This function can be called in early-execution mode.