From 138b1337ac8f097c9b08e2d76f2a6b00858058e5 Mon Sep 17 00:00:00 2001 From: ddaodan <731882332@qq.com> Date: Sun, 14 Jul 2024 01:25:47 +0800 Subject: [PATCH] =?UTF-8?q?2.1=20-=20=E6=8E=A5=E5=85=A5bStats=20-=20?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=EF=BC=8C?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9B=B4=E6=96=B0=E5=8A=9F=E8=83=BD=EF=BC=8C?= =?UTF-8?q?=E7=8E=B0=E5=9C=A8=E6=9B=B4=E6=96=B0=E6=8F=92=E4=BB=B6=E5=BA=94?= =?UTF-8?q?=E8=AF=A5=E4=B8=8D=E7=94=A8=E5=86=8D=E5=A4=87=E4=BB=BD=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E4=BA=86=20-=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=BA=86gradle=E4=B8=AD=E9=94=99=E8=AF=AF=E7=9A=84=E4=BE=9D?= =?UTF-8?q?=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 8 +++-- changelog.md | 4 +++ readme.md | 25 +++++++++++--- .../ddaodan/MineChatGPT/CommandHandler.java | 2 +- .../ddaodan/MineChatGPT/ConfigManager.java | 7 ++-- .../java/com/ddaodan/MineChatGPT/Main.java | 34 ++++++++++++++++++- src/main/resources/config.yml | 5 +-- src/main/resources/config_zh.yml | 7 ++-- 8 files changed, 75 insertions(+), 17 deletions(-) diff --git a/build.gradle b/build.gradle index 53c0337..f1e5236 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group = 'com' -version = '2.0' +version = '2.1' repositories { mavenCentral() @@ -16,17 +16,21 @@ repositories { name = "sonatype" url = "https://oss.sonatype.org/content/groups/public/" } + maven { + url = 'https://repo.codemc.io/repository/maven-public/' + } } dependencies { compileOnly "org.spigotmc:spigot-api:1.13-R0.1-SNAPSHOT" + compileOnly 'org.bstats:bstats-bukkit:3.0.2' implementation 'org.jodd:jodd-http:6.3.0' implementation 'org.json:json:20231013' } shadowJar { archiveFileName = "MineChatGPT-${project.version}.jar" - relocate 'org.apache.http', 'com.ddaodan.shaded.org.apache.http' + relocate 'jodd', 'com.ddaodan.shaded.jodd' relocate 'org.json', 'com.ddaodan.minechatgpt.libs.org.json' } diff --git a/changelog.md b/changelog.md index 09dbfa7..f3cd9d1 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,8 @@ # 更新日志 +## 2.1 +- 接入bStats +- 调整配置文件,添加更新功能,现在更新插件应该不用再备份配置文件了 +- 修改了gradle中错误的依赖 ## 2.0 - 更换为jodd-http库,减少插件大小 - 支持指令补全 diff --git a/readme.md b/readme.md index 93aaf69..2bf6ee0 100644 --- a/readme.md +++ b/readme.md @@ -1,5 +1,6 @@ # MineChatGPT -在Minecraft中与ChatGPT交流 +在Minecraft中与ChatGPT交流 +理论支持全版本,欢迎测试 所有的代码都是ChatGPT写的哦 @@ -32,7 +33,7 @@ # API 相关设置 api: # 你的 OpenAI API key,用于身份验证 - # 获取 API key 的方法:访问 //platform.openai.com/account/api-keys 并创建一个新的 API key + # 获取 API key 的方法:访问 https://platform.openai.com/account/api-keys 并创建一个新的 API key key: "sk-your_openai_api_key" # OpenAI API 的基础 URL,用于构建请求 base_url: "https://api.openai.com/v1" @@ -62,7 +63,6 @@ messages: help_reload: "&e/chatgpt reload - 重新加载配置文件" help_model: "&e/chatgpt model - 切换至其他模型" help_modellist: "&e/chatgpt modellist - 可用的模型列表" - usage: "&c输入: /chatgpt model " model_switch: "&a已切换至模型 %s" chatgpt_error: "&c无法联系ChatGPT。" chatgpt_response: "&bChatGPT: %s" @@ -70,7 +70,19 @@ messages: invalid_model: "&c模型无效。使用 /chatgpt modellist 查看可用模型。" available_models: "&e可用模型列表:" no_permission: "&c你没有权限使用这个指令。需要的权限:%s" +# 不要动!!!!! +version: 2.1 ``` + +## 指令与权限 +|指令|权限|描述| +|-|-|-| +|`/chatgpt`|chatgpt.use|查看插件帮助| +|`/chatgpt `|chatgpt.use|向ChatGPT提问| +|`/chatgpt reload`|chatgpt.reload|重新加载配置文件| +|`/chatgpt model `|chatgpt.model|切换至其他模型| +|`/chatgpt modellist`|chatgpt.modellist|查看可用的模型列表| + ## 兼容的版本 ✔ = 完全支持 ? = 部分支持 @@ -87,6 +99,11 @@ messages: 检查控制台输出的错误内容。 ### `connect timeout` `connect reset` 检查`config.yml`中的`base_url`能否正常访问。如果你无法连接到OpenAI官方的API地址,可以考虑使用其他反代。 - +### 我可以添加其他模型吗? +可以,只要模型支持OpenAI的API,就可以使用。 +## 我没有ChatGPT的账号,可以用吗? +可以,目前有很多代理网站,可以很轻松地使用,而且还支持其他模型,费用通常来说也会比官方便宜。如果你愿意,也可以使用我的代理,目前仅在我的QQ群:226385797中提供。 +### 是否会支持Folia +不会。Folia仍然在开发中,短期内不会支持。 ## 赞助 ![afdian-ddaodan.jpeg](https://i.ddaodan.cn/images/afdian-ddaodan.jpeg) \ No newline at end of file diff --git a/src/main/java/com/ddaodan/MineChatGPT/CommandHandler.java b/src/main/java/com/ddaodan/MineChatGPT/CommandHandler.java index 15d4938..3329b4e 100644 --- a/src/main/java/com/ddaodan/MineChatGPT/CommandHandler.java +++ b/src/main/java/com/ddaodan/MineChatGPT/CommandHandler.java @@ -45,7 +45,7 @@ public class CommandHandler implements CommandExecutor { return true; } if (args.length < 2) { - sender.sendMessage(configManager.getUsageMessage()); + sender.sendMessage(configManager.getHelpModelMessage()); return true; } String model = args[1]; diff --git a/src/main/java/com/ddaodan/MineChatGPT/ConfigManager.java b/src/main/java/com/ddaodan/MineChatGPT/ConfigManager.java index a6b14d2..8dfb229 100644 --- a/src/main/java/com/ddaodan/MineChatGPT/ConfigManager.java +++ b/src/main/java/com/ddaodan/MineChatGPT/ConfigManager.java @@ -21,6 +21,9 @@ public class ConfigManager { private String translateColorCodes(String message) { return ChatColor.translateAlternateColorCodes('&', message); } + public String getConfigVersion() { + return config.getString("version", "1.0"); + } public String getApiKey() { return config.getString("api.key"); } @@ -61,10 +64,6 @@ public class ConfigManager { return translateColorCodes(config.getString("messages.help_modellist")); } - public String getUsageMessage() { - return translateColorCodes(config.getString("messages.usage")); - } - public String getModelSwitchMessage() { return translateColorCodes(config.getString("messages.model_switch")); } diff --git a/src/main/java/com/ddaodan/MineChatGPT/Main.java b/src/main/java/com/ddaodan/MineChatGPT/Main.java index 09e1ffe..42b1af3 100644 --- a/src/main/java/com/ddaodan/MineChatGPT/Main.java +++ b/src/main/java/com/ddaodan/MineChatGPT/Main.java @@ -1,6 +1,8 @@ package com.ddaodan.MineChatGPT; +import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.plugin.java.JavaPlugin; +import org.bstats.bukkit.Metrics; import java.util.Objects; @@ -17,10 +19,40 @@ public final class Main extends JavaPlugin { tabCompleter = new MineChatGPTTabCompleter(configManager); Objects.requireNonNull(getCommand("chatgpt")).setExecutor(commandHandler); Objects.requireNonNull(getCommand("chatgpt")).setTabCompleter(tabCompleter); + // Initialize bStats + int pluginId = 22635; + new Metrics(this, pluginId); } @Override public void onDisable() { saveConfig(); } -} + + private void checkAndUpdateConfig() { + String currentVersion = getConfig().getString("version", "1.0"); + String pluginVersion = getDescription().getVersion(); + + if (!currentVersion.equals(pluginVersion)) { + // 备份旧配置文件 + saveConfig(); + saveResource("config.old.yml", true); + + // 加载默认配置文件 + FileConfiguration defaultConfig = getConfig(); + reloadConfig(); + FileConfiguration newConfig = getConfig(); + + // 合并配置文件 + for (String key : defaultConfig.getKeys(true)) { + if (!newConfig.contains(key)) { + newConfig.set(key, defaultConfig.get(key)); + } + } + + // 更新版本号 + newConfig.set("version", pluginVersion); + saveConfig(); + } + } +} \ No newline at end of file diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 02f3aa0..9aba81b 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -31,11 +31,12 @@ messages: help_reload: "&e/chatgpt reload - Reload the configuration file." help_model: "&e/chatgpt model - Switch to a different model." help_modellist: "&e/chatgpt modellist - List available models." - usage: "&cUsage: /chatgpt model " model_switch: "&aModel switched to %s" chatgpt_error: "&cFailed to contact ChatGPT." chatgpt_response: "&bChatGPT: %s" question: "&bYou: %s" invalid_model: "&cInvalid model. Use /chatgpt modellist to see available models." available_models: "&eAvailable models:" - no_permission: "&cYou do not have permission to use this command. Required permission: %s" \ No newline at end of file + no_permission: "&cYou do not have permission to use this command. Required permission: %s" +# DO NOT EDIT!!!!! +version: 2.1 \ No newline at end of file diff --git a/src/main/resources/config_zh.yml b/src/main/resources/config_zh.yml index b7cbea8..762ad11 100644 --- a/src/main/resources/config_zh.yml +++ b/src/main/resources/config_zh.yml @@ -1,7 +1,7 @@ # API 相关设置 api: # 你的 OpenAI API key,用于身份验证 - # 获取 API key 的方法:访问 //platform.openai.com/account/api-keys 并创建一个新的 API key + # 获取 API key 的方法:访问 https://platform.openai.com/account/api-keys 并创建一个新的 API key key: "sk-your_openai_api_key" # OpenAI API 的基础 URL,用于构建请求 base_url: "https://api.openai.com/v1" @@ -31,11 +31,12 @@ messages: help_reload: "&e/chatgpt reload - 重新加载配置文件" help_model: "&e/chatgpt model - 切换至其他模型" help_modellist: "&e/chatgpt modellist - 可用的模型列表" - usage: "&c输入: /chatgpt model " model_switch: "&a已切换至模型 %s" chatgpt_error: "&c无法联系ChatGPT。" chatgpt_response: "&bChatGPT: %s" question: "&b你: %s" invalid_model: "&c模型无效。使用 /chatgpt modellist 查看可用模型。" available_models: "&e可用模型列表:" - no_permission: "&c你没有权限使用这个指令。需要的权限:%s" \ No newline at end of file + no_permission: "&c你没有权限使用这个指令。需要的权限:%s" +# 不要动!!!!! +version: 2.1 \ No newline at end of file