mirror of
https://github.com/ddaodan/minechatgpt.git
synced 2025-11-01 04:24:13 +08:00
2.1
- 接入bStats - 调整配置文件,添加更新功能,现在更新插件应该不用再备份配置文件了 - 修改了gradle中错误的依赖
This commit is contained in:
@@ -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];
|
||||
|
||||
@@ -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"));
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,11 +31,12 @@ messages:
|
||||
help_reload: "&e/chatgpt reload - Reload the configuration file."
|
||||
help_model: "&e/chatgpt model <model_name> - Switch to a different model."
|
||||
help_modellist: "&e/chatgpt modellist - List available models."
|
||||
usage: "&cUsage: /chatgpt model <model_name>"
|
||||
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_permission: "&cYou do not have permission to use this command. Required permission: %s"
|
||||
# DO NOT EDIT!!!!!
|
||||
version: 2.1
|
||||
@@ -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 <model_name> - 切换至其他模型"
|
||||
help_modellist: "&e/chatgpt modellist - 可用的模型列表"
|
||||
usage: "&c输入: /chatgpt model <model_name>"
|
||||
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_permission: "&c你没有权限使用这个指令。需要的权限:%s"
|
||||
# 不要动!!!!!
|
||||
version: 2.1
|
||||
Reference in New Issue
Block a user