- 修复插件无法加载
- 修复 #2:模型切换实际并不生效
This commit is contained in:
ddaodan 2024-07-14 10:57:49 +08:00
parent 138b1337ac
commit b8aaaaf6a3
8 changed files with 31 additions and 9 deletions

View File

@ -4,7 +4,7 @@ plugins {
}
group = 'com'
version = '2.1'
version = '2.2'
repositories {
mavenCentral()
@ -23,7 +23,7 @@ repositories {
dependencies {
compileOnly "org.spigotmc:spigot-api:1.13-R0.1-SNAPSHOT"
compileOnly 'org.bstats:bstats-bukkit:3.0.2'
implementation 'org.bstats:bstats-bukkit:3.0.2'
implementation 'org.jodd:jodd-http:6.3.0'
implementation 'org.json:json:20231013'
}
@ -32,6 +32,7 @@ shadowJar {
archiveFileName = "MineChatGPT-${project.version}.jar"
relocate 'jodd', 'com.ddaodan.shaded.jodd'
relocate 'org.json', 'com.ddaodan.minechatgpt.libs.org.json'
relocate 'org.bstats', 'com.ddaodan.minechatgpt.libs.org.bstats'
}
def targetJavaVersion = 8

View File

@ -1,4 +1,7 @@
# 更新日志
## 2.2
- 修复插件无法加载
- 修复 #2:模型切换实际并不生效
## 2.1
- 接入bStats
- 调整配置文件,添加更新功能,现在更新插件应该不用再备份配置文件了

View File

@ -63,6 +63,7 @@ messages:
help_reload: "&e/chatgpt reload - 重新加载配置文件"
help_model: "&e/chatgpt model <model_name> - 切换至其他模型"
help_modellist: "&e/chatgpt modellist - 可用的模型列表"
current_model_info: "&e当前模型%s输入 /chatgpt model <model_name> 来切换模型。"
model_switch: "&a已切换至模型 %s"
chatgpt_error: "&c无法联系ChatGPT。"
chatgpt_response: "&bChatGPT: %s"
@ -88,6 +89,7 @@ version: 2.1
= 部分支持
× = 不支持
只列出经过测试的版本
|服务端|支持情况|
|-|-|
|Mohist 1.20.1|✔|

View File

@ -45,13 +45,15 @@ public class CommandHandler implements CommandExecutor {
return true;
}
if (args.length < 2) {
sender.sendMessage(configManager.getHelpModelMessage());
String currentModel = configManager.getCurrentModel();
sender.sendMessage(configManager.getCurrentModelInfoMessage().replace("%s", currentModel));
return true;
}
String model = args[1];
List<String> models = configManager.getModels();
if (models.contains(model)) {
// Logic to switch model
configManager.setCurrentModel(model);
sender.sendMessage(configManager.getModelSwitchMessage().replace("%s", model));
} else {
sender.sendMessage(configManager.getInvalidModelMessage());
@ -92,6 +94,7 @@ public class CommandHandler implements CommandExecutor {
message.put("content", question);
messages.put(message);
json.put("messages", messages);
json.put("model", configManager.getCurrentModel());
HttpRequest request = HttpRequest.post(configManager.getBaseUrl() + "/chat/completions")
.header("Content-Type", "application/json")

View File

@ -7,6 +7,7 @@ import java.util.List;
public class ConfigManager {
private final Main plugin;
private FileConfiguration config;
private String currentModel;
public ConfigManager(Main plugin) {
this.plugin = plugin;
@ -16,11 +17,20 @@ public class ConfigManager {
public void reloadConfig() {
plugin.reloadConfig();
config = plugin.getConfig();
currentModel = config.getString("default_model");
}
private String translateColorCodes(String message) {
return ChatColor.translateAlternateColorCodes('&', message);
}
public String getCurrentModel() {
return currentModel;
}
public void setCurrentModel(String model) {
currentModel = model;
}
public String getConfigVersion() {
return config.getString("version", "1.0");
}
@ -91,4 +101,8 @@ public class ConfigManager {
public String getNoPermissionMessage() {
return translateColorCodes(config.getString("messages.no_permission"));
}
public String getCurrentModelInfoMessage() {
return translateColorCodes(config.getString("messages.current_model_info"));
}
}

View File

@ -19,6 +19,7 @@ public final class Main extends JavaPlugin {
tabCompleter = new MineChatGPTTabCompleter(configManager);
Objects.requireNonNull(getCommand("chatgpt")).setExecutor(commandHandler);
Objects.requireNonNull(getCommand("chatgpt")).setTabCompleter(tabCompleter);
checkAndUpdateConfig();
// Initialize bStats
int pluginId = 22635;
new Metrics(this, pluginId);
@ -34,10 +35,6 @@ public final class Main extends JavaPlugin {
String pluginVersion = getDescription().getVersion();
if (!currentVersion.equals(pluginVersion)) {
// 备份旧配置文件
saveConfig();
saveResource("config.old.yml", true);
// 加载默认配置文件
FileConfiguration defaultConfig = getConfig();
reloadConfig();

View File

@ -31,6 +31,7 @@ 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."
current_model_info: "&eCurrent model: %s. Use /chatgpt model <model_name> to switch models."
model_switch: "&aModel switched to %s"
chatgpt_error: "&cFailed to contact ChatGPT."
chatgpt_response: "&bChatGPT: %s"
@ -39,4 +40,4 @@ messages:
available_models: "&eAvailable models:"
no_permission: "&cYou do not have permission to use this command. Required permission: %s"
# DO NOT EDIT!!!!!
version: 2.1
version: 2.2

View File

@ -31,6 +31,7 @@ messages:
help_reload: "&e/chatgpt reload - 重新加载配置文件"
help_model: "&e/chatgpt model <model_name> - 切换至其他模型"
help_modellist: "&e/chatgpt modellist - 可用的模型列表"
current_model_info: "&e当前模型%s输入 /chatgpt model <model_name> 来切换模型。"
model_switch: "&a已切换至模型 %s"
chatgpt_error: "&c无法联系ChatGPT。"
chatgpt_response: "&bChatGPT: %s"
@ -39,4 +40,4 @@ messages:
available_models: "&e可用模型列表"
no_permission: "&c你没有权限使用这个指令。需要的权限%s"
# 不要动!!!!!
version: 2.1
version: 2.2