diff --git a/fabric/gradle.properties b/fabric/gradle.properties index d40df81b..4b10e564 100644 --- a/fabric/gradle.properties +++ b/fabric/gradle.properties @@ -12,4 +12,4 @@ minecraft_version=1.20.1 loader_version=0.14.21 fabric_version=0.83.1+1.20.1 onebot_client_version=0.3.6-light -toml_version=0.1.0 \ No newline at end of file +toml_version=0.1.1 \ No newline at end of file diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/command/AddChannelIDCommand.java b/fabric/src/main/java/cn/evole/mods/mcbot/command/AddChannelIDCommand.java index 740e27c0..c54d3a12 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/command/AddChannelIDCommand.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/command/AddChannelIDCommand.java @@ -30,6 +30,7 @@ public static int execute(CommandContext context) throws Com } else { ModConfig.INSTANCE.getCommon().addChannelId(id); } + ModConfig.INSTANCE.save(); return 1; } diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/command/AddGroupIDCommand.java b/fabric/src/main/java/cn/evole/mods/mcbot/command/AddGroupIDCommand.java index cdb87183..9ceea7a9 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/command/AddGroupIDCommand.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/command/AddGroupIDCommand.java @@ -34,7 +34,7 @@ public static int execute(CommandContext context) throws Com //$$ context.getSource().sendSuccess(Component.literal("已成功添加QQ群号:" + id + "!"), true); //#endif } - + ModConfig.INSTANCE.save(); return 1; } diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/command/AuthKeyCommand.java b/fabric/src/main/java/cn/evole/mods/mcbot/command/AuthKeyCommand.java index 4b625d13..82ed79a2 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/command/AuthKeyCommand.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/command/AuthKeyCommand.java @@ -23,7 +23,7 @@ public static int execute(CommandContext context) throws Com //#else //$$ context.getSource().sendSuccess(Component.literal("已设置Mirai框架的VerifyKey为:" + id), true); //#endif - + ModConfig.INSTANCE.save(); return 1; } diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/command/BotIDCommand.java b/fabric/src/main/java/cn/evole/mods/mcbot/command/BotIDCommand.java index 985eae5b..c2428a4e 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/command/BotIDCommand.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/command/BotIDCommand.java @@ -23,7 +23,7 @@ public static int execute(CommandContext context) throws Com //#else //$$ context.getSource().sendSuccess(Component.literal("已设置机器人QQ号为:" + id + "!"), true); //#endif - + ModConfig.INSTANCE.save(); return 1; } diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/command/ConnectCommand.java b/fabric/src/main/java/cn/evole/mods/mcbot/command/ConnectCommand.java index 159fc3d0..0f2b3ca9 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/command/ConnectCommand.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/command/ConnectCommand.java @@ -48,7 +48,7 @@ public static int cqhttpExecute(CommandContext context) thro } ModConfig.INSTANCE.getStatus().setREnable(true); ModConfig.INSTANCE.getCommon().setEnable(true); - + ModConfig.INSTANCE.save(); return 1; } else { @@ -89,7 +89,7 @@ public static int miraiExecute(CommandContext context) throw } ModConfig.INSTANCE.getStatus().setREnable(true); ModConfig.INSTANCE.getCommon().setEnable(true); - + ModConfig.INSTANCE.save(); return 1; } else { @@ -124,7 +124,7 @@ public static int cqhttpCommonExecute(CommandContext context } ModConfig.INSTANCE.getStatus().setREnable(true); ModConfig.INSTANCE.getCommon().setEnable(true); - + ModConfig.INSTANCE.save(); return 1; } @@ -149,8 +149,7 @@ public static int miraiCommonExecute(CommandContext context) } ModConfig.INSTANCE.getStatus().setREnable(true); ModConfig.INSTANCE.getCommon().setEnable(true); - - + ModConfig.INSTANCE.save(); return 1; } diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/command/DebugCommand.java b/fabric/src/main/java/cn/evole/mods/mcbot/command/DebugCommand.java index 6487bede..e08079b4 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/command/DebugCommand.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/command/DebugCommand.java @@ -36,7 +36,7 @@ public static int execute(CommandContext context) throws Com //$$ context.getSource().sendSuccess(Component.literal("已关闭开发者模式"), true); //#endif } - + ModConfig.INSTANCE.save(); return 1; } } diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/command/RemoveChannelIDCommand.java b/fabric/src/main/java/cn/evole/mods/mcbot/command/DelChannelIDCommand.java similarity index 94% rename from fabric/src/main/java/cn/evole/mods/mcbot/command/RemoveChannelIDCommand.java rename to fabric/src/main/java/cn/evole/mods/mcbot/command/DelChannelIDCommand.java index fe071f39..5c45da7c 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/command/RemoveChannelIDCommand.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/command/DelChannelIDCommand.java @@ -10,7 +10,7 @@ //#else //$$ import net.minecraft.network.chat.TextComponent; //#endif -public class RemoveChannelIDCommand { +public class DelChannelIDCommand { public static int execute(CommandContext context) throws CommandSyntaxException { @@ -26,7 +26,7 @@ public static int execute(CommandContext context) throws Com //$$ context.getSource().sendSuccess(Component.literal("子频道号:" + id + "并未出现!"), true); //#endif } - + ModConfig.INSTANCE.save(); return 1; } diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/command/RemoveGroupIDCommand.java b/fabric/src/main/java/cn/evole/mods/mcbot/command/DelGroupIDCommand.java similarity index 94% rename from fabric/src/main/java/cn/evole/mods/mcbot/command/RemoveGroupIDCommand.java rename to fabric/src/main/java/cn/evole/mods/mcbot/command/DelGroupIDCommand.java index b73209b3..44d9d836 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/command/RemoveGroupIDCommand.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/command/DelGroupIDCommand.java @@ -10,7 +10,7 @@ //#else //$$ import net.minecraft.network.chat.TextComponent; //#endif -public class RemoveGroupIDCommand { +public class DelGroupIDCommand { public static int execute(CommandContext context) throws CommandSyntaxException { @@ -26,7 +26,7 @@ public static int execute(CommandContext context) throws Com //$$ context.getSource().sendSuccess(Component.literal("QQ群号:" + id + "并未出现!"), true); //#endif } - + ModConfig.INSTANCE.save(); return 1; } diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/command/DisconnectCommand.java b/fabric/src/main/java/cn/evole/mods/mcbot/command/DisconnectCommand.java index 3221ca38..0b194a25 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/command/DisconnectCommand.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/command/DisconnectCommand.java @@ -36,7 +36,7 @@ public static int execute(CommandContext context) throws Com } ModConfig.INSTANCE.getCommon().setEnable(false); } - + ModConfig.INSTANCE.save(); return 1; } } diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/command/GuildIDCommand.java b/fabric/src/main/java/cn/evole/mods/mcbot/command/GuildIDCommand.java index 70659260..58054277 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/command/GuildIDCommand.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/command/GuildIDCommand.java @@ -24,7 +24,7 @@ public static int execute(CommandContext context) throws Com //#else //$$ context.getSource().sendSuccess(Component.literal("已设置互通的频道号为:" + id), true); //#endif - + ModConfig.INSTANCE.save(); return 1; } diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/command/HelpCommand.java b/fabric/src/main/java/cn/evole/mods/mcbot/command/HelpCommand.java index 18aa6a23..bd294a7a 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/command/HelpCommand.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/command/HelpCommand.java @@ -2,6 +2,7 @@ +import cn.evole.mods.mcbot.init.config.ModConfig; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import lombok.val; @@ -70,7 +71,7 @@ public static int execute(CommandContext context) throws Com //#else //$$ context.getSource().sendSuccess(Component.literal(toSend).append(urlC).append(endC), true); //#endif - + ModConfig.INSTANCE.save(); return 1; } } diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/command/ListCustomCommand.java b/fabric/src/main/java/cn/evole/mods/mcbot/command/ListCustomCommand.java index a59ff880..4b7fcb1d 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/command/ListCustomCommand.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/command/ListCustomCommand.java @@ -1,6 +1,7 @@ package cn.evole.mods.mcbot.command; +import cn.evole.mods.mcbot.init.config.ModConfig; import cn.evole.mods.mcbot.init.handler.CustomCmdHandler; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; @@ -25,7 +26,7 @@ public static int execute(CommandContext context) throws Com //#else //$$ context.getSource().sendSuccess(Component.literal(out.toString()), true); //#endif - + ModConfig.INSTANCE.save(); return 1; } } diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/command/ReConnectCommand.java b/fabric/src/main/java/cn/evole/mods/mcbot/command/ReConnectCommand.java index 2f15911c..4c3fbd88 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/command/ReConnectCommand.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/command/ReConnectCommand.java @@ -33,8 +33,7 @@ public static int execute(CommandContext context) throws Com //$$ context.getSource().sendSuccess(Component.literal("已关闭自动重连"), true); //#endif } - - + ModConfig.INSTANCE.save(); return 1; } } diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/command/ReceiveCommand.java b/fabric/src/main/java/cn/evole/mods/mcbot/command/ReceiveCommand.java index 9cad0b25..f2ead91a 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/command/ReceiveCommand.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/command/ReceiveCommand.java @@ -33,7 +33,7 @@ public static int allExecute(CommandContext context) throws //$$ context.getSource().sendSuccess(Component.literal("全局接收群消息开关已被设置为关闭"), true); //#endif } - + ModConfig.INSTANCE.save(); return 1; } @@ -58,7 +58,7 @@ public static int chatExecute(CommandContext context) throws //$$ context.getSource().sendSuccess(Component.literal("接收群内聊天消息开关已被设置为关闭"), true); //#endif } - + ModConfig.INSTANCE.save(); return 1; } @@ -84,7 +84,7 @@ public static int cmdExecute(CommandContext context) throws //$$ context.getSource().sendSuccess(Component.literal("接收群内命令消息开关已被设置为关闭"), true); //#endif } - + ModConfig.INSTANCE.save(); return 1; } } diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/command/ReloadConfigCmd.java b/fabric/src/main/java/cn/evole/mods/mcbot/command/ReloadConfigCmd.java index 838358b0..0525b36e 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/command/ReloadConfigCmd.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/command/ReloadConfigCmd.java @@ -18,7 +18,7 @@ public class ReloadConfigCmd { public static int execute(CommandContext context) throws CommandSyntaxException { try { - + ModConfig.INSTANCE.reload(); if (ModConfig.INSTANCE == null) { //#if MC >= 12000 context.getSource().sendSuccess(()->Component.literal("重载配置失败"), true); @@ -44,7 +44,6 @@ public static int execute(CommandContext context) throws Com //$$ context.getSource().sendSuccess(Component.literal("重载配置失败"), true); //#endif } - return 1; } } diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/command/SendCommand.java b/fabric/src/main/java/cn/evole/mods/mcbot/command/SendCommand.java index f5f28f1d..d16ece1e 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/command/SendCommand.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/command/SendCommand.java @@ -35,7 +35,7 @@ public static int qqLeaveExecute(CommandContext context) thr //$$ context.getSource().sendSuccess(Component.literal("发送新人加入QQ群的消息开关已被设置为关闭"), true); //#endif } - + ModConfig.INSTANCE.save(); return 1; } @@ -61,7 +61,7 @@ public static int qqWelcomeExecute(CommandContext context) t //$$ context.getSource().sendSuccess(Component.literal("发送新人加入QQ群的消息开关已被设置为关闭"), true); //#endif } - + ModConfig.INSTANCE.save(); return 1; } @@ -85,7 +85,7 @@ public static int allExecute(CommandContext context) throws //$$ context.getSource().sendSuccess(Component.literal("全局发送消息开关已被设置为关闭"), true); //#endif } - + ModConfig.INSTANCE.save(); return 1; } @@ -110,7 +110,7 @@ public static int joinExecute(CommandContext context) throws //$$ context.getSource().sendSuccess(Component.literal("发送玩家加入游戏消息开关已被设置为关闭"), true); //#endif } - + ModConfig.INSTANCE.save(); return 1; } @@ -135,7 +135,7 @@ public static int leaveExecute(CommandContext context) throw //$$ context.getSource().sendSuccess(Component.literal("发送玩家离开游戏消息开关已被设置为关闭"), true); //#endif } - + ModConfig.INSTANCE.save(); return 1; } @@ -160,7 +160,7 @@ public static int deathExecute(CommandContext context) throw //$$ context.getSource().sendSuccess(Component.literal("发送玩家死亡游戏消息开关已被设置为关闭"), true); //#endif } - + ModConfig.INSTANCE.save(); return 1; } @@ -185,7 +185,7 @@ public static int chatExecute(CommandContext context) throws //$$ context.getSource().sendSuccess(Component.literal("发送玩家聊天游戏消息开关已被设置为关闭"), true); //#endif } - + ModConfig.INSTANCE.save(); return 1; } @@ -210,7 +210,7 @@ public static int achievementsExecute(CommandContext context //$$ context.getSource().sendSuccess(Component.literal("发送玩家成就游戏消息开关已被设置为关闭"), true); //#endif } - + ModConfig.INSTANCE.save(); return 1; } diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/command/StatusCommand.java b/fabric/src/main/java/cn/evole/mods/mcbot/command/StatusCommand.java index 2536e2d5..fa94bee6 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/command/StatusCommand.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/command/StatusCommand.java @@ -67,7 +67,7 @@ public static int execute(CommandContext context) throws Com //#else //$$ context.getSource().sendSuccess(Component.literal(toSend), true); //#endif - + ModConfig.INSTANCE.save(); return 1; } } diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/init/config/CommonConfig.java b/fabric/src/main/java/cn/evole/mods/mcbot/init/config/CommonConfig.java index 4bdd999b..1d44c1d5 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/init/config/CommonConfig.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/init/config/CommonConfig.java @@ -21,13 +21,13 @@ public class CommonConfig extends AutoLoadTomlConfig { @TableField(rightComment = "开启q群功能") private boolean groupOn = true; @TableField(rightComment = "支持多个q群") - private Long[] groupIdList = new Long[0];//支持多个q群 + private List groupIdList = new ArrayList(){};//支持多个q群 @TableField(rightComment = "是否开启频道") private boolean guildOn = false;//是否开启频道 @TableField(rightComment = "频道id") private String guildId = "";//频道id @TableField(rightComment = "子频道列表") - private String[] channelIdList = new String[0];//子频道列表 + private List channelIdList = new ArrayList(){};//子频道列表 @TableField(rightComment = "机器人qq") private long botId = 0;//机器人qq @TableField(rightComment = "是否启用") @@ -51,27 +51,19 @@ public CommonConfig(TomlTable source) { } public void addChannelId(String id) { - if (!Arrays.stream(channelIdList).toList().contains(id)) Arrays.stream(channelIdList).toList().add(id); + if (!channelIdList.contains(id)) channelIdList.add(id); } public void removeChannelId(String id) { - Arrays.stream(channelIdList).toList().remove(id); + channelIdList.remove(id); } public void removeGroupId(long id) { - Arrays.stream(groupIdList).toList().remove(id); + groupIdList.remove(id); } public void addGroupId(long id) { - if (!Arrays.stream(groupIdList).toList().contains(id)) Arrays.stream(groupIdList).toList().add(id); + if (!groupIdList.contains(id)) groupIdList.add(id); } - - public List getGroupIdList() { - return Arrays.asList(groupIdList); - } - - public List getChannelIdList() { - return Arrays.asList(channelIdList); - } } diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/init/config/ModConfig.java b/fabric/src/main/java/cn/evole/mods/mcbot/init/config/ModConfig.java index 3606d6ea..17199dea 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/init/config/ModConfig.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/init/config/ModConfig.java @@ -41,4 +41,8 @@ public ModConfig(TomlTable source) { this.load(ModConfig.class); } + public void save(){ + TomlUtil.writeConfig(McBot.CONFIG_FILE,INSTANCE); + } + } diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/init/event/ICmdEvent.java b/fabric/src/main/java/cn/evole/mods/mcbot/init/event/ICmdEvent.java index b2d501df..83076114 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/init/event/ICmdEvent.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/init/event/ICmdEvent.java @@ -43,7 +43,7 @@ public static void register(CommandDispatcher dispatcher){ .executes(AddChannelIDCommand::execute))) .then(Commands.literal("delChannelId") .then(Commands.argument("ChannelId", StringArgumentType.greedyString()) - .executes(RemoveChannelIDCommand::execute))) + .executes(DelChannelIDCommand::execute))) .then(Commands.literal("setGuild") .then(Commands.argument("GuildId", StringArgumentType.greedyString()) .executes(GuildIDCommand::execute))) @@ -54,9 +54,9 @@ public static void register(CommandDispatcher dispatcher){ .then(Commands.literal("addGroup") .then(Commands.argument("GroupId", LongArgumentType.longArg()) .executes(AddGroupIDCommand::execute))) - .then(Commands.literal("removeGroup") + .then(Commands.literal("delGroup") .then(Commands.argument("GroupId", LongArgumentType.longArg()) - .executes(RemoveGroupIDCommand::execute))) + .executes(DelGroupIDCommand::execute))) .then(Commands.literal("setBot") .then(Commands.argument("BotId", LongArgumentType.longArg()) .executes(BotIDCommand::execute)))