Skip to content

Commit

Permalink
feat(config): implement jupiter-config for configuration management
Browse files Browse the repository at this point in the history
- Replace Configurate with Jupiter Config for configuration handling
- Update configuration classes to use new Jupiter Config API
- Modify command execution and configuration saving to use new API
- Remove AutoConfig interface and ConfigHandler/ConfigManager classes
- Update I18n and other util classes to use new configuration approach
- Add new language file for English translations
  • Loading branch information
cnlimiter committed Oct 26, 2024
1 parent 8a823d2 commit 28a1a82
Show file tree
Hide file tree
Showing 47 changed files with 786 additions and 904 deletions.
10 changes: 8 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,19 @@ subprojects {
includeGroup 'org.projectlombok'
}
}
maven {
url "https://www.cursemaven.com"
content {
includeGroup "curse.maven"
}
}
maven { url 'https://maven.nova-committee.cn/releases' }
maven { url 'https://maven.minecraftforge.net/' }
maven { url 'https://maven.parchmentmc.org' }
maven { url "https://maven.shedaniel.me/" }
maven { url "https://maven.terraformersmc.com/releases/" }
maven { url "https://api.modrinth.com/maven"
}
}

dependencies {
Expand All @@ -41,8 +49,6 @@ subprojects {
officialMojangMappings()
parchment("org.parchmentmc.data:parchment-$minecraft_version:$mappings_version@zip")
}
implementation ("org.yaml:snakeyaml:1.28")

}

