Skip to content

Commit 138b133

Browse files
committed
2.1
- 接入bStats - 调整配置文件,添加更新功能,现在更新插件应该不用再备份配置文件了 - 修改了gradle中错误的依赖
1 parent 73edeba commit 138b133

File tree

8 files changed

+75
-17
lines changed

8 files changed

+75
-17
lines changed

build.gradle

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
}
55

66
group = 'com'
7-
version = '2.0'
7+
version = '2.1'
88

99
repositories {
1010
mavenCentral()
@@ -16,17 +16,21 @@ repositories {
1616
name = "sonatype"
1717
url = "https://oss.sonatype.org/content/groups/public/"
1818
}
19+
maven {
20+
url = 'https://repo.codemc.io/repository/maven-public/'
21+
}
1922
}
2023

2124
dependencies {
2225
compileOnly "org.spigotmc:spigot-api:1.13-R0.1-SNAPSHOT"
26+
compileOnly 'org.bstats:bstats-bukkit:3.0.2'
2327
implementation 'org.jodd:jodd-http:6.3.0'
2428
implementation 'org.json:json:20231013'
2529
}
2630

2731
shadowJar {
2832
archiveFileName = "MineChatGPT-${project.version}.jar"
29-
relocate 'org.apache.http', 'com.ddaodan.shaded.org.apache.http'
33+
relocate 'jodd', 'com.ddaodan.shaded.jodd'
3034
relocate 'org.json', 'com.ddaodan.minechatgpt.libs.org.json'
3135
}
3236

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# 更新日志
2+
## 2.1
3+
- 接入bStats
4+
- 调整配置文件,添加更新功能,现在更新插件应该不用再备份配置文件了
5+
- 修改了gradle中错误的依赖
26
## 2.0
37
- 更换为jodd-http库,减少插件大小
48
- 支持指令补全

readme.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# MineChatGPT
2-
在Minecraft中与ChatGPT交流
2+
在Minecraft中与ChatGPT交流
3+
理论支持全版本,欢迎测试
34

45
所有的代码都是ChatGPT写的哦
56

