# 变量符输出替换

## 关于

大部分变量符无法自定义它的输出内容，这使得你无法让它们显示你希望它们显示的样子。例如你需要显示玩家是否在挂机或者隐形，可这些插件的变量符只会显示 "yes" 或者 "no" 而不是一些炫酷的文本。这些插件本应该提供自定义的功能，但是它们没有，所以 TAB 为你提供这个功能。

## 配置

打开 **config.yml** 并找到如下部分:

```
placeholder-output-replacements:
  <placeholder>:
    <original output>: <new output>
```

### 支持的替换模式

#### 模式 1: 准确文本

让一个变量符的输出内容准确的满足左侧内容，那么它将会被替换为右侧的内容。\
示例:

```
placeholder-output-replacements:
  "%tps%":
    "20": "Running at perfect 20 TPS!"
  "%essentials_vanished%":
    "yes": " &7[V]"
    "no": ""
```

**注意 1:** 如果你希望替换后不显示文本，在左侧填写 `""` 或者 `''` 即可。

**注意 2:** 内容必须十分精确，包括颜色代码。要检查该变量符包含的颜色代码，你可以使用命令  [`/tab parse <player> <placeholder>`](https://github.com/NEZNAMY/TAB/wiki/Commands-&-Permissions#tab-parse-text) 并查看 "无颜色"。

#### 模式 2: 数字间隔

如果一个变量符输出的内容在一个间隔内，那么它将会被替换。\
示例:

```
placeholder-output-replacements:
  "%tps%": #服务器TPS
    "15-20": "还可以"
    "5-15": "有的糟"
    "0-5": "糟糕"
```

**注意:** 如果一个数字包含在超过 1 个间隔中(就像上面的 5 和 15)。间隔上限大的将会被使用。这样的话，15 将会显示 `还可以` 并且 5 将会显示 `有的糟`。

#### 模式 3: else（或者）

如果变量符输出的结果不满足所设置的所有预定值（即右侧内容），并且 "else" 模式也被设置，那么替换的内容将会使用 "else" 所设置的内容。\
示例:

```
placeholder-output-replacements:
  "%tps%":
    "20": "非常完美的 20 TPS!"
    "15-20": "还可以"
    "5-15": "有点糟"
    "else": "太糟糕了" #这种情况下else就是0-5 ，因为TPS只能是0-20
```

### 替换值中支持的内容

你可以使用其他变量符作为替换后的内容，但你不能使用与替换前相同的变量符，因为这只会导致死循环。\
要避免这个问题，你可以使用 `%value%` 来显示该变量符本来将会显示的内容。\
示例

```
placeholder-output-replacements:
  "%tps%":
    "20": "Running at perfect 20 TPS!"
    "15-20": "%value% (Solid)"
    "5-15": "%value% (Bad)"
    "else": "%value% (Terrible)"
```

在这个示例中，如果 TPS 达到 17.5，那么替换后的实际输出值是 `17.5 (Solid)`。

## 在其他插件使用

这些替换将只在 TAB 内部使用，其他插件不会被替换。\
如果你希望在其他插件使用这些替换变量符，你只需要 TAB 插件的变量符拓展（将会自动安装），并使用 `%tab_replace_<变量符>%`。例如你想要 TAB 替换后的 %player\_health% 变量符，只需使用 `%tab_replace_player_health%` 变量符即可显示。

这只支持 PlaceholderAPI 的变量符，并且不能是 TAB 的内部变量符。要使用 TAB 的内部变量符，请使用 `%tab_placeholder_<变量符>`, 例如 %health% 使用 `%tab_placeholder_health%`。

## 附加信息

### 附加注意 1

如果你使用的变量符包含 `.` (例如检查玩家是否有某个权限节点)，以前的格式将不起作用。这是因为 `.` 符号被用于间隔配置文件之间选项的路径。要使得这种变量符正常工作，只需在每个带有 `.` 的地方拆分。示例：使用 `%player_has_permission_test.permission%` 权限节点

```
placeholder-output-replacements:
  "%player_has_permission_test":
    "permission%":
      yes: "Permission present"
      no: "No permission"
```

## 提示

如果你在 BC 服安装了 TAB 并且不希望在变量符尚未加载好之前显示它本来的样子，你可以使用这个功能来实现没加载好之前的内容自动被替换。示例：

```
placeholder-output-replacements:
  "%my_placeholder%":
    "%my_placeholder%": "" # 当变量符尚未加载好时，它就是空的，而不是以前的显示变量符本来的样子
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.superiormc.cn/tab-wiki/functions/bian-liang-fu-shu-chu-ti-huan.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
