# SignEdit

`com.jsmacrosce.jsmacros.client.api.event.impl.player.EventSignEdit`

**Since:** 1.2.7

**Cancellable:** Yes. Call `event.cancel()` in a handler before releasing the event lock.

Fires when the local player opens a sign editing screen. A joined listener can cancel the event
or call `setShouldCloseScreen(...)` to prevent the screen from opening and send the edited
text to the server. Changed text is also applied to the local sign immediately.  
`getSignText()` starts with the sign's current text; only its first four entries are used,  
missing entries become empty, and `null` blanks all four lines.  
```js
JsMacros.on("SignEdit", true, JavaWrapper.methodToJava(function (event) {
  const text = event.getSignText();  
  if (text === null) {
    return;  
  }
  let blocked = false;  
  for (const line of text) {
    if (line.includes("badWord")) {
      blocked = true;  
    }
  }
  if (blocked) {
    // rewrite the text, then send the edit without ever opening the editor
    let i = 0;  
    while (i !== text.size()) {
      text.set(i, text.get(i).replaceAll("badWord", "***"));  
      i += 1;  
    }
    event.cancel();  
    return;  
  }
  Chat.log(`Editing sign at ${event.pos.x}, ${event.pos.y}, ${event.pos.z}`);  
}))
```

## Constructors

### new EventSignEdit {#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventSignEdit_constructor-List-int-int-int-boolean-}

```js
new EventSignEdit(List<String> signText, int x, int y, int z, boolean front)
```

Initializes the event with its client core, block position, edited text, and sign side.  
The supplied coordinates are integer block coordinates stored in a new [Pos3D](../../../../../../../../../classes/com/jsmacrosce/jsmacros/api/math/Pos3D.md);  
`front` is stored unchanged. `signText` is copied without normalizing it, so
later changes to the passed list do not affect this event.

**Parameters:**
- `signText`: the text list to copy, or `null`
- `x`: the block-coordinate x position
- `y`: the block-coordinate y position
- `z`: the block-coordinate z position
- `front`: whether the edited side is the front; `false` denotes the back

## Fields

### closeScreen {#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventSignEdit_closeScreen}

```js
closeScreen: boolean
```

Whether to send the edit without opening the screen; defaults to `false`. Setting it
to `true` has the same effect as cancelling the event.

**Deprecated:** Removal in 3.0.0: Use [shouldCloseScreen()](#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventSignEdit_shouldCloseScreen-) and [setShouldCloseScreen(boolean)](#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventSignEdit_setShouldCloseScreen-boolean-) instead.

### front {#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventSignEdit_front}

```js
front: boolean
```

`true` when editing the front side; `false` when editing the back side.

**Deprecated:** Removal in 3.0.0: Use [isFront()](#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventSignEdit_isFront-) instead.

### pos {#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventSignEdit_pos}

```js
pos: Pos3D
```

The sign's block position in block coordinates.

### signText {#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventSignEdit_signText}

```js
signText: List<String>
```

The sign's four text lines, initially copied from the current sign text. Only the first four
entries are used; missing entries become empty, and `null` blanks all four lines.

**Deprecated:** Removal in 3.0.0: Use [getSignText()](#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventSignEdit_getSignText-) and [setSignText(List)](#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventSignEdit_setSignText-List-) instead.

## Methods

### getSignText {#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventSignEdit_getSignText-}

```js
getSignText(): List<String>
```

Returns the sign's text lines. A joined delivery receives a live, checked list; a non-joined
or already released delivery receives an unmodifiable view. A retained live list can still be
read after release, but writes through it are checked when they happen.

**Returns:** the current text list, an unmodifiable view, or `null` to blank all four lines

**Since:** 2.2.0

### isFront {#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventSignEdit_isFront-}

```js
isFront(): boolean
```

Returns whether the edited side is the front.

**Returns:** `true` for the front side; `false` for the back

**Since:** 2.2.0

### setShouldCloseScreen {#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventSignEdit_setShouldCloseScreen-boolean-}

```js
setShouldCloseScreen(boolean shouldCloseScreen): void
```

Chooses whether to send the edit without opening the screen. `true` has the same effect
as cancelling the event.

**Parameters:**
- `shouldCloseScreen`: `true` to send the edit without opening the screen

**Since:** 2.2.0

### setSignText {#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventSignEdit_setSignText-List-}

```js
setSignText(List<String> signText): void
```

Replaces the text lines. Only the first four entries are used; missing entries become empty,  
and `null` blanks all four lines. The list is copied, so later changes to the passed
list do not affect the event.

**Parameters:**
- `signText`: replacement list, or `null` to blank all four lines

**Since:** 2.2.0

### shouldCloseScreen {#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventSignEdit_shouldCloseScreen-}

```js
shouldCloseScreen(): boolean
```

Returns whether the edit should skip the sign editor and be sent immediately.

**Returns:** `true` when the screen should stay closed

**Since:** 2.2.0

### toString {#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventSignEdit_toString-}

```js
toString(): String
```

Returns a diagnostic string containing the event name and current position in the form
`%s:{"pos": [%s]}`; the position is enclosed in square brackets. It omits the text,  
side, and screen-close flag, and is not a serialization of the full event.

**Returns:** the event name and current position in diagnostic format