@@ -32,7 +33,7 @@
3233
# API 相关设置
3334
api:
3435
# 你的 OpenAI API key,用于身份验证
35-
# 获取 API key 的方法:访问 //platform.openai.com/account/api-keys 并创建一个新的 API key
36+
# 获取 API key 的方法:访问 https://platform.openai.com/account/api-keys 并创建一个新的 API key
3637
key: "sk-your_openai_api_key"
3738
# OpenAI API 的基础 URL,用于构建请求
3839
base_url: "https://api.openai.com/v1"
@@ -62,15 +63,26 @@ messages:
6263
help_reload: "&e/chatgpt reload - 重新加载配置文件"
6364
help_model: "&e/chatgpt model <model_name> - 切换至其他模型"
6465
help_modellist: "&e/chatgpt modellist - 可用的模型列表"
65-
usage: "&c输入: /chatgpt model <model_name>"
6666
model_switch: "&a已切换至模型 %s"
6767
chatgpt_error: "&c无法联系ChatGPT。"
6868
chatgpt_response: "&bChatGPT: %s"
6969
question: "&b你: %s"
7070
invalid_model: "&c模型无效。使用 /chatgpt modellist 查看可用模型。"
7171
available_models: "&e可用模型列表:"
7272
no_permission: "&c你没有权限使用这个指令。需要的权限:%s"
73+
# 不要动!!!!!
74+
version: 2.1
7375
```
76+
77+
## 指令与权限
78+
|指令|权限|描述|
79+
|-|-|-|
80+
|`/chatgpt`|chatgpt.use|查看插件帮助|
81+
|`/chatgpt <text>`|chatgpt.use|向ChatGPT提问|
82+
|`/chatgpt reload`|chatgpt.reload|重新加载配置文件|
83+
|`/chatgpt model <model_name>`|chatgpt.model|切换至其他模型|
84+
|`/chatgpt modellist`|chatgpt.modellist|查看可用的模型列表|
85+
7486
## 兼容的版本
7587
✔ = 完全支持
7688
? = 部分支持
@@ -87,6 +99,11 @@ messages:
8799
检查控制台输出的错误内容。
88100
### `connect timeout` `connect reset`
89101
检查`config.yml`中的`base_url`能否正常访问。如果你无法连接到OpenAI官方的API地址,可以考虑使用其他反代。
90-
102+
### 我可以添加其他模型吗?
103+
可以,只要模型支持OpenAI的API,就可以使用。
104+
## 我没有ChatGPT的账号,可以用吗?
105+
可以,目前有很多代理网站,可以很轻松地使用,而且还支持其他模型,费用通常来说也会比官方便宜。如果你愿意,也可以使用我的代理,目前仅在我的QQ群:226385797中提供。
106+
### 是否会支持Folia
107+
不会。Folia仍然在开发中,短期内不会支持。
91108
## 赞助
92109
![afdian-ddaodan.jpeg](https://i.ddaodan.cn/images/afdian-ddaodan.jpeg)

src/main/java/com/ddaodan/MineChatGPT/CommandHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
4545
return true;
4646
}
4747
if (args.length < 2) {
48-
sender.sendMessage(configManager.getUsageMessage());
48+
sender.sendMessage(configManager.getHelpModelMessage());
4949
return true;
5050
}
5151
String model = args[1];

src/main/java/com/ddaodan/MineChatGPT/ConfigManager.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ public void reloadConfig() {
2121
private String translateColorCodes(String message) {
2222
return ChatColor.translateAlternateColorCodes('&', message);
2323
}
24+
public String getConfigVersion() {
25+
return config.getString("version", "1.0");
26+
}
2427
public String getApiKey() {
2528
return config.getString("api.key");
2629
}
@@ -61,10 +64,6 @@ public String getHelpModelListMessage() {
6164
return translateColorCodes(config.getString("messages.help_modellist"));
6265
}
6366

64-
public String getUsageMessage() {
65-
return translateColorCodes(config.getString("messages.usage"));
66-
}
67-
6867
public String getModelSwitchMessage() {
6968
return translateColorCodes(config.getString("messages.model_switch"));
7069
}

src/main/java/com/ddaodan/MineChatGPT/Main.java

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.ddaodan.MineChatGPT;
22

3+
import org.bukkit.configuration.file.FileConfiguration;
34
import org.bukkit.plugin.java.JavaPlugin;
5+
import org.bstats.bukkit.Metrics;
46

57
import java.util.Objects;
68

@@ -17,10 +19,40 @@ public void onEnable() {
1719
tabCompleter = new MineChatGPTTabCompleter(configManager);
1820
Objects.requireNonNull(getCommand("chatgpt")).setExecutor(commandHandler);
1921
Objects.requireNonNull(getCommand("chatgpt")).setTabCompleter(tabCompleter);
22+
// Initialize bStats
23+
int pluginId = 22635;
24+
new Metrics(this, pluginId);
2025
}
2126

2227
@Override
2328
public void onDisable() {
2429
saveConfig();
2530
}
26-
}
31+
32+
private void checkAndUpdateConfig() {
33+
String currentVersion = getConfig().getString("version", "1.0");
34+
String pluginVersion = getDescription().getVersion();
35+
36+
if (!currentVersion.equals(pluginVersion)) {
37+
// 备份旧配置文件
38+
saveConfig();
39+
saveResource("config.old.yml", true);
40+
41+
// 加载默认配置文件
42+
FileConfiguration defaultConfig = getConfig();
43+
reloadConfig();
44+
FileConfiguration newConfig = getConfig();
45+
46+
// 合并配置文件
47+
for (String key : defaultConfig.getKeys(true)) {
48+
if (!newConfig.contains(key)) {
49+
newConfig.set(key, defaultConfig.get(key));
50+
}
51+
}
52+
53+
// 更新版本号
54+
newConfig.set("version", pluginVersion);
55+
saveConfig();
56+
}
57+
}
58+
}

src/main/resources/config.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ messages:
3131
help_reload: "&e/chatgpt reload - Reload the configuration file."
3232
help_model: "&e/chatgpt model <model_name> - Switch to a different model."
3333
help_modellist: "&e/chatgpt modellist - List available models."
34-
usage: "&cUsage: /chatgpt model <model_name>"
3534
model_switch: "&aModel switched to %s"
3635
chatgpt_error: "&cFailed to contact ChatGPT."
3736
chatgpt_response: "&bChatGPT: %s"
3837
question: "&bYou: %s"
3938
invalid_model: "&cInvalid model. Use /chatgpt modellist to see available models."
4039
available_models: "&eAvailable models:"
41-
no_permission: "&cYou do not have permission to use this command. Required permission: %s"
40+
no_permission: "&cYou do not have permission to use this command. Required permission: %s"
41+
# DO NOT EDIT!!!!!
42+
version: 2.1

src/main/resources/config_zh.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# API 相关设置
22
api:
33
# 你的 OpenAI API key,用于身份验证
4-
# 获取 API key 的方法:访问 //platform.openai.com/account/api-keys 并创建一个新的 API key
4+
# 获取 API key 的方法:访问 https://platform.openai.com/account/api-keys 并创建一个新的 API key
55
key: "sk-your_openai_api_key"
66
# OpenAI API 的基础 URL,用于构建请求
77
base_url: "https://api.openai.com/v1"
@@ -31,11 +31,12 @@ messages:
3131
help_reload: "&e/chatgpt reload - 重新加载配置文件"
3232
help_model: "&e/chatgpt model <model_name> - 切换至其他模型"
3333
help_modellist: "&e/chatgpt modellist - 可用的模型列表"
34-
usage: "&c输入: /chatgpt model <model_name>"
3534
model_switch: "&a已切换至模型 %s"
3635
chatgpt_error: "&c无法联系ChatGPT。"
3736
chatgpt_response: "&bChatGPT: %s"
3837
question: "&b你: %s"
3938
invalid_model: "&c模型无效。使用 /chatgpt modellist 查看可用模型。"
4039
available_models: "&e可用模型列表:"
41-
no_permission: "&c你没有权限使用这个指令。需要的权限:%s"
40+
no_permission: "&c你没有权限使用这个指令。需要的权限:%s"
41+
# 不要动!!!!!
42+
version: 2.1

0 commit comments

Comments
 (0)