> For the complete documentation index, see [llms.txt](https://doc.stellarvan.cn/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.stellarvan.cn/readme/kai-fa-ji-chu/pei-zhi-wen-jian-yu-shu-ju.md).

# 配置文件与数据

## 配置文件与数据

大多数插件都需要两类数据：

* 配置数据
* 运行数据或玩家数据

这两类数据不要混在一起。

### 读取 `config.yml`

你可以先放一个默认配置文件。

{% code title="config.yml" %}

```yaml
join-message: "欢迎来到服务器。"
heal-amount: 20
```

{% endcode %}

然后在插件启用时加载它。

{% code title="MyPlugin.java" %}

```java
@Override
public void onEnable() {
    saveDefaultConfig();
}
```

{% endcode %}

读取配置也很直接。

{% code title="JoinListener.java" %}

```java
String message = plugin.getConfig().getString("join-message", "欢迎。");
int healAmount = plugin.getConfig().getInt("heal-amount", 20);
```

{% endcode %}

### 什么时候用哪种存储

#### `config.yml`

适合存静态配置。

比如：

* 开关
* 提示文本
* 数值参数

#### 自定义 YAML 文件

适合中小规模的数据。

比如：

* 出生点列表
* 区域设置
* 简单玩家缓存

#### 数据库

适合结构化和长期数据。

比如：

* 玩家经济
* 成就记录
* 跨服同步数据

### 保存数据时要注意什么

* 不要每次事件触发都立刻写盘
* 不要把所有数据都塞进一个文件
* 关闭插件前记得落盘
* 读写量大时考虑异步处理

### 一个简单原则

先用最简单的方案。

单服小插件通常先从 `config.yml` 或自定义 YAML 开始就够了。 只有在数据量和复杂度上来后，再考虑数据库。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://doc.stellarvan.cn/readme/kai-fa-ji-chu/pei-zhi-wen-jian-yu-shu-ju.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