java {
Expand Down
3 changes: 1 addition & 2 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ dependencies {
modImplementation ("net.fabricmc:fabric-loader:$rootProject.fabric_loader_version")

implementation ("cn.evole.onebot:OneBot-Client:$onebot_client_version"){transitive = false}
implementation ("org.spongepowered:configurate-yaml:$yaml_version")
implementation ("com.github.houbb:csv:0.2.0")
modImplementation ("me.shedaniel.cloth:cloth-config:$cloth_config_version")
modImplementation ("curse.maven:jupiter-1072905:$jupiter_fabric_version")
compileOnly ("org.projectlombok:lombok:$lombok_version")
annotationProcessor ("org.projectlombok:lombok:$lombok_version")
}
4 changes: 1 addition & 3 deletions common/src/main/java/cn/evole/mods/mcbot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import cn.evole.mods.mcbot.api.cmd.McBotCommandSource;
import cn.evole.mods.mcbot.platform.Services;
import cn.evole.mods.mcbot.util.FileUtils;
import cn.evole.mods.mcbot.util.MsgThreadUtils;
import cn.evole.mods.mcbot.util.onebot.CQUtils;
import cn.evole.onebot.client.OneBotClient;
import cn.evole.onebot.sdk.util.GsonUtils;
import com.google.gson.Gson;
Expand All @@ -25,7 +23,7 @@ public class Constants {
public static final ExecutorService cqExecutor = Executors.newSingleThreadExecutor();
public static final ExecutorService commonExecutor = Executors.newFixedThreadPool(4);
public static final Gson GSON = GsonUtils.getNullGson();
public static final Path CONFIG_FOLDER = Services.PLATFORM.getGamePath().resolve("mcbot");
public static final Path CONFIG_FOLDER = FileUtils.checkFolder(Services.PLATFORM.getGamePath().resolve("mcbot"));
public static Path DATA_FOLDER = FileUtils.checkFolder(CONFIG_FOLDER.resolve("data"));

public static boolean isShutdown = false;
Expand Down
19 changes: 9 additions & 10 deletions common/src/main/java/cn/evole/mods/mcbot/McBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,26 @@


import cn.evole.mods.mcbot.api.cmd.McBotCommandSource;
import cn.evole.mods.mcbot.api.config.ConfigManager;
import cn.evole.mods.mcbot.api.event.server.ServerGameEvents;
import cn.evole.mods.mcbot.common.config.*;
import cn.evole.mods.mcbot.plugins.cmd.CmdHandler;
import cn.evole.mods.mcbot.common.config.ModConfig;
import cn.evole.mods.mcbot.common.event.IBotEvent;
import cn.evole.mods.mcbot.common.event.IChatEvent;
import cn.evole.mods.mcbot.common.event.IPlayerEvent;
import cn.evole.mods.mcbot.plugins.cmd.CmdHandler;
import cn.evole.mods.mcbot.plugins.data.DataHandler;
import cn.evole.mods.mcbot.util.locale.I18n;
import cn.evole.onebot.client.OneBotClient;
import com.iafenvoy.jupiter.ServerConfigManager;
import com.iafenvoy.jupiter.malilib.config.ConfigManager;
import net.minecraft.server.MinecraftServer;

import static cn.evole.mods.mcbot.Constants.*;

public class McBot {

public static void init() {
try (final ConfigManager manager = new ConfigManager(CONFIG_FOLDER)) {
manager.initConfigs(
ModConfig.class
);
try {
ConfigManager.getInstance().registerConfigHandler(ModConfig.INSTANCE);
ServerConfigManager.registerServerConfig(ModConfig.INSTANCE, ServerConfigManager.PermissionChecker.IS_OPERATOR);
} catch (Exception e) {
LOGGER.error("配置加载错误...");
}
Expand All @@ -45,7 +44,7 @@ public static void onServerStarting(MinecraftServer server) {

public static void onServerStarted(MinecraftServer server) {
mcBotCommand = new McBotCommandSource(server);
if (ModConfig.get().getCommon().isAutoOpen()) {
if (ModConfig.get().getCommon().getAutoOpen().getBooleanValue()) {
onebot = OneBotClient
.create(ModConfig.get().getBotConfig().build())
.open()
Expand All @@ -62,7 +61,7 @@ public static void onServerStopping(MinecraftServer server) {
}

public static void onServerStopped(MinecraftServer server) {
ConfigManager.getInstance().saveAllConfig();
ModConfig.get().save();
Constants.shutdown();
if (onebot != null) onebot.close();
}
Expand Down
12 changes: 6 additions & 6 deletions common/src/main/java/cn/evole/mods/mcbot/api/bot/BotApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ public static void sendGroupMsg(long group_id, Callable<String> message) {
}

public static void sendAllGroupMsg(String message) {
for (long id : ModConfig.get().getCommon().getGroupIdList()) {
sendGroupMsg(id, message);
for (String id : ModConfig.get().getCommon().getGroupIdList().getStrings()) {
sendGroupMsg(Long.parseLong(id), message);
}
}

public static void sendAllGroupMsg(Callable<String> message) {
for (long id : ModConfig.get().getCommon().getGroupIdList()) {
sendGroupMsg(id, message);
for (String id : ModConfig.get().getCommon().getGroupIdList().getStrings()) {
sendGroupMsg(Long.parseLong(id), message);
}
}

Expand All @@ -45,8 +45,8 @@ public static void sendAllGroupMsg(Callable<String> message) {
* @param player 玩家
*/
public static void sendAllGroupMsg(Callable<String> message, ServerPlayer player) {
for (long id : ModConfig.get().getCommon().getGroupIdList()) {
MsgThreadUtils.INSTANCE.submit(id, message, false, player);
for (String id : ModConfig.get().getCommon().getGroupIdList().getStrings()) {
MsgThreadUtils.INSTANCE.submit(Long.parseLong(id), message, false, player);
}
}

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public static void wsConnect() {
.create(ModConfig.get().getBotConfig().build())
.open()
.registerEvents(new IBotEvent());//重新实例化
ModConfig.get().getStatus().setREnable(true);
ModConfig.get().getCommon().setEnable(true);
ModConfig.get().getStatus().getSEnable().setBooleanValue(true);
ModConfig.get().getCommon().getEnable().setBooleanValue(true);
Constants.connected = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static void add(String group_id, String qq_id, String game_name){

List<String> permissions = new ArrayList<>();
for (String permission : userInfo.getPermissions()){
permissions.add(ModConfig.get().getBotConfig().getTag() + "." + permission);//添加权限tag,区分群组服
permissions.add(ModConfig.get().getBotConfig().getTag().getStringValue() + "." + permission);//添加权限tag,区分群组服
}
userInfo.setPermissions(permissions);
userInfos.add(userInfo);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cn.evole.mods.mcbot.common.command;

import cn.evole.mods.mcbot.api.data.UserInfoApi;
import cn.evole.mods.mcbot.common.config.ModConfig;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.commands.CommandSourceStack;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ public class AddGroupIDCommand {

public static int execute(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
val id = context.getArgument("GroupId", Long.class);
if (ModConfig.get().getCommon().getGroupIdList().contains(id)) {
if (ModConfig.get().getCommon().getGroupIdList().getStrings().contains(String.valueOf(id))) {
context.getSource().sendSuccess(() -> Component.literal("QQ群号:" + id + "已经出现了!"), true);

} else {
ModConfig.get().getCommon().addGroupId(id);
context.getSource().sendSuccess(() -> Component.literal("已成功添加QQ群号:" + id + "!"), true);
}
ModConfig.save();
ModConfig.get().save();
return 1;
}

Expand Down
Loading

0 comments on commit 28a1a82

Please sign in to comment.