From fe256dc916c317358dd8f6707e1bc08a0127b62a Mon Sep 17 00:00:00 2001 From: CarmJos Date: Wed, 5 Jan 2022 04:39:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E5=AD=98=E5=82=A8=E7=9A=84=E5=BC=80=E5=8F=91=E4=BB=8B=E7=BB=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .documentation/README.md | 6 + .documentation/develop/use-custome-storage.md | 105 ++++++++++++++++++ .github/ISSUE_TEMPLATE/bugs_report.md | 14 +-- .github/ISSUE_TEMPLATE/feature_issues.md | 8 +- README.md | 4 + 5 files changed, 126 insertions(+), 11 deletions(-) create mode 100644 .documentation/develop/use-custome-storage.md diff --git a/.documentation/README.md b/.documentation/README.md index eaaa73c..cc4aba4 100644 --- a/.documentation/README.md +++ b/.documentation/README.md @@ -14,3 +14,9 @@ ## [开发文档](JAVADOC-README.md) 基于 [Github Pages](https://pages.github.com/) 搭建,请访问 [JavaDoc](https://carmjos.github.io/UltraDepository) 。 + +## 插件介绍目录 + +- [使用]() +- [开发](develop) + - [自定义存储源](develop/use-custome-storage.md) \ No newline at end of file diff --git a/.documentation/develop/use-custome-storage.md b/.documentation/develop/use-custome-storage.md new file mode 100644 index 0000000..9f835a9 --- /dev/null +++ b/.documentation/develop/use-custome-storage.md @@ -0,0 +1,105 @@ +# 开发 - 自定义存储源 + +在某些情况下,插件提供的几种存储方式并不能满足您的需求,此时您可以选择在您自己的插件中自定义本插件的存储源。 + +## 1. 修改 plugin.yml + +您需要在您自己的插件中声明依赖了本插件,即在 `plugin.yml` 中添加以下内容: + +```yaml +softdepend: + - UltraDepository +``` + +添加后,Bukkit会让您的插件在本插件之后加载,此时您就可以应用您的存储源。 + +## 2. 依赖本插件 + +请依据 [开发指南](../README.md) 中的依赖介绍部分完成对本插件的依赖。 + +## 3. 实现 DataStorage + +您需要在您的插件中实现 DataStorage 类,并实现其中的功能,他看起来像是这样的: + +```java + +import cc.carm.plugin.ultradepository.data.UserData; +import cc.carm.plugin.ultradepository.storage.DataStorage; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.TestOnly; + +import java.util.UUID; + +public class CustomStorage implements DataStorage { + + @Override + public boolean initialize() { + //初始化存储,在这里可进行连接数据库、创建表等操作。 + + return true; //返回true代表初始化成功,若失败则插件将不再加载 + } + + @Override + public void shutdown() { + // 插件卸载时触发,一般用于释放连接池。 + } + + @Override + public @Nullable UserData loadData(@NotNull UUID uuid) throws Exception { + // 加载玩家数据部分 + // 若抛出错误,则视为加载出错,会采用临时玩家数据的形式保证插件继续运行,同时在后台提示检查。 + // 返回空则代表暂无该玩家数据,会自动视作新数据 + return null; + } + + @Override + public void saveUserData(@NotNull UserData data) throws Exception { + // 保存玩家数据部分 + // 若抛出错误,则视为保存出错,将在后台提示检查。 + } + +} +``` + +您也可以 [点击这里](../../src/main/java/cc/carm/plugin/ultradepository/storage/impl) 参考本插件提供的其他已实现的存储方式,并在此基础上开发您的自定义存储。 + +> 若您需要JSON格式存储,可以直接继承 [`JSONStorage`](../../src/main/java/cc/carm/plugin/ultradepository/storage/impl/JSONStorage.java) ,并重写相关方法。 + +## 4. 应用您的存储 + +您需要在插件加载(`onLoad()`)时,应用您的自定义存储。 + +```java + +import cc.carm.plugin.ultradepository.storage.DataStorage; +import cc.carm.plugin.ultradepository.storage.StorageMethod; +import cc.carm.plugin.ultradepository.storage.impl.CustomStorage; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.function.Supplier; + +public class YourPlugin extends JavaPlugin { + + @Override + public void onLoad() { + + // 应用您的存储方式 + StorageMethod.CUSTOM.setStorageSupplier(new Supplier() { + @Override + public DataStorage get() { + return new CustomStorage(); + } + }); + + // 简化后大概长这样(lamda) + StorageMethod.CUSTOM.setStorageSupplier(CustomStorage::new); + } +} +``` + +## 5. 修改本插件的 config.yml + +您需要修改本插件的 `config.yml` 中的 `storage.method` 为 **CUSTOM** 。 + +修改完成后,在插件下次启动时就将应用您实现的 **DataStorage** 从而完成自定义存储源。 \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/bugs_report.md b/.github/ISSUE_TEMPLATE/bugs_report.md index e163a00..6c6a5a3 100644 --- a/.github/ISSUE_TEMPLATE/bugs_report.md +++ b/.github/ISSUE_TEMPLATE/bugs_report.md @@ -1,30 +1,30 @@ --- name: 问题提交 -about: 提交并描述问题,帮助我们对其进行检查与修复。 +about: 描述问题并提交,帮助我们对其进行检查与修复。 title: '' labels: bug assignees: '' --- -**问题简述** +### **问题简述** 用简短的话语描述一下大概问题。 -**问题来源** +### **问题来源** 描述一下通过哪些操作才发现的问题,如: 1. 打开 '...' 2. 点击了 '....' 3. 出现了报错 '....' -**预期结果**(可选) +### **预期结果**(可选) 如果问题不发生,应该是什么情况 -**问题截图/问题报错** +### **问题截图/问题报错** 如果有报错或输出,请提供截图。 -**操作环境** +### *操作环境** 请在后台输入 `version` 并复制相关输出。 -**其他补充** +### **其他补充** 如有其他补充,可以在这里描述。 diff --git a/.github/ISSUE_TEMPLATE/feature_issues.md b/.github/ISSUE_TEMPLATE/feature_issues.md index b7e7f40..9407bad 100644 --- a/.github/ISSUE_TEMPLATE/feature_issues.md +++ b/.github/ISSUE_TEMPLATE/feature_issues.md @@ -7,14 +7,14 @@ assignees: '' --- -**功能简述** +### **功能简述** 简单的描述一下你想要的功能 -**需求来源** +### **需求来源** 简单的描述一下为什么需要这个功能。 -**功能参考**(可选) +### **功能参考**(可选) 如果有相关功能的参考,如文本、截图,请提供给我们。 -**附加内容** +### **附加内容** 如果有什么小细节需要重点注意,请在这里告诉我们。 diff --git a/README.md b/README.md index 482c011..cbe8925 100644 --- a/README.md +++ b/README.md @@ -217,6 +217,10 @@ 您也可以 [点击这里](.examples/depositories/full-example.yml) 查看一份*详细的仓库配置示例*,以制作您自己的仓库。 +## 开发 + +详细开发介绍请 [点击这里](.documentation/README.md) , JavaDoc(最新Release) 请 [点击这里](https://carmjos.github.io/UltraDepository) 。 + ## 使用统计 [![bStats](https://bstats.org/signatures/bukkit/UltraDepository.svg)](https://bstats.org/plugin/bukkit/UltraDepository/13777)