From 6a6f3375e8fe020f32832293b5638f72426aaab0 Mon Sep 17 00:00:00 2001 From: cnlimiter Date: Mon, 4 Dec 2023 03:00:35 +0800 Subject: [PATCH] =?UTF-8?q?+=20toml=E9=85=8D=E7=BD=AE=20+=20=E7=9B=91?= =?UTF-8?q?=E6=8E=A7=E9=85=8D=E7=BD=AE=E6=9B=B4=E6=96=B0=20+=20i18?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- forge/common.gradle | 2 +- forge/gradle.properties | 6 +- .../main/java/cn/evole/mods/mcbot/Const.java | 37 ++- .../main/java/cn/evole/mods/mcbot/IMcBot.java | 37 +-- .../cn/evole/mods/mcbot/cmds/BotCmdRun.java | 3 +- .../java/cn/evole/mods/mcbot/cmds/CmdApi.java | 26 +- .../mcbot/command/AddChannelIDCommand.java | 10 +- .../mods/mcbot/command/AddGroupIDCommand.java | 8 +- .../mods/mcbot/command/AuthKeyCommand.java | 8 +- .../mods/mcbot/command/BotIDCommand.java | 6 +- .../mods/mcbot/command/ConnectCommand.java | 53 ++-- .../mods/mcbot/command/DebugCommand.java | 7 +- ...DCommand.java => DelChannelIDCommand.java} | 10 +- ...pIDCommand.java => DelGroupIDCommand.java} | 10 +- .../mods/mcbot/command/DisconnectCommand.java | 5 +- .../mods/mcbot/command/GuildIDCommand.java | 8 +- .../evole/mods/mcbot/command/HelpCommand.java | 4 +- .../mods/mcbot/command/ListCustomCommand.java | 7 +- .../mods/mcbot/command/ReConnectCommand.java | 8 +- .../mods/mcbot/command/ReceiveCommand.java | 21 +- .../mods/mcbot/command/ReloadConfigCmd.java | 8 +- .../evole/mods/mcbot/command/SendCommand.java | 47 +-- .../mods/mcbot/command/StatusCommand.java | 36 ++- .../mods/mcbot/init/config/BotConfig.java | 40 +++ .../mods/mcbot/init/config/CmdConfig.java | 61 ++++ .../mods/mcbot/init/config/CommonConfig.java | 70 +++++ .../mods/mcbot/init/config/ModConfig.java | 292 ++---------------- .../mods/mcbot/init/config/StatusConfig.java | 53 ++++ .../mods/mcbot/init/event/IBotEvent.java | 128 ++++---- .../mods/mcbot/init/event/IChatEvent.java | 65 ++-- .../mods/mcbot/init/event/ICmdEvent.java | 110 +++---- .../mods/mcbot/init/event/IPlayerEvent.java | 146 ++++----- .../mods/mcbot/init/event/ITickEvent.java | 35 +-- .../mcbot/init/handler/CustomCmdHandler.java | 12 +- .../cn/evole/mods/mcbot/util/locale/I18n.java | 35 ++- .../mods/mcbot/util/onebot/BotUtils.java | 2 +- .../evole/mods/mcbot/util/onebot/CQUtils.java | 5 +- 37 files changed, 706 insertions(+), 715 deletions(-) rename forge/src/main/java/cn/evole/mods/mcbot/command/{RemoveChannelIDCommand.java => DelChannelIDCommand.java} (79%) rename forge/src/main/java/cn/evole/mods/mcbot/command/{RemoveGroupIDCommand.java => DelGroupIDCommand.java} (79%) create mode 100644 forge/src/main/java/cn/evole/mods/mcbot/init/config/BotConfig.java create mode 100644 forge/src/main/java/cn/evole/mods/mcbot/init/config/CmdConfig.java create mode 100644 forge/src/main/java/cn/evole/mods/mcbot/init/config/CommonConfig.java create mode 100644 forge/src/main/java/cn/evole/mods/mcbot/init/config/StatusConfig.java diff --git a/forge/common.gradle b/forge/common.gradle index 9e784a9e..821f8a2d 100644 --- a/forge/common.gradle +++ b/forge/common.gradle @@ -23,7 +23,7 @@ dependencies { forge "net.minecraftforge:forge:${project.minecraft_version}-${project.forge_version}" implementation forgeRuntimeLibrary(include("cn.evole.bot:OneBot-Client:${project.onebot_client_version}")) - implementation forgeRuntimeLibrary(include("cn.evole.config:AtomConfig-Yaml:${project.atomconfig_version}")) + implementation forgeRuntimeLibrary(include("cn.evole.config:AtomConfig-Toml:${project.toml_version}")) compileOnly 'org.projectlombok:lombok:1.18.24' annotationProcessor "org.projectlombok:lombok:1.18.24" diff --git a/forge/gradle.properties b/forge/gradle.properties index 4926dcff..2f33405c 100644 --- a/forge/gradle.properties +++ b/forge/gradle.properties @@ -2,13 +2,13 @@ org.gradle.jvmargs=-Xmx8G # Mod Properties -mod_version=2.1.7 +mod_version=2.1.9 maven_group=cn.evole.mods archives_base_name=McBot-forge mod_id=mcbot # Wrapper Properties # check these on https://fabricmc.net/develop minecraft_version=1.20.1 -onebot_client_version=0.3.6-light +onebot_client_version=0.3.7 jankson_version=1.2.1 -atomconfig_version=0.2.0 +toml_version=0.1.1 diff --git a/forge/src/main/java/cn/evole/mods/mcbot/Const.java b/forge/src/main/java/cn/evole/mods/mcbot/Const.java index f24e5ce4..9e0679f8 100644 --- a/forge/src/main/java/cn/evole/mods/mcbot/Const.java +++ b/forge/src/main/java/cn/evole/mods/mcbot/Const.java @@ -1,11 +1,11 @@ package cn.evole.mods.mcbot; -//#if MC >= 11700 +import cn.evole.mods.mcbot.init.config.ModConfig; +import cn.evole.onebot.sdk.util.BotUtils; import net.minecraftforge.fml.ModList; -import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; -import net.minecraftforge.fml.javafmlmod.FMLModContainer; -import net.minecraftforge.fml.loading.FMLLoader; import net.minecraftforge.fml.loading.FMLPaths; +import java.nio.file.Path; +//#if MC >= 11700 import org.slf4j.Logger; import org.slf4j.LoggerFactory; //#else @@ -27,9 +27,38 @@ public class Const { //$$ public static final Logger LOGGER = LogManager.getLogger("McBot"); //#endif public static boolean isShutdown = false; + public static Path configDir = FMLPaths.CONFIGDIR.get(); public static boolean isLoad(String modId){ return ModList.get().isLoaded(modId); } + public static void sendGroupMsg(String message){ + for (long id : ModConfig.INSTANCE.getCommon().getGroupIdList()){ + groupMsg(id, message); + } + } + + public static void groupMsg(long id, String message){ + if (ModConfig.INSTANCE.getBotConfig().getMsgType().equalsIgnoreCase("string")){ + IMcBot.bot.sendGroupMsg(id, message, false); + } + else { + IMcBot.bot.sendGroupMsg(id, BotUtils.rawToJson(message), false); + } + } + + public static void sendGuildMsg(String message){ + for (String id : ModConfig.INSTANCE.getCommon().getChannelIdList()){ + guildMsg(ModConfig.INSTANCE.getCommon().getGuildId(), id, message); + } + } + public static void guildMsg(String guildId, String channelId, String message){ + if (ModConfig.INSTANCE.getBotConfig().getMsgType().equalsIgnoreCase("string")){ + IMcBot.bot.sendGuildMsg(guildId, channelId, message); + } + else { + IMcBot.bot.sendGuildMsg(guildId, channelId, BotUtils.rawToJson(message)); + } + } } diff --git a/forge/src/main/java/cn/evole/mods/mcbot/IMcBot.java b/forge/src/main/java/cn/evole/mods/mcbot/IMcBot.java index 55112689..6bbbf3d9 100644 --- a/forge/src/main/java/cn/evole/mods/mcbot/IMcBot.java +++ b/forge/src/main/java/cn/evole/mods/mcbot/IMcBot.java @@ -1,6 +1,5 @@ package cn.evole.mods.mcbot; -import cn.evole.config.yaml.serialization.ConfigurationSerialization; import cn.evole.mods.mcbot.init.config.ModConfig; import cn.evole.mods.mcbot.init.event.IBotEvent; import cn.evole.mods.mcbot.init.event.IChatEvent; @@ -24,10 +23,8 @@ public class IMcBot { public static MinecraftServer SERVER = null; - - public static CustomCmdHandler CMD ; public static Path CONFIG_FOLDER; - + public static Path CONFIG_FILE; public static LinkedBlockingQueue blockingQueue; public static ConnectFactory service; @@ -35,9 +32,6 @@ public class IMcBot { public static Bot bot; public static Thread app; - public static ModConfig config; - - public MinecraftServer getServer() { return SERVER; } @@ -45,18 +39,11 @@ public MinecraftServer getServer() { public IMcBot(Path configDir) { init(configDir); } - public void init(Path config_dir) { - ConfigurationSerialization.registerClass(ModConfig.Status.class);//注册序列对象 - ConfigurationSerialization.registerClass(ModConfig.Bot.class);//注册序列对象 - ConfigurationSerialization.registerClass(ModConfig.Cmd.class);//注册序列对象 - ConfigurationSerialization.registerClass(ModConfig.Common.class);//注册序列对象 - CONFIG_FOLDER = config_dir.resolve("mcbot"); + public void init(Path config_dir) { + CONFIG_FOLDER = Const.configDir.resolve("mcbot"); FileUtils.checkFolder(CONFIG_FOLDER); - config = new ModConfig(CONFIG_FOLDER.toFile()); - config.load(); - - CMD = new CustomCmdHandler(CONFIG_FOLDER); + CONFIG_FILE = CONFIG_FOLDER.resolve("config.toml"); Runtime.getRuntime().addShutdownHook(new Thread(IMcBot::killOutThreads)); } @@ -66,10 +53,10 @@ public void onServerStarting(MinecraftServer server) { public void onServerStarted(MinecraftServer server) { blockingQueue = new LinkedBlockingQueue<>();//使用队列传输数据 - if (config.getCommon().isAutoOpen()) { + if (ModConfig.INSTANCE.getCommon().isAutoOpen()) { try { app = new Thread(() -> { - service = new ConnectFactory(IMcBot.config.getBotConfig(), blockingQueue);//创建websocket连接 + service = new ConnectFactory(ModConfig.INSTANCE.getBotConfig().toBot(), blockingQueue);//创建websocket连接 bot = service.ws.createBot();//创建机器人实例 }, "BotServer"); app.start(); @@ -78,7 +65,7 @@ public void onServerStarted(MinecraftServer server) { } } bus = new EventBus(blockingQueue);//创建事件分发器 - CMD.load();//自定义命令加载 + CustomCmdHandler.INSTANCE.load();//自定义命令加载 IBotEvent.init(bus);//事件监听s } @@ -96,8 +83,7 @@ public void onServerStopped(MinecraftServer server) { private static void killOutThreads() { try { - config.save();//保存配置 - CMD.clear();//自定义命令持久层清空 + CustomCmdHandler.INSTANCE.clear();//自定义命令持久层清空 } catch (Exception e) { e.printStackTrace(); } @@ -107,19 +93,18 @@ public void onServerTick(MinecraftServer server) { ITickEvent.register(server); } public void onServerChat(Level level, Player player, String msg) { - IChatEvent.register(level, player, msg); + IChatEvent.register(player, msg); } public void onPlayerLogIn(Level level, Player player) { IPlayerEvent.loggedIn(level, player); } - public void onPlayerLogOut(Level level, Player player) { IPlayerEvent.loggedOut(level, player); } public void onPlayerDeath(Level level, DamageSource source, ServerPlayer player) { - IPlayerEvent.death(level, source, player); + IPlayerEvent.death(source, player); } public void onPlayerAdvancement(Level level, Player player, Advancement advancement) { - IPlayerEvent.advancement(level, player, advancement); + IPlayerEvent.advancement(player, advancement); } } diff --git a/forge/src/main/java/cn/evole/mods/mcbot/cmds/BotCmdRun.java b/forge/src/main/java/cn/evole/mods/mcbot/cmds/BotCmdRun.java index 65a56353..96da676f 100644 --- a/forge/src/main/java/cn/evole/mods/mcbot/cmds/BotCmdRun.java +++ b/forge/src/main/java/cn/evole/mods/mcbot/cmds/BotCmdRun.java @@ -8,6 +8,7 @@ import net.minecraft.world.entity.Entity; import net.minecraft.world.phys.Vec2; import net.minecraft.world.phys.Vec3; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; @@ -59,7 +60,7 @@ public void sendSuccess(Supplier supplier, boolean bl) { } //#else //$$ @Override - //$$ public void sendSuccess(Component component, boolean p_81356_) { + //$$ public void sendSuccess(@NotNull Component component, boolean p_81356_) { //$$ super.sendSuccess(component, p_81356_); //$$ this.outPut.add(component.getString()); //$$ } diff --git a/forge/src/main/java/cn/evole/mods/mcbot/cmds/CmdApi.java b/forge/src/main/java/cn/evole/mods/mcbot/cmds/CmdApi.java index 28c6be8d..d7c5d2e4 100644 --- a/forge/src/main/java/cn/evole/mods/mcbot/cmds/CmdApi.java +++ b/forge/src/main/java/cn/evole/mods/mcbot/cmds/CmdApi.java @@ -1,9 +1,9 @@ package cn.evole.mods.mcbot.cmds; +import cn.evole.mods.mcbot.Const; import cn.evole.mods.mcbot.IMcBot; import cn.evole.mods.mcbot.init.handler.CustomCmdHandler; import cn.evole.mods.mcbot.util.onebot.BotUtils; -import cn.evole.onebot.client.core.Bot; import cn.evole.onebot.sdk.event.message.GroupMessageEvent; import cn.evole.onebot.sdk.event.message.GuildMessageEvent; @@ -29,25 +29,25 @@ private static StringBuilder CmdMain(String cmd, boolean isOp) { return result; } - private static void GroupCmd(Bot bot, long groupId, String cmd, boolean isOp) { - bot.sendGroupMsg(groupId, CmdMain(cmd, isOp).toString(), true); + private static void GroupCmd(long groupId, String cmd, boolean isOp) { + Const.groupMsg(groupId, CmdMain(cmd, isOp).toString()); } - private static void GuildCmd(Bot bot, String guildId, String channelId, String cmd, boolean isOp) { - bot.sendGuildMsg(guildId, channelId, CmdMain(cmd, isOp).toString()); + private static void GuildCmd(String guildId, String channelId, String cmd, boolean isOp) { + Const.guildMsg(guildId, channelId, CmdMain(cmd, isOp).toString()); } public static void invokeCommandGroup(GroupMessageEvent event) { String command = event.getMessage().substring(1);//去除前缀 if (BotUtils.groupAdminParse(event)) { - IMcBot.CMD.getCustomCmds().stream() + CustomCmdHandler.INSTANCE.getCustomCmds().stream() .filter(customCmd -> command.contains(customCmd.getCmdAlies())) - .forEach(customCmd -> GroupCmd(IMcBot.bot, event.getGroupId(), BotUtils.varParse(customCmd, command), true));//admin + .forEach(customCmd -> GroupCmd(event.getGroupId(), BotUtils.varParse(customCmd, command), true));//admin } else - IMcBot.CMD.getCustomCmds().stream() + CustomCmdHandler.INSTANCE.getCustomCmds().stream() .filter(customCmd -> customCmd.getRequirePermission() < 1 && command.contains(customCmd.getCmdAlies())) - .forEach(customCmd -> GroupCmd(IMcBot.bot, event.getGroupId(), BotUtils.varParse(customCmd, command), false)); + .forEach(customCmd -> GroupCmd(event.getGroupId(), BotUtils.varParse(customCmd, command), false)); } @@ -55,11 +55,11 @@ public static void invokeCommandGuild(GuildMessageEvent event) { String command = event.getMessage().substring(1);//去除前缀 if (BotUtils.guildAdminParse(event)) { - IMcBot.CMD.getCustomCmds().stream() + CustomCmdHandler.INSTANCE.getCustomCmds().stream() .filter(customCmd -> command.contains(customCmd.getCmdAlies())) - .forEach(customCmd -> GuildCmd(IMcBot.bot, event.getGuildId(), event.getChannelId(), BotUtils.varParse(customCmd, command), true));//admin - } else IMcBot.CMD.getCustomCmds().stream() + .forEach(customCmd -> GuildCmd(event.getGuildId(), event.getChannelId(), BotUtils.varParse(customCmd, command), true));//admin + } else CustomCmdHandler.INSTANCE.getCustomCmds().stream() .filter(customCmd -> customCmd.getRequirePermission() < 1 && command.contains(customCmd.getCmdAlies())) - .forEach(customCmd -> GuildCmd(IMcBot.bot, event.getGuildId(), event.getChannelId(), BotUtils.varParse(customCmd, command), false)); + .forEach(customCmd -> GuildCmd(event.getGuildId(), event.getChannelId(), BotUtils.varParse(customCmd, command), false)); } } \ No newline at end of file diff --git a/forge/src/main/java/cn/evole/mods/mcbot/command/AddChannelIDCommand.java b/forge/src/main/java/cn/evole/mods/mcbot/command/AddChannelIDCommand.java index cb3d69b3..c54d3a12 100644 --- a/forge/src/main/java/cn/evole/mods/mcbot/command/AddChannelIDCommand.java +++ b/forge/src/main/java/cn/evole/mods/mcbot/command/AddChannelIDCommand.java @@ -1,6 +1,6 @@ package cn.evole.mods.mcbot.command; -import cn.evole.mods.mcbot.IMcBot; +import cn.evole.mods.mcbot.init.config.ModConfig; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import lombok.val; @@ -16,8 +16,8 @@ public class AddChannelIDCommand { public static int execute(CommandContext context) throws CommandSyntaxException { val id = context.getArgument("ChannelID", String.class); - IMcBot.config.getCommon().setGuildOn(true); - if (IMcBot.config.getCommon().getChannelIdList().contains(id)) { + ModConfig.INSTANCE.getCommon().setGuildOn(true); + if (ModConfig.INSTANCE.getCommon().getChannelIdList().contains(id)) { //#if MC >= 12000 context.getSource().sendSuccess(()->Component.literal("子频道号:" + id + "已经出现了!"), true); @@ -28,9 +28,9 @@ public static int execute(CommandContext context) throws Com //#endif } else { - IMcBot.config.getCommon().addChannelId(id); + ModConfig.INSTANCE.getCommon().addChannelId(id); } - IMcBot.config.save(); + ModConfig.INSTANCE.save(); return 1; } diff --git a/forge/src/main/java/cn/evole/mods/mcbot/command/AddGroupIDCommand.java b/forge/src/main/java/cn/evole/mods/mcbot/command/AddGroupIDCommand.java index 91abefc1..9ceea7a9 100644 --- a/forge/src/main/java/cn/evole/mods/mcbot/command/AddGroupIDCommand.java +++ b/forge/src/main/java/cn/evole/mods/mcbot/command/AddGroupIDCommand.java @@ -1,6 +1,6 @@ package cn.evole.mods.mcbot.command; -import cn.evole.mods.mcbot.IMcBot; +import cn.evole.mods.mcbot.init.config.ModConfig; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import lombok.val; @@ -16,7 +16,7 @@ public class AddGroupIDCommand { public static int execute(CommandContext context) throws CommandSyntaxException { val id = context.getArgument("GroupId", Long.class); - if (IMcBot.config.getCommon().getGroupIdList().contains(id)) { + if (ModConfig.INSTANCE.getCommon().getGroupIdList().contains(id)) { //#if MC >= 12000 context.getSource().sendSuccess(()->Component.literal("QQ群号:" + id + "已经出现了!"), true); //#elseif MC < 11900 @@ -25,7 +25,7 @@ public static int execute(CommandContext context) throws Com //$$ context.getSource().sendSuccess(Component.literal("QQ群号:" + id + "已经出现了!"), true); //#endif } else { - IMcBot.config.getCommon().addGroupId(id); + ModConfig.INSTANCE.getCommon().addGroupId(id); //#if MC >= 12000 context.getSource().sendSuccess(()->Component.literal("已成功添加QQ群号:" + id + "!"), true); //#elseif MC < 11900 @@ -34,7 +34,7 @@ public static int execute(CommandContext context) throws Com //$$ context.getSource().sendSuccess(Component.literal("已成功添加QQ群号:" + id + "!"), true); //#endif } - IMcBot.config.save(); + ModConfig.INSTANCE.save(); return 1; } diff --git a/forge/src/main/java/cn/evole/mods/mcbot/command/AuthKeyCommand.java b/forge/src/main/java/cn/evole/mods/mcbot/command/AuthKeyCommand.java index 37dff708..82ed79a2 100644 --- a/forge/src/main/java/cn/evole/mods/mcbot/command/AuthKeyCommand.java +++ b/forge/src/main/java/cn/evole/mods/mcbot/command/AuthKeyCommand.java @@ -1,6 +1,6 @@ package cn.evole.mods.mcbot.command; -import cn.evole.mods.mcbot.IMcBot; +import cn.evole.mods.mcbot.init.config.ModConfig; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import lombok.val; @@ -15,15 +15,15 @@ public class AuthKeyCommand { public static int execute(CommandContext context) throws CommandSyntaxException { val id = context.getArgument("AuthKey", String.class); - IMcBot.config.getBotConfig().setToken(id); + ModConfig.INSTANCE.getBotConfig().setToken(id); //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("已设置Mirai框架的AuthKey为:" + id), true); + context.getSource().sendSuccess(()->Component.literal("已设置框架的AuthKey为:" + id), true); //#elseif MC < 11900 //$$ context.getSource().sendSuccess(new TextComponent("已设置Mirai框架的VerifyKey为:" + id), true); //#else //$$ context.getSource().sendSuccess(Component.literal("已设置Mirai框架的VerifyKey为:" + id), true); //#endif - IMcBot.config.save(); + ModConfig.INSTANCE.save(); return 1; } diff --git a/forge/src/main/java/cn/evole/mods/mcbot/command/BotIDCommand.java b/forge/src/main/java/cn/evole/mods/mcbot/command/BotIDCommand.java index 5bbfc387..c2428a4e 100644 --- a/forge/src/main/java/cn/evole/mods/mcbot/command/BotIDCommand.java +++ b/forge/src/main/java/cn/evole/mods/mcbot/command/BotIDCommand.java @@ -1,6 +1,6 @@ package cn.evole.mods.mcbot.command; -import cn.evole.mods.mcbot.IMcBot; +import cn.evole.mods.mcbot.init.config.ModConfig; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.minecraft.commands.CommandSourceStack; @@ -15,7 +15,7 @@ public class BotIDCommand { public static int execute(CommandContext context) throws CommandSyntaxException { long id = context.getArgument("BotId", Long.class); - IMcBot.config.getCommon().setBotId(id); + ModConfig.INSTANCE.getCommon().setBotId(id); //#if MC >= 12000 context.getSource().sendSuccess(()->Component.literal("已设置机器人QQ号为:" + id + "!"), true); //#elseif MC < 11900 @@ -23,7 +23,7 @@ public static int execute(CommandContext context) throws Com //#else //$$ context.getSource().sendSuccess(Component.literal("已设置机器人QQ号为:" + id + "!"), true); //#endif - IMcBot.config.save(); + ModConfig.INSTANCE.save(); return 1; } diff --git a/forge/src/main/java/cn/evole/mods/mcbot/command/ConnectCommand.java b/forge/src/main/java/cn/evole/mods/mcbot/command/ConnectCommand.java index eecb00c0..b89c7c15 100644 --- a/forge/src/main/java/cn/evole/mods/mcbot/command/ConnectCommand.java +++ b/forge/src/main/java/cn/evole/mods/mcbot/command/ConnectCommand.java @@ -3,20 +3,20 @@ import cn.evole.mods.mcbot.Const; import cn.evole.mods.mcbot.IMcBot; +import cn.evole.mods.mcbot.init.config.ModConfig; import cn.evole.onebot.client.connection.ConnectFactory; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import lombok.val; import net.minecraft.ChatFormatting; import net.minecraft.commands.CommandSourceStack; +import java.util.regex.Pattern; //#if MC >= 11900 import net.minecraft.network.chat.Component; //#else //$$ import net.minecraft.network.chat.TextComponent; //#endif -import java.util.regex.Pattern; - public class ConnectCommand { public static int cqhttpExecute(CommandContext context) throws CommandSyntaxException { @@ -26,7 +26,7 @@ public static int cqhttpExecute(CommandContext context) thro val pattern = Pattern.compile("(\\d+\\.\\d+\\.\\d+\\.\\d+):(\\d+)"); val matcher = pattern.matcher(parameter); if (matcher.find()) { - IMcBot.config.getBotConfig().setUrl("ws://" + parameter); + ModConfig.INSTANCE.getBotConfig().setUrl("ws://" + parameter); //#if MC >= 12000 context.getSource().sendSuccess(()->Component.literal("尝试链接框架" + ChatFormatting.LIGHT_PURPLE + "cqhttp"), true); //#elseif MC < 11900 @@ -34,20 +34,20 @@ public static int cqhttpExecute(CommandContext context) thro //#else //$$ context.getSource().sendSuccess(Component.literal("尝试链接框架" + ChatFormatting.LIGHT_PURPLE + "cqhttp"), true); //#endif - IMcBot.config.getBotConfig().setMiraiHttp(false); + ModConfig.INSTANCE.getBotConfig().setMiraiHttp(false); try { IMcBot.app = new Thread(() -> { - IMcBot.service = new ConnectFactory(IMcBot.config.getBotConfig(), IMcBot.blockingQueue);//创建websocket连接 + IMcBot.service = new ConnectFactory(ModConfig.INSTANCE.getBotConfig().toBot(), IMcBot.blockingQueue);//创建websocket连接 IMcBot.bot = IMcBot.service.ws.createBot();//创建机器人实例 }, "BotServer"); IMcBot.app.start(); } catch (Exception e) { Const.LOGGER.error("§c机器人服务端配置不正确"); } - IMcBot.config.getStatus().setREnable(true); - IMcBot.config.getCommon().setEnable(true); - IMcBot.config.save(); + ModConfig.INSTANCE.getStatus().setREnable(true); + ModConfig.INSTANCE.getCommon().setEnable(true); + ModConfig.INSTANCE.save(); return 1; } else { @@ -68,7 +68,7 @@ public static int miraiExecute(CommandContext context) throw val pattern = Pattern.compile("(\\d+\\.\\d+\\.\\d+\\.\\d+):(\\d+)"); val matcher = pattern.matcher(parameter); if (matcher.find()) { - IMcBot.config.getBotConfig().setUrl("ws://" + parameter); + ModConfig.INSTANCE.getBotConfig().setUrl("ws://" + parameter); //#if MC >= 12000 context.getSource().sendSuccess(()->Component.literal("尝试链接框架" + ChatFormatting.LIGHT_PURPLE + "mirai"), true); //#elseif MC < 11900 @@ -76,19 +76,19 @@ public static int miraiExecute(CommandContext context) throw //#else //$$ context.getSource().sendSuccess(Component.literal("尝试链接框架" + ChatFormatting.LIGHT_PURPLE + "mirai"), true); //#endif - IMcBot.config.getBotConfig().setMiraiHttp(true); + ModConfig.INSTANCE.getBotConfig().setMiraiHttp(true); try { IMcBot.app = new Thread(() -> { - IMcBot.service = new ConnectFactory(IMcBot.config.getBotConfig(), IMcBot.blockingQueue);//创建websocket连接 + IMcBot.service = new ConnectFactory(ModConfig.INSTANCE.getBotConfig().toBot(), IMcBot.blockingQueue);//创建websocket连接 IMcBot.bot = IMcBot.service.ws.createBot();//创建机器人实例 }, "BotServer"); IMcBot.app.start(); } catch (Exception e) { Const.LOGGER.error("§c机器人服务端配置不正确"); } - IMcBot.config.getStatus().setREnable(true); - IMcBot.config.getCommon().setEnable(true); - IMcBot.config.save(); + ModConfig.INSTANCE.getStatus().setREnable(true); + ModConfig.INSTANCE.getCommon().setEnable(true); + ModConfig.INSTANCE.save(); return 1; } else { @@ -111,19 +111,19 @@ public static int cqhttpCommonExecute(CommandContext context //#else //$$ context.getSource().sendSuccess(Component.literal("尝试链接框架" + ChatFormatting.LIGHT_PURPLE + "cqhttp"), true); //#endif - IMcBot.config.getBotConfig().setMiraiHttp(false); + ModConfig.INSTANCE.getBotConfig().setMiraiHttp(false); try { IMcBot.app = new Thread(() -> { - IMcBot.service = new ConnectFactory(IMcBot.config.getBotConfig(), IMcBot.blockingQueue);//创建websocket连接 - IMcBot.bot = IMcBot.service.ws.createBot();//创建机器人实例 + IMcBot.service = new ConnectFactory(ModConfig.INSTANCE.getBotConfig().toBot(), IMcBot.blockingQueue);//创建websocket连接 + IMcBot.bot = IMcBot.service.ws.createBot();//创建机器人实例 }, "BotServer"); IMcBot.app.start(); } catch (Exception e) { Const.LOGGER.error("§c机器人服务端配置不正确"); } - IMcBot.config.getStatus().setREnable(true); - IMcBot.config.getCommon().setEnable(true); - IMcBot.config.save(); + ModConfig.INSTANCE.getStatus().setREnable(true); + ModConfig.INSTANCE.getCommon().setEnable(true); + ModConfig.INSTANCE.save(); return 1; } @@ -136,20 +136,19 @@ public static int miraiCommonExecute(CommandContext context) //#else //$$ context.getSource().sendSuccess(Component.literal("尝试链接框架" + ChatFormatting.LIGHT_PURPLE + "mirai"), true); //#endif - IMcBot.config.getBotConfig().setMiraiHttp(true); + ModConfig.INSTANCE.getBotConfig().setMiraiHttp(true); try { IMcBot.app = new Thread(() -> { - IMcBot.service = new ConnectFactory(IMcBot.config.getBotConfig(), IMcBot.blockingQueue);//创建websocket连接 - IMcBot.bot = IMcBot.service.ws.createBot();//创建机器人实例 + IMcBot.service = new ConnectFactory(ModConfig.INSTANCE.getBotConfig().toBot(), IMcBot.blockingQueue);//创建websocket连接 + IMcBot.bot = IMcBot.service.ws.createBot();//创建机器人实例 }, "BotServer"); IMcBot.app.start(); } catch (Exception e) { Const.LOGGER.error("§c机器人服务端配置不正确"); } - IMcBot.config.getStatus().setREnable(true); - IMcBot.config.getCommon().setEnable(true); - - IMcBot.config.save(); + ModConfig.INSTANCE.getStatus().setREnable(true); + ModConfig.INSTANCE.getCommon().setEnable(true); + ModConfig.INSTANCE.save(); return 1; } diff --git a/forge/src/main/java/cn/evole/mods/mcbot/command/DebugCommand.java b/forge/src/main/java/cn/evole/mods/mcbot/command/DebugCommand.java index 6fda78fd..e08079b4 100644 --- a/forge/src/main/java/cn/evole/mods/mcbot/command/DebugCommand.java +++ b/forge/src/main/java/cn/evole/mods/mcbot/command/DebugCommand.java @@ -1,8 +1,9 @@ package cn.evole.mods.mcbot.command; -import cn.evole.mods.mcbot.IMcBot; +import cn.evole.mods.mcbot.init.config.ModConfig; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; +import net.minecraft.ChatFormatting; import net.minecraft.commands.CommandSourceStack; //#if MC >= 11900 import net.minecraft.network.chat.Component; @@ -17,7 +18,7 @@ public class DebugCommand { public static int execute(CommandContext context) throws CommandSyntaxException { boolean isEnabled = context.getArgument("enabled", Boolean.class); - IMcBot.config.getCommon().setDebug(isEnabled); + ModConfig.INSTANCE.getCommon().setDebug(isEnabled); if (isEnabled) { //#if MC >= 12000 context.getSource().sendSuccess(()->Component.literal("已开启开发者模式"), true); @@ -35,7 +36,7 @@ public static int execute(CommandContext context) throws Com //$$ context.getSource().sendSuccess(Component.literal("已关闭开发者模式"), true); //#endif } - IMcBot.config.save(); + ModConfig.INSTANCE.save(); return 1; } } diff --git a/forge/src/main/java/cn/evole/mods/mcbot/command/RemoveChannelIDCommand.java b/forge/src/main/java/cn/evole/mods/mcbot/command/DelChannelIDCommand.java similarity index 79% rename from forge/src/main/java/cn/evole/mods/mcbot/command/RemoveChannelIDCommand.java rename to forge/src/main/java/cn/evole/mods/mcbot/command/DelChannelIDCommand.java index 51797868..5c45da7c 100644 --- a/forge/src/main/java/cn/evole/mods/mcbot/command/RemoveChannelIDCommand.java +++ b/forge/src/main/java/cn/evole/mods/mcbot/command/DelChannelIDCommand.java @@ -1,6 +1,6 @@ package cn.evole.mods.mcbot.command; -import cn.evole.mods.mcbot.IMcBot; +import cn.evole.mods.mcbot.init.config.ModConfig; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import lombok.val; @@ -10,13 +10,13 @@ //#else //$$ import net.minecraft.network.chat.TextComponent; //#endif -public class RemoveChannelIDCommand { +public class DelChannelIDCommand { public static int execute(CommandContext context) throws CommandSyntaxException { val id = context.getArgument("ChannelID", String.class); - if (IMcBot.config.getCommon().getChannelIdList().contains(id)) { - IMcBot.config.getCommon().removeChannelId(id); + if (ModConfig.INSTANCE.getCommon().getChannelIdList().contains(id)) { + ModConfig.INSTANCE.getCommon().removeChannelId(id); } else { //#if MC >= 12000 context.getSource().sendSuccess(()->Component.literal("子频道号:" + id + "并未出现!"), true); @@ -26,7 +26,7 @@ public static int execute(CommandContext context) throws Com //$$ context.getSource().sendSuccess(Component.literal("子频道号:" + id + "并未出现!"), true); //#endif } - IMcBot.config.save(); + ModConfig.INSTANCE.save(); return 1; } diff --git a/forge/src/main/java/cn/evole/mods/mcbot/command/RemoveGroupIDCommand.java b/forge/src/main/java/cn/evole/mods/mcbot/command/DelGroupIDCommand.java similarity index 79% rename from forge/src/main/java/cn/evole/mods/mcbot/command/RemoveGroupIDCommand.java rename to forge/src/main/java/cn/evole/mods/mcbot/command/DelGroupIDCommand.java index 52f8311f..44d9d836 100644 --- a/forge/src/main/java/cn/evole/mods/mcbot/command/RemoveGroupIDCommand.java +++ b/forge/src/main/java/cn/evole/mods/mcbot/command/DelGroupIDCommand.java @@ -1,6 +1,6 @@ package cn.evole.mods.mcbot.command; -import cn.evole.mods.mcbot.IMcBot; +import cn.evole.mods.mcbot.init.config.ModConfig; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import lombok.val; @@ -10,13 +10,13 @@ //#else //$$ import net.minecraft.network.chat.TextComponent; //#endif -public class RemoveGroupIDCommand { +public class DelGroupIDCommand { public static int execute(CommandContext context) throws CommandSyntaxException { val id = context.getArgument("GroupID", Long.class); - if (IMcBot.config.getCommon().getGroupIdList().contains(id)) { - IMcBot.config.getCommon().removeGroupId(id); + if (ModConfig.INSTANCE.getCommon().getGroupIdList().contains(id)) { + ModConfig.INSTANCE.getCommon().removeGroupId(id); } else { //#if MC >= 12000 context.getSource().sendSuccess(()->Component.literal("QQ群号:" + id + "并未出现!"), true); @@ -26,7 +26,7 @@ public static int execute(CommandContext context) throws Com //$$ context.getSource().sendSuccess(Component.literal("QQ群号:" + id + "并未出现!"), true); //#endif } - IMcBot.config.save(); + ModConfig.INSTANCE.save(); return 1; } diff --git a/forge/src/main/java/cn/evole/mods/mcbot/command/DisconnectCommand.java b/forge/src/main/java/cn/evole/mods/mcbot/command/DisconnectCommand.java index 0eb0cc7d..267c95d8 100644 --- a/forge/src/main/java/cn/evole/mods/mcbot/command/DisconnectCommand.java +++ b/forge/src/main/java/cn/evole/mods/mcbot/command/DisconnectCommand.java @@ -2,6 +2,7 @@ import cn.evole.mods.mcbot.IMcBot; +import cn.evole.mods.mcbot.init.config.ModConfig; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.minecraft.commands.CommandSourceStack; @@ -33,9 +34,9 @@ public static int execute(CommandContext context) throws Com //$$ context.getSource().sendSuccess(Component.literal("WebSocket目前未连接"), true); //#endif } - IMcBot.config.getCommon().setEnable(false); + ModConfig.INSTANCE.getCommon().setEnable(false); } - IMcBot.config.save(); + ModConfig.INSTANCE.save(); return 1; } } diff --git a/forge/src/main/java/cn/evole/mods/mcbot/command/GuildIDCommand.java b/forge/src/main/java/cn/evole/mods/mcbot/command/GuildIDCommand.java index 07a2e4c3..58054277 100644 --- a/forge/src/main/java/cn/evole/mods/mcbot/command/GuildIDCommand.java +++ b/forge/src/main/java/cn/evole/mods/mcbot/command/GuildIDCommand.java @@ -1,6 +1,6 @@ package cn.evole.mods.mcbot.command; -import cn.evole.mods.mcbot.IMcBot; +import cn.evole.mods.mcbot.init.config.ModConfig; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import lombok.val; @@ -15,8 +15,8 @@ public class GuildIDCommand { public static int execute(CommandContext context) throws CommandSyntaxException { val id = context.getArgument("GuildID", String.class); - IMcBot.config.getCommon().setGuildOn(true); - IMcBot.config.getCommon().setGuildId(id); + ModConfig.INSTANCE.getCommon().setGuildOn(true); + ModConfig.INSTANCE.getCommon().setGuildId(id); //#if MC >= 12000 context.getSource().sendSuccess(()->Component.literal("已设置互通的频道号为:" + id), true); //#elseif MC < 11900 @@ -24,7 +24,7 @@ public static int execute(CommandContext context) throws Com //#else //$$ context.getSource().sendSuccess(Component.literal("已设置互通的频道号为:" + id), true); //#endif - IMcBot.config.save(); + ModConfig.INSTANCE.save(); return 1; } diff --git a/forge/src/main/java/cn/evole/mods/mcbot/command/HelpCommand.java b/forge/src/main/java/cn/evole/mods/mcbot/command/HelpCommand.java index 18aa6a23..762bf3de 100644 --- a/forge/src/main/java/cn/evole/mods/mcbot/command/HelpCommand.java +++ b/forge/src/main/java/cn/evole/mods/mcbot/command/HelpCommand.java @@ -1,7 +1,7 @@ package cn.evole.mods.mcbot.command; - +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 +70,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/forge/src/main/java/cn/evole/mods/mcbot/command/ListCustomCommand.java b/forge/src/main/java/cn/evole/mods/mcbot/command/ListCustomCommand.java index 14ccc258..4f5d8817 100644 --- a/forge/src/main/java/cn/evole/mods/mcbot/command/ListCustomCommand.java +++ b/forge/src/main/java/cn/evole/mods/mcbot/command/ListCustomCommand.java @@ -1,7 +1,8 @@ package cn.evole.mods.mcbot.command; -import cn.evole.mods.mcbot.IMcBot; + +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; @@ -16,7 +17,7 @@ public class ListCustomCommand { public static int execute(CommandContext context) throws CommandSyntaxException { StringBuilder out = new StringBuilder(); - for (String s : IMcBot.CMD.getCustomCmdMap().keySet()) { + for (String s : CustomCmdHandler.INSTANCE.getCustomCmdMap().keySet()) { out.append(s).append("\n"); } //#if MC >= 12000 @@ -26,7 +27,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/forge/src/main/java/cn/evole/mods/mcbot/command/ReConnectCommand.java b/forge/src/main/java/cn/evole/mods/mcbot/command/ReConnectCommand.java index 02ee3f45..7a7af7c9 100644 --- a/forge/src/main/java/cn/evole/mods/mcbot/command/ReConnectCommand.java +++ b/forge/src/main/java/cn/evole/mods/mcbot/command/ReConnectCommand.java @@ -1,7 +1,6 @@ package cn.evole.mods.mcbot.command; - -import cn.evole.mods.mcbot.IMcBot; +import cn.evole.mods.mcbot.init.config.ModConfig; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.minecraft.commands.CommandSourceStack; @@ -15,7 +14,7 @@ public class ReConnectCommand { public static int execute(CommandContext context) throws CommandSyntaxException { boolean isEnabled = context.getArgument("enabled", Boolean.class); - IMcBot.config.getBotConfig().setReconnect(isEnabled); + ModConfig.INSTANCE.getBotConfig().setReconnect(isEnabled); if (isEnabled) { //#if MC >= 12000 context.getSource().sendSuccess(()->Component.literal("已设置自动重连"), true); @@ -33,8 +32,7 @@ public static int execute(CommandContext context) throws Com //$$ context.getSource().sendSuccess(Component.literal("已关闭自动重连"), true); //#endif } - - IMcBot.config.save(); + ModConfig.INSTANCE.save(); return 1; } } diff --git a/forge/src/main/java/cn/evole/mods/mcbot/command/ReceiveCommand.java b/forge/src/main/java/cn/evole/mods/mcbot/command/ReceiveCommand.java index 48730dc7..9e824621 100644 --- a/forge/src/main/java/cn/evole/mods/mcbot/command/ReceiveCommand.java +++ b/forge/src/main/java/cn/evole/mods/mcbot/command/ReceiveCommand.java @@ -1,12 +1,11 @@ package cn.evole.mods.mcbot.command; -import cn.evole.mods.mcbot.IMcBot; +import cn.evole.mods.mcbot.init.config.ModConfig; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.network.chat.Component; import net.minecraft.commands.CommandSourceStack; //#if MC >= 11900 - +import net.minecraft.network.chat.Component; //#else //$$ import net.minecraft.network.chat.TextComponent; //#endif @@ -15,7 +14,7 @@ public class ReceiveCommand { public static int allExecute(CommandContext context) throws CommandSyntaxException { boolean isEnabled = context.getArgument("enabled", Boolean.class); - IMcBot.config.getStatus().setREnable(isEnabled); + ModConfig.INSTANCE.getStatus().setREnable(isEnabled); if (isEnabled) { //#if MC >= 12000 context.getSource().sendSuccess(()->Component.literal("全局接收群消息开关已被设置为打开"), true); @@ -33,15 +32,15 @@ public static int allExecute(CommandContext context) throws //$$ context.getSource().sendSuccess(Component.literal("全局接收群消息开关已被设置为关闭"), true); //#endif } - IMcBot.config.save(); + ModConfig.INSTANCE.save(); return 1; } public static int chatExecute(CommandContext context) throws CommandSyntaxException { boolean isEnabled = context.getArgument("enabled", Boolean.class); - IMcBot.config.getStatus().setRChatEnable(isEnabled); + ModConfig.INSTANCE.getStatus().setRChatEnable(isEnabled); if (isEnabled) { - IMcBot.config.getStatus().setREnable(true); + ModConfig.INSTANCE.getStatus().setREnable(true); //#if MC >= 12000 context.getSource().sendSuccess(()->Component.literal("接收群内聊天消息开关已被设置为打开"), true); //#elseif MC < 11900 @@ -58,16 +57,16 @@ public static int chatExecute(CommandContext context) throws //$$ context.getSource().sendSuccess(Component.literal("接收群内聊天消息开关已被设置为关闭"), true); //#endif } - IMcBot.config.save(); + ModConfig.INSTANCE.save(); return 1; } public static int cmdExecute(CommandContext context) throws CommandSyntaxException { boolean isEnabled = context.getArgument("enabled", Boolean.class); - IMcBot.config.getStatus().setRCmdEnable(isEnabled); + ModConfig.INSTANCE.getStatus().setRCmdEnable(isEnabled); if (isEnabled) { - IMcBot.config.getStatus().setREnable(true); + ModConfig.INSTANCE.getStatus().setREnable(true); //#if MC >= 12000 context.getSource().sendSuccess(()->Component.literal("接收群内命令消息开关已被设置为打开"), true); //#elseif MC < 11900 @@ -84,7 +83,7 @@ public static int cmdExecute(CommandContext context) throws //$$ context.getSource().sendSuccess(Component.literal("接收群内命令消息开关已被设置为关闭"), true); //#endif } - IMcBot.config.save(); + ModConfig.INSTANCE.save(); return 1; } } diff --git a/forge/src/main/java/cn/evole/mods/mcbot/command/ReloadConfigCmd.java b/forge/src/main/java/cn/evole/mods/mcbot/command/ReloadConfigCmd.java index fcfbe30d..0525b36e 100644 --- a/forge/src/main/java/cn/evole/mods/mcbot/command/ReloadConfigCmd.java +++ b/forge/src/main/java/cn/evole/mods/mcbot/command/ReloadConfigCmd.java @@ -1,14 +1,11 @@ package cn.evole.mods.mcbot.command; -import cn.evole.mods.mcbot.IMcBot; import cn.evole.mods.mcbot.init.config.ModConfig; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.minecraft.commands.CommandSourceStack; //#if MC >= 11900 import net.minecraft.network.chat.Component; - -import static cn.evole.mods.mcbot.IMcBot.CONFIG_FOLDER; //#else //$$ import net.minecraft.network.chat.TextComponent; //#endif @@ -21,9 +18,8 @@ public class ReloadConfigCmd { public static int execute(CommandContext context) throws CommandSyntaxException { try { - IMcBot.config = new ModConfig(CONFIG_FOLDER.toFile()); - IMcBot.config.load(); - if (IMcBot.config == null) { + ModConfig.INSTANCE.reload(); + if (ModConfig.INSTANCE == null) { //#if MC >= 12000 context.getSource().sendSuccess(()->Component.literal("重载配置失败"), true); //#elseif MC < 11900 diff --git a/forge/src/main/java/cn/evole/mods/mcbot/command/SendCommand.java b/forge/src/main/java/cn/evole/mods/mcbot/command/SendCommand.java index 1b3910d3..d16ece1e 100644 --- a/forge/src/main/java/cn/evole/mods/mcbot/command/SendCommand.java +++ b/forge/src/main/java/cn/evole/mods/mcbot/command/SendCommand.java @@ -1,6 +1,6 @@ package cn.evole.mods.mcbot.command; -import cn.evole.mods.mcbot.IMcBot; +import cn.evole.mods.mcbot.init.config.ModConfig; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.minecraft.commands.CommandSourceStack; @@ -13,10 +13,12 @@ public class SendCommand { + public static int qqLeaveExecute(CommandContext context) throws CommandSyntaxException { boolean isEnabled = context.getArgument("enabled", Boolean.class); - IMcBot.config.getStatus().setSQqLeaveEnable(isEnabled); + ModConfig.INSTANCE.getStatus().setSQqLeaveEnable(isEnabled); if (isEnabled) { + ModConfig.INSTANCE.getStatus().setSEnable(true); //#if MC >= 12000 context.getSource().sendSuccess(()->Component.literal("发送离开QQ群的消息开关已被设置为打开"), true); //#elseif MC < 11900 @@ -33,15 +35,16 @@ public static int qqLeaveExecute(CommandContext context) thr //$$ context.getSource().sendSuccess(Component.literal("发送新人加入QQ群的消息开关已被设置为关闭"), true); //#endif } - IMcBot.config.save(); + ModConfig.INSTANCE.save(); return 1; } public static int qqWelcomeExecute(CommandContext context) throws CommandSyntaxException { boolean isEnabled = context.getArgument("enabled", Boolean.class); - IMcBot.config.getStatus().setSQqWelcomeEnable(isEnabled); + ModConfig.INSTANCE.getStatus().setSQqWelcomeEnable(isEnabled); if (isEnabled) { + ModConfig.INSTANCE.getStatus().setSEnable(true); //#if MC >= 12000 context.getSource().sendSuccess(()->Component.literal("发送新人加入QQ群的消息开关已被设置为打开"), true); //#elseif MC < 11900 @@ -58,13 +61,13 @@ public static int qqWelcomeExecute(CommandContext context) t //$$ context.getSource().sendSuccess(Component.literal("发送新人加入QQ群的消息开关已被设置为关闭"), true); //#endif } - IMcBot.config.save(); + ModConfig.INSTANCE.save(); return 1; } public static int allExecute(CommandContext context) throws CommandSyntaxException { boolean isEnabled = context.getArgument("enabled", Boolean.class); - IMcBot.config.getStatus().setSEnable(isEnabled); + ModConfig.INSTANCE.getStatus().setSEnable(isEnabled); if (isEnabled) { //#if MC >= 12000 context.getSource().sendSuccess(()->Component.literal("全局发送消息开关已被设置为打开"), true); @@ -82,15 +85,15 @@ public static int allExecute(CommandContext context) throws //$$ context.getSource().sendSuccess(Component.literal("全局发送消息开关已被设置为关闭"), true); //#endif } - IMcBot.config.save(); + ModConfig.INSTANCE.save(); return 1; } public static int joinExecute(CommandContext context) throws CommandSyntaxException { boolean isEnabled = context.getArgument("enabled", Boolean.class); - IMcBot.config.getStatus().setSJoinEnable(isEnabled); + ModConfig.INSTANCE.getStatus().setSJoinEnable(isEnabled); if (isEnabled) { - IMcBot.config.getStatus().setSEnable(true); + ModConfig.INSTANCE.getStatus().setSEnable(true); //#if MC >= 12000 context.getSource().sendSuccess(()->Component.literal("发送玩家加入游戏消息开关已被设置为打开"), true); //#elseif MC < 11900 @@ -107,15 +110,15 @@ public static int joinExecute(CommandContext context) throws //$$ context.getSource().sendSuccess(Component.literal("发送玩家加入游戏消息开关已被设置为关闭"), true); //#endif } - IMcBot.config.save(); + ModConfig.INSTANCE.save(); return 1; } public static int leaveExecute(CommandContext context) throws CommandSyntaxException { boolean isEnabled = context.getArgument("enabled", Boolean.class); - IMcBot.config.getStatus().setSLeaveEnable(isEnabled); + ModConfig.INSTANCE.getStatus().setSLeaveEnable(isEnabled); if (isEnabled) { - IMcBot.config.getStatus().setSEnable(true); + ModConfig.INSTANCE.getStatus().setSEnable(true); //#if MC >= 12000 context.getSource().sendSuccess(()->Component.literal("发送玩家离开游戏消息开关已被设置为打开"), true); //#elseif MC < 11900 @@ -132,15 +135,15 @@ public static int leaveExecute(CommandContext context) throw //$$ context.getSource().sendSuccess(Component.literal("发送玩家离开游戏消息开关已被设置为关闭"), true); //#endif } - IMcBot.config.save(); + ModConfig.INSTANCE.save(); return 1; } public static int deathExecute(CommandContext context) throws CommandSyntaxException { boolean isEnabled = context.getArgument("enabled", Boolean.class); - IMcBot.config.getStatus().setSDeathEnable(isEnabled); + ModConfig.INSTANCE.getStatus().setSDeathEnable(isEnabled); if (isEnabled) { - IMcBot.config.getStatus().setSEnable(true); + ModConfig.INSTANCE.getStatus().setSEnable(true); //#if MC >= 12000 context.getSource().sendSuccess(()->Component.literal("发送玩家死亡游戏消息开关已被设置为打开"), true); //#elseif MC < 11900 @@ -157,15 +160,15 @@ public static int deathExecute(CommandContext context) throw //$$ context.getSource().sendSuccess(Component.literal("发送玩家死亡游戏消息开关已被设置为关闭"), true); //#endif } - IMcBot.config.save(); + ModConfig.INSTANCE.save(); return 1; } public static int chatExecute(CommandContext context) throws CommandSyntaxException { boolean isEnabled = context.getArgument("enabled", Boolean.class); - IMcBot.config.getStatus().setSChatEnable(isEnabled); + ModConfig.INSTANCE.getStatus().setSChatEnable(isEnabled); if (isEnabled) { - IMcBot.config.getStatus().setSEnable(true); + ModConfig.INSTANCE.getStatus().setSEnable(true); //#if MC >= 12000 context.getSource().sendSuccess(()->Component.literal("发送玩家聊天游戏消息开关已被设置为打开"), true); //#elseif MC < 11900 @@ -182,15 +185,15 @@ public static int chatExecute(CommandContext context) throws //$$ context.getSource().sendSuccess(Component.literal("发送玩家聊天游戏消息开关已被设置为关闭"), true); //#endif } - IMcBot.config.save(); + ModConfig.INSTANCE.save(); return 1; } public static int achievementsExecute(CommandContext context) throws CommandSyntaxException { boolean isEnabled = context.getArgument("enabled", Boolean.class); - IMcBot.config.getStatus().setSAdvanceEnable(isEnabled); + ModConfig.INSTANCE.getStatus().setSAdvanceEnable(isEnabled); if (isEnabled) { - IMcBot.config.getStatus().setSEnable(true); + ModConfig.INSTANCE.getStatus().setSEnable(true); //#if MC >= 12000 context.getSource().sendSuccess(()->Component.literal("发送玩家成就游戏消息开关已被设置为打开"), true); //#elseif MC < 11900 @@ -207,7 +210,7 @@ public static int achievementsExecute(CommandContext context //$$ context.getSource().sendSuccess(Component.literal("发送玩家成就游戏消息开关已被设置为关闭"), true); //#endif } - IMcBot.config.save(); + ModConfig.INSTANCE.save(); return 1; } diff --git a/forge/src/main/java/cn/evole/mods/mcbot/command/StatusCommand.java b/forge/src/main/java/cn/evole/mods/mcbot/command/StatusCommand.java index 2688c84b..884ee95a 100644 --- a/forge/src/main/java/cn/evole/mods/mcbot/command/StatusCommand.java +++ b/forge/src/main/java/cn/evole/mods/mcbot/command/StatusCommand.java @@ -2,6 +2,7 @@ import cn.evole.mods.mcbot.IMcBot; +import cn.evole.mods.mcbot.init.config.ModConfig; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import lombok.val; @@ -14,28 +15,28 @@ public class StatusCommand { public static int execute(CommandContext context) throws CommandSyntaxException { - boolean clientEnabled = IMcBot.config.getCommon().isEnable(); + boolean clientEnabled = ModConfig.INSTANCE.getCommon().isEnable(); - boolean receiveEnabled = IMcBot.config.getStatus().isREnable(); - boolean rChatEnabled = IMcBot.config.getStatus().isRChatEnable(); - boolean rCmdEnabled = IMcBot.config.getStatus().isRCmdEnable(); + boolean receiveEnabled = ModConfig.INSTANCE.getStatus().isREnable(); + boolean rChatEnabled = ModConfig.INSTANCE.getStatus().isRChatEnable(); + boolean rCmdEnabled = ModConfig.INSTANCE.getStatus().isRCmdEnable(); - boolean sendEnabled = IMcBot.config.getStatus().isSEnable(); - boolean sJoinEnabled = IMcBot.config.getStatus().isSJoinEnable(); - boolean sLeaveEnabled = IMcBot.config.getStatus().isSLeaveEnable(); - boolean sDeathEnabled = IMcBot.config.getStatus().isSDeathEnable(); - boolean sAchievementsEnabled = IMcBot.config.getStatus().isSAdvanceEnable(); - boolean sQqWelcomeEnabled = IMcBot.config.getStatus().isSQqWelcomeEnable(); - boolean sQqLeaveEnabled = IMcBot.config.getStatus().isSQqLeaveEnable(); + boolean sendEnabled = ModConfig.INSTANCE.getStatus().isSEnable(); + boolean sJoinEnabled = ModConfig.INSTANCE.getStatus().isSJoinEnable(); + boolean sLeaveEnabled = ModConfig.INSTANCE.getStatus().isSLeaveEnable(); + boolean sDeathEnabled = ModConfig.INSTANCE.getStatus().isSDeathEnable(); + boolean sAchievementsEnabled = ModConfig.INSTANCE.getStatus().isSAdvanceEnable(); + boolean sQqWelcomeEnabled = ModConfig.INSTANCE.getStatus().isSQqWelcomeEnable(); + boolean sQqLeaveEnabled = ModConfig.INSTANCE.getStatus().isSQqLeaveEnable(); - val groupId = IMcBot.config.getCommon().getGroupIdList().toString(); - val guildId = IMcBot.config.getCommon().getGuildId(); - val channelId = IMcBot.config.getCommon().getChannelIdList().toString(); - boolean debuggable = IMcBot.config.getCommon().isDebug(); + val groupId = ModConfig.INSTANCE.getCommon().getGroupIdList().toString(); + val guildId = ModConfig.INSTANCE.getCommon().getGuildId(); + val channelId = ModConfig.INSTANCE.getCommon().getChannelIdList().toString(); + boolean debuggable = ModConfig.INSTANCE.getCommon().isDebug(); boolean connected = IMcBot.service != null; boolean white = IMcBot.SERVER.getPlayerList().isUsingWhitelist(); - String host = IMcBot.config.getBotConfig().getUrl(); - long QQid = IMcBot.config.getCommon().getBotId(); + String host = ModConfig.INSTANCE.getBotConfig().getUrl(); + long QQid = ModConfig.INSTANCE.getCommon().getBotId(); String toSend = "\n姬妻人服务状态:\n" + "姬妻人QQId:" + QQid + " \n" @@ -66,6 +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/forge/src/main/java/cn/evole/mods/mcbot/init/config/BotConfig.java b/forge/src/main/java/cn/evole/mods/mcbot/init/config/BotConfig.java new file mode 100644 index 00000000..7c942531 --- /dev/null +++ b/forge/src/main/java/cn/evole/mods/mcbot/init/config/BotConfig.java @@ -0,0 +1,40 @@ +package cn.evole.mods.mcbot.init.config; + +import cn.evole.config.toml.AutoLoadTomlConfig; +import cn.evole.libs.tomlj.TomlTable; +import lombok.Getter; +import lombok.Setter; + +/** + * Name: McBot-fabric / BotConfig + * Author: cnlimiter + * CreateTime: 2023/11/7 20:28 + * Description: + */ + +@Getter +@Setter +public class BotConfig extends AutoLoadTomlConfig { + + private String url = "ws://127.0.0.1:8080"; + private String token = ""; + private long botId = 0L; + private boolean isAccessToken = false; + private boolean miraiHttp = false; + private boolean reconnect = true; + private int maxReconnectAttempts = 20; + private String msgType = "string"; + + public BotConfig() { + super(null); + } + + public BotConfig(TomlTable source) { + super(source); + this.load(BotConfig.class); + } + + public cn.evole.onebot.client.config.BotConfig toBot(){ + return new cn.evole.onebot.client.config.BotConfig(url, token, botId, isAccessToken, miraiHttp, reconnect, maxReconnectAttempts, msgType); + } +} diff --git a/forge/src/main/java/cn/evole/mods/mcbot/init/config/CmdConfig.java b/forge/src/main/java/cn/evole/mods/mcbot/init/config/CmdConfig.java new file mode 100644 index 00000000..ed5b2f45 --- /dev/null +++ b/forge/src/main/java/cn/evole/mods/mcbot/init/config/CmdConfig.java @@ -0,0 +1,61 @@ +package cn.evole.mods.mcbot.init.config; + +import cn.evole.config.toml.AutoLoadTomlConfig; +import cn.evole.config.toml.annotation.TableField; +import cn.evole.libs.tomlj.TomlTable; +import lombok.Getter; +import lombok.Setter; + +/** + * Name: McBot-fabric / CmdConfig + * Author: cnlimiter + * CreateTime: 2023/11/7 20:19 + * Description: + */ + +@Getter +@Setter +public class CmdConfig extends AutoLoadTomlConfig { + @TableField(rightComment = "自定义q群加入事件消息") + private String welcomeNotice = "欢迎加群~";//自定义q群加入事件消息 + @TableField(rightComment = "自定义q群离开消息") + private String leaveNotice = "离开了我们qwq";//自定义q群离开消息 + @TableField(rightComment = "q群中使用命令的关键符号") + private String cmdStart = "!";//q群中使用命令的关键符号 + + @TableField(rightComment = "是否开启显示到游戏中的前缀") + private boolean gamePrefixOn = true;//是否开启显示到游戏中的前缀 + @TableField(rightComment = "是否开启显示到游戏中的id前缀") + private boolean idGamePrefixOn = true;//是否开启显示到游戏中的id前缀 + @TableField(rightComment = "来自q群显示到游戏中的前缀") + private String qqGamePrefix = "群聊";//来自q群显示到游戏中的前缀 + @TableField(rightComment = "来自频道显示到游戏中的前缀") + private String guildGamePrefix = "频道";//来自频道显示到游戏中的前缀 + @TableField(rightComment = "是否开启显示到游戏中的昵称为群昵称") + private boolean groupNickOn = false;//是否开启显示到游戏中的昵称为群昵称 + + + @TableField(rightComment = "是否开启来自游戏的消息显示到群中的前缀") + private boolean mcPrefixOn = true;//是否开启来自游戏的消息显示到群中的前缀 + @TableField(rightComment = "来自游戏的消息显示到群中的前缀") + private String mcPrefix = "MC";//来自游戏的消息显示到群中的前缀 + + + + @TableField(rightComment = "是否开启游戏中自定义关键词") + private boolean mcChatPrefixOn = false;//是否开启游戏中自定义关键词 + @TableField(rightComment = "是否开启qq中自定义关键词") + private boolean qqChatPrefixOn = false;//是否开启qq中自定义关键词 + @TableField(rightComment = "游戏中自定义的消息头文本") + private String mcChatPrefix = "q";//游戏中自定义的消息头文本 + @TableField(rightComment = "qq中自定义的消息头文本") + private String qqChatPrefix = "m";//qq中自定义的消息头文本 + + public CmdConfig() { + super(null); + } + public CmdConfig(TomlTable source) { + super(source); + this.load(CmdConfig.class); + } +} diff --git a/forge/src/main/java/cn/evole/mods/mcbot/init/config/CommonConfig.java b/forge/src/main/java/cn/evole/mods/mcbot/init/config/CommonConfig.java new file mode 100644 index 00000000..2857a398 --- /dev/null +++ b/forge/src/main/java/cn/evole/mods/mcbot/init/config/CommonConfig.java @@ -0,0 +1,70 @@ +package cn.evole.mods.mcbot.init.config; + +import cn.evole.config.toml.AutoLoadTomlConfig; +import cn.evole.config.toml.annotation.TableField; +import cn.evole.libs.tomlj.TomlTable; +import lombok.Getter; +import lombok.Setter; + +import java.util.ArrayList; +import java.util.List; + +/** + * Name: McBot-fabric / CommonConfig + * Author: cnlimiter + * CreateTime: 2023/11/7 20:24 + * Description: + */ +@Getter +@Setter +public class CommonConfig extends AutoLoadTomlConfig { + + @TableField(rightComment = "开启q群功能") + private boolean groupOn = true; + @TableField(rightComment = "支持多个q群") + private List groupIdList = new ArrayList(){};//支持多个q群 + @TableField(rightComment = "是否开启频道") + private boolean guildOn = false;//是否开启频道 + @TableField(rightComment = "频道id") + private String guildId = "";//频道id + @TableField(rightComment = "子频道列表") + private List channelIdList = new ArrayList(){};//子频道列表 + @TableField(rightComment = "机器人qq") + private long botId = 0;//机器人qq + @TableField(rightComment = "是否启用") + private boolean enable = true;//是否启用 + @TableField(rightComment = "是否开发模式,将显示事件信息操作") + private boolean debug = false;//是否开发模式,将显示事件信息操作 + @TableField(rightComment = "选择语言系统") + private String languageSelect = "zh_cn";//选择语言系统 + @TableField(rightComment = "自动连接") + private boolean autoOpen = true;//自动连接 + @TableField(rightComment = "是否开启聊天栏图片功能") + private boolean imageOn = true;//是否开启聊天栏图片功能 + + public CommonConfig() { + super(null); + } + + public CommonConfig(TomlTable source) { + super(source); + this.load(CommonConfig.class); + } + + public void addChannelId(String id) { + if (!channelIdList.contains(id)) channelIdList.add(id); + } + + public void removeChannelId(String id) { + channelIdList.remove(id); + } + + public void removeGroupId(long id) { + groupIdList.remove(id); + } + + public void addGroupId(long id) { + if (!groupIdList.contains(id)) groupIdList.add(id); + } + +} diff --git a/forge/src/main/java/cn/evole/mods/mcbot/init/config/ModConfig.java b/forge/src/main/java/cn/evole/mods/mcbot/init/config/ModConfig.java index bfd3deff..26efe25e 100644 --- a/forge/src/main/java/cn/evole/mods/mcbot/init/config/ModConfig.java +++ b/forge/src/main/java/cn/evole/mods/mcbot/init/config/ModConfig.java @@ -1,20 +1,13 @@ package cn.evole.mods.mcbot.init.config; -import cn.evole.config.YmlConfig; -import cn.evole.config.api.ConfigComments; -import cn.evole.config.api.ConfigField; -import cn.evole.config.yaml.serialization.ConfigurationSerializable; -import cn.evole.config.yaml.serialization.SerializableAs; -import cn.evole.onebot.client.config.BotConfig; -import lombok.Data; +import cn.evole.config.toml.AutoReloadToml; +import cn.evole.config.toml.TomlUtil; +import cn.evole.config.toml.annotation.Reload; +import cn.evole.config.toml.annotation.TableField; +import cn.evole.libs.tomlj.TomlTable; +import cn.evole.mods.mcbot.IMcBot; import lombok.Getter; -import org.jetbrains.annotations.NotNull; - -import java.io.File; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; +import lombok.Setter; /** * Description: @@ -22,259 +15,34 @@ * Date: 2022/10/2 13:44 * Version: 1.0 */ -@Getter -public class ModConfig extends YmlConfig { - public ModConfig(File folder) { - super(folder.getAbsolutePath() + File.separator + "config.yml"); - } - - @ConfigField("common") - @ConfigComments("通用") - private Common common = new Common(); - @ConfigField("status") - @ConfigComments("状态") - private Status status = new Status(); - @ConfigField("cmd") - @ConfigComments("命令") - private Cmd cmd = new Cmd(); - @ConfigField("bot_config") - @ConfigComments("机器人") - private Bot botConfig = new Bot(); - - @SerializableAs("Bot") - public static class Bot extends BotConfig implements ConfigurationSerializable{ - - @Override - public @NotNull Map serialize() { - Map serialize = new HashMap<>(); - - serialize.put("url", this.getUrl()); - serialize.put("token", this.getToken()); - serialize.put("botId", this.getBotId()); - serialize.put("isAccessToken", this.isAccessToken()); - serialize.put("miraiHttp", this.isMiraiHttp()); - serialize.put("reconnect", this.isReconnect()); - serialize.put("maxReconnectAttempts", this.getMaxReconnectAttempts()); - - return serialize; - } - } - - @Data - @SerializableAs("Status") - public static class Status implements ConfigurationSerializable { - - //接收来自q群的消息开关 - //接收来自q群的消息开关 - //////@SerializedName("RECEIVE_ENABLED") - ////@Comment("全局接收") - private boolean rEnable = true; - //////@SerializedName("R_COMMAND_ENABLED") - ////@Comment("命令接收") - private boolean rCmdEnable = true; - //////@SerializedName("R_CHAT_ENABLE") - ////@Comment("消息接收") - private boolean rChatEnable = true; - - //发往q群消息的开关 - //////@SerializedName("SEND_ENABLED") - ////@Comment("发送消息") - private boolean sEnable = true; - //////@SerializedName("S_QQ_WELCOME_ENABLE") - ////@Comment("发送欢迎玩家入群消息") - private boolean sQqWelcomeEnable = true; - //////@SerializedName("S_QQ_LEAVE_ENABLE") - ////@Comment("发送玩家退群消息") - private boolean sQqLeaveEnable = true; - //////@SerializedName("S_JOIN_ENABLE") - ////@Comment("发送加入服务器消息") - private boolean sJoinEnable = true; - //////@SerializedName("S_LEAVE_ENABLE") - ////@Comment("发送离开服务器消息") - private boolean sLeaveEnable = true; - //////@SerializedName("S_DEATH_ENABLE") - ////@Comment("发送玩家死亡消息") - private boolean sDeathEnable = true; - //////@SerializedName("S_CHAT_ENABLE") - ////@Comment("发送服务器聊天") - private boolean sChatEnable = true; - //////@SerializedName("S_ADVANCE_ENABLE") - ////@Comment("发送成就消息") - private boolean sAdvanceEnable = true; - - @Override - public @NotNull Map serialize() { - Map serialize = new HashMap<>(); - - serialize.put("rEnable", this.rEnable); - serialize.put("rCmdEnable", this.rCmdEnable); - serialize.put("sEnable", this.sEnable); - serialize.put("sQqWelcomeEnable", this.sQqWelcomeEnable); - serialize.put("sQqLeaveEnable", this.sQqLeaveEnable); - serialize.put("sJoinEnable", this.sJoinEnable); - serialize.put("sLeaveEnable", this.sLeaveEnable); - serialize.put("sDeathEnable", this.sDeathEnable); - serialize.put("sChatEnable", this.sChatEnable); - serialize.put("sAdvanceEnable", this.sAdvanceEnable); - - return serialize; - } +@Getter +@Setter +public class ModConfig extends AutoReloadToml { + @Reload(autoReload = true) + public static ModConfig INSTANCE = TomlUtil.readConfig(IMcBot.CONFIG_FILE, ModConfig.class, true); + + @TableField(value = "common", topComment = "通用") + private CommonConfig common = new CommonConfig(); + @TableField(value = "status", topComment = "状态") + private StatusConfig status = new StatusConfig(); + @TableField(value = "cmd", topComment = "命令") + private CmdConfig cmd = new CmdConfig(); + @TableField(value = "bot_config", topComment = "机器人") + private BotConfig botConfig = new BotConfig(); + + + public ModConfig() { + super(null, IMcBot.CONFIG_FILE); } - @Data - @SerializableAs("Cmd") - public static class Cmd implements ConfigurationSerializable { - ////@SerializedName("welcome_notice") - //@Comment("自定义q群加入事件消息") - private String welcomeNotice = "欢迎加群~";//自定义q群加入事件消息 - ////@SerializedName("leave_notice") - //@Comment("自定义q群离开消息") - private String leaveNotice = "离开了我们qwq";//自定义q群离开消息 - ////@SerializedName("command_start") - //@Comment("q群中使用命令的关键符号") - private String cmdStart = "!";//q群中使用命令的关键符号 - - ////@SerializedName("gamePrefixOn") - //@Comment("####################\n" + - //"是否开启显示到游戏中的前缀") - private boolean gamePrefixOn = true;//是否开启显示到游戏中的前缀 - ////@SerializedName("idGamePrefixOn") - //@Comment("是否开启显示到游戏中的id前缀") - private boolean idGamePrefixOn = true;//是否开启显示到游戏中的id前缀 - ////@SerializedName("qqGamePrefix") - //@Comment("来自q群显示到游戏中的前缀") - private String qqGamePrefix = "群聊";//来自q群显示到游戏中的前缀 - ////@SerializedName("guildGamePrefix") - //@Comment("来自频道显示到游戏中的前缀") - private String guildGamePrefix = "频道";//来自频道显示到游戏中的前缀 - ////@SerializedName("groupNickOn") - //@Comment("是否开启显示到游戏中的昵称为群昵称") - private boolean groupNickOn = false;//是否开启显示到游戏中的昵称为群昵称 - - - ////@SerializedName( - // "mcPrefixOn") - //@Comment("####################\n" + - // "是否开启来自游戏的消息显示到群中的前缀") - private boolean mcPrefixOn = true;//是否开启来自游戏的消息显示到群中的前缀 - ////@SerializedName("mcPrefix") - //@Comment("来自游戏的消息显示到群中的前缀") - private String mcPrefix = "MC";//来自游戏的消息显示到群中的前缀 - - - ////@SerializedName( - //"mcChatPrefixOn") - //@Comment("####################\n" + - //"是否开启游戏中自定义关键词") - private boolean mcChatPrefixOn = false;//是否开启游戏中自定义关键词 - ////@SerializedName("qqChatPrefixOn") - //@Comment("是否开启qq中自定义关键词") - private boolean qqChatPrefixOn = false;//是否开启qq中自定义关键词 - ////@SerializedName("mcChatPrefix") - //@Comment("游戏中自定义的消息头文本") - private String mcChatPrefix = "q";//游戏中自定义的消息头文本 - ////@SerializedName("qqChatPrefix") - //@Comment("qq中自定义的消息头文本") - private String qqChatPrefix = "m";//qq中自定义的消息头文本 - - @Override - public @NotNull Map serialize() { - Map serialize = new HashMap<>(); - - serialize.put("welcomeNotice", this.welcomeNotice); - serialize.put("leaveNotice", this.leaveNotice); - serialize.put("cmdStart", this.cmdStart); - - serialize.put("gamePrefixOn", this.gamePrefixOn); - serialize.put("idGamePrefixOn", this.idGamePrefixOn); - serialize.put("qqGamePrefix", this.qqGamePrefix); - serialize.put("guildGamePrefix", this.guildGamePrefix); - serialize.put("groupNickOn", this.groupNickOn); - - serialize.put("mcPrefixOn", this.mcPrefixOn); - serialize.put("mcPrefix", this.mcPrefix); - - serialize.put("mcChatPrefixOn", this.mcChatPrefixOn); - serialize.put("qqChatPrefixOn", this.qqChatPrefixOn); - serialize.put("mcChatPrefix", this.mcChatPrefix); - serialize.put("qqChatPrefix", this.qqChatPrefix); - - return serialize; - } + public ModConfig(TomlTable source) { + super(source, IMcBot.CONFIG_FILE); + this.load(ModConfig.class); } - @Data - @SerializableAs("Common") - public static class Common implements ConfigurationSerializable { - //@SerializedName("group_on") - //@Comment("开启q群功能") - private boolean groupOn = true; - //@SerializedName("group_id_list") - //@Comment("支持多个q群") - private HashSet groupIdList = new HashSet<>();//支持多个q群 - //@SerializedName("guild_on") - //@Comment("是否开启频道") - private boolean guildOn = false;//是否开启频道 - //@SerializedName("guild_id") - //@Comment("频道id") - private String guildId = "";//频道id - //@SerializedName("channel_id_list") - //@Comment("子频道列表") - private HashSet channelIdList = new HashSet<>();//子频道列表 - //@SerializedName("bot_id") - //@Comment("机器人qq") - private long botId = 0;//机器人qq - //@SerializedName("enable") - //@Comment("是否启用") - private boolean enable = true;//是否启用 - //@SerializedName("debuggable") - //@Comment("是否开发模式,将显示事件信息操作") - private boolean debug = false;//是否开发模式,将显示事件信息操作 - //@SerializedName("language_select") - //@Comment("选择语言系统") - private String languageSelect = "zh_cn";//选择语言系统 - //@SerializedName("auto_open") - //@Comment("自动连接") - private boolean autoOpen = true;//自动连接 - //@SerializedName("image_on") - //@Comment("是否开启聊天栏图片功能") - private boolean imageOn = true;//是否开启聊天栏图片功能 - - public void addChannelId(String id) { - this.channelIdList.add(id); - } - - public void removeChannelId(String id) { - this.channelIdList.remove(id); - } - - public void removeGroupId(long id) { - this.groupIdList.remove(id); - } - - public void addGroupId(long id) { - this.groupIdList.add(id); - } - - @Override - public @NotNull Map serialize() { - Map serialize = new HashMap<>(); - - serialize.put("groupOn", this.groupOn); - serialize.put("groupIdList", this.groupIdList); - serialize.put("guildOn", this.guildOn); - serialize.put("guildId", this.guildId); - serialize.put("channelIdList", this.channelIdList); - serialize.put("botId", this.botId); - serialize.put("enable", this.enable); - serialize.put("debuggable", this.debug); - serialize.put("languageSelect", this.languageSelect); - serialize.put("autoOpen", this.autoOpen); - serialize.put("imageOn", this.imageOn); - - return serialize; - } + public void save(){ + TomlUtil.writeConfig(IMcBot.CONFIG_FILE,INSTANCE); } } diff --git a/forge/src/main/java/cn/evole/mods/mcbot/init/config/StatusConfig.java b/forge/src/main/java/cn/evole/mods/mcbot/init/config/StatusConfig.java new file mode 100644 index 00000000..70b6e06c --- /dev/null +++ b/forge/src/main/java/cn/evole/mods/mcbot/init/config/StatusConfig.java @@ -0,0 +1,53 @@ +package cn.evole.mods.mcbot.init.config; + +import cn.evole.config.toml.AutoLoadTomlConfig; +import cn.evole.config.toml.annotation.TableField; +import cn.evole.libs.tomlj.TomlTable; +import lombok.Getter; +import lombok.Setter; + +/** + * Name: McBot-fabric / StatusConfig + * Author: cnlimiter + * CreateTime: 2023/11/7 18:49 + * Description: + */ + +@Getter +@Setter +public class StatusConfig extends AutoLoadTomlConfig { + //接收来自q群的消息开关 + @TableField(rightComment = "全局接收") + private boolean rEnable = true; + @TableField(rightComment = "命令接收") + private boolean rCmdEnable = true; + @TableField(rightComment = "消息接收") + private boolean rChatEnable = true; + + //发往q群消息的开关 + @TableField(rightComment = "发送消息") + private boolean sEnable = true; + @TableField(rightComment = "发送欢迎玩家入群消息") + private boolean sQqWelcomeEnable = true; + @TableField(rightComment = "发送玩家退群消息") + private boolean sQqLeaveEnable = true; + @TableField(rightComment = "发送加入服务器消息") + private boolean sJoinEnable = true; + @TableField(rightComment = "发送离开服务器消息") + private boolean sLeaveEnable = true; + @TableField(rightComment = "发送玩家死亡消息") + private boolean sDeathEnable = true; + @TableField(rightComment = "发送服务器聊天") + private boolean sChatEnable = true; + @TableField(rightComment = "发送成就消息") + private boolean sAdvanceEnable = true; + + public StatusConfig(){ + super(null); + } + + public StatusConfig(TomlTable source) { + super(source); + this.load(StatusConfig.class); + } +} diff --git a/forge/src/main/java/cn/evole/mods/mcbot/init/event/IBotEvent.java b/forge/src/main/java/cn/evole/mods/mcbot/init/event/IBotEvent.java index d1597f68..e0627b62 100644 --- a/forge/src/main/java/cn/evole/mods/mcbot/init/event/IBotEvent.java +++ b/forge/src/main/java/cn/evole/mods/mcbot/init/event/IBotEvent.java @@ -1,7 +1,9 @@ package cn.evole.mods.mcbot.init.event; +import cn.evole.mods.mcbot.Const; import cn.evole.mods.mcbot.IMcBot; import cn.evole.mods.mcbot.cmds.CmdApi; +import cn.evole.mods.mcbot.init.config.ModConfig; import cn.evole.mods.mcbot.util.onebot.CQUtils; import cn.evole.onebot.client.handler.EventBus; import cn.evole.onebot.client.listener.SimpleEventListener; @@ -22,46 +24,43 @@ public class IBotEvent { public static void init(EventBus dispatchers) { - if (IMcBot.config.getCommon().isEnable()) - { - GroupChatHandler(dispatchers); - GroupCmdsHandler(dispatchers); - GroupNoticeHandler(dispatchers); - GuildChatHandler(dispatchers); - GuildCmdsHandler(dispatchers); - LifeCycleHandler(dispatchers); - } - + GroupChatHandler(dispatchers); + GroupCmdsHandler(dispatchers); + GroupNoticeHandler(dispatchers); + GuildChatHandler(dispatchers); + GuildCmdsHandler(dispatchers); + LifeCycleHandler(dispatchers); } private static void GroupChatHandler(EventBus dispatchers) { dispatchers.addListener(new SimpleEventListener() { @Override public void onMessage(GroupMessageEvent event) { - if (IMcBot.config.getCommon().getGroupIdList().contains(event.getGroupId())//判断是否是配置中的群 - && !event.getMessage().startsWith(IMcBot.config.getCmd().getCmdStart())//过滤命令前缀 - && IMcBot.config.getStatus().isREnable()//总接受开关 - && IMcBot.config.getStatus().isRChatEnable()//接受聊天开关 - && event.getUserId() != IMcBot.config.getCommon().getBotId()//过滤机器人 + if (ModConfig.INSTANCE.getCommon().getGroupIdList().contains(event.getGroupId())//判断是否是配置中的群 + && !event.getMessage().startsWith(ModConfig.INSTANCE.getCmd().getCmdStart())//过滤命令前缀 + && ModConfig.INSTANCE.getStatus().isREnable()//总接受开关 + && ModConfig.INSTANCE.getStatus().isRChatEnable()//接受聊天开关 + && event.getUserId() != ModConfig.INSTANCE.getCommon().getBotId()//过滤机器人 ) { String send = CQUtils.replace(event.getMessage());//暂时匹配仅符合字符串聊天内容与图片 - if (IMcBot.config.getCmd().isQqChatPrefixOn()) { + if (ModConfig.INSTANCE.getCmd().isQqChatPrefixOn()) { val split = event.getMessage().split(" "); - if (IMcBot.config.getCmd().getQqChatPrefix().equals(split[0])) //指定前缀发送 + if (ModConfig.INSTANCE.getCmd().getQqChatPrefix().equals(split[0])) //指定前缀发送 send = split[1]; else return; } - String nick = IMcBot.bot.getGroupMemberInfo(event.getGroupId(), event.getUserId(), true).getData().getCard(); - String groupNick = IMcBot.config.getCmd().isGroupNickOn() // 是否使用群昵称 - ? nick == null ? event.getSender().getCard() : nick // 防止api返回为空 + Const.LOGGER.info(send); + var nick = IMcBot.bot.getGroupMemberInfo(event.getGroupId(), event.getUserId(), true); + String groupNick = ModConfig.INSTANCE.getCmd().isGroupNickOn() // 是否使用群昵称 + ? nick == null ? event.getSender().getCard() : nick.getData().getCard() // 防止api返回为空 : event.getSender().getNickname(); - String toSend = IMcBot.config.getCmd().isGamePrefixOn() - ? IMcBot.config.getCmd().isIdGamePrefixOn() - ? String.format("§b[§l%s§r(§5%s§b)]§a<%s>§f %s", IMcBot.config.getCmd().getQqGamePrefix(), event.getGroupId(), groupNick, send) - : String.format("§b[§l%s§b]§a<%s>§f %s", IMcBot.config.getCmd().getQqGamePrefix(), groupNick, send) + String toSend = ModConfig.INSTANCE.getCmd().isGamePrefixOn() + ? ModConfig.INSTANCE.getCmd().isIdGamePrefixOn() + ? String.format("§b[§l%s§r(§5%s§b)]§a<%s>§f %s", ModConfig.INSTANCE.getCmd().getQqGamePrefix(), event.getGroupId(), groupNick, send) + : String.format("§b[§l%s§b]§a<%s>§f %s", ModConfig.INSTANCE.getCmd().getQqGamePrefix(), groupNick, send) : String.format("§a<%s>§f %s", groupNick, send); ITickEvent.getSendQueue().add(toSend); } @@ -73,10 +72,10 @@ private static void GroupCmdsHandler(EventBus dispatchers) { dispatchers.addListener(new SimpleEventListener() { @Override public void onMessage(GroupMessageEvent event) { - if (IMcBot.config.getCommon().getGroupIdList().contains(event.getGroupId()) - && event.getMessage().startsWith(IMcBot.config.getCmd().getCmdStart())//命令前缀 - && IMcBot.config.getStatus().isREnable()//总接受开关 - && IMcBot.config.getStatus().isRCmdEnable()//接受命令开关 + if (ModConfig.INSTANCE.getCommon().getGroupIdList().contains(event.getGroupId()) + && event.getMessage().startsWith(ModConfig.INSTANCE.getCmd().getCmdStart())//命令前缀 + && ModConfig.INSTANCE.getStatus().isREnable()//总接受开关 + && ModConfig.INSTANCE.getStatus().isRCmdEnable()//接受命令开关 ) { CmdApi.invokeCommandGroup(event); } @@ -88,11 +87,11 @@ private static void GroupNoticeHandler(EventBus dispatchers) { dispatchers.addListener(new SimpleEventListener() { @Override public void onMessage(GroupIncreaseNoticeEvent event) { - if (IMcBot.config.getCommon().getGroupIdList().contains(event.getGroupId()) - && IMcBot.config.getStatus().isREnable() - && IMcBot.config.getStatus().isSQqWelcomeEnable()) { - - IMcBot.bot.sendGroupMsg(event.getGroupId(), MsgUtils.builder().at(event.getUserId()).build() + "\n" + IMcBot.config.getCmd().getWelcomeNotice(), false); + if (ModConfig.INSTANCE.getCommon().getGroupIdList().contains(event.getGroupId()) + && ModConfig.INSTANCE.getStatus().isSEnable() + && ModConfig.INSTANCE.getStatus().isSQqWelcomeEnable()) { + var msg = MsgUtils.builder().at(event.getUserId()).build() + "\n" + ModConfig.INSTANCE.getCmd().getWelcomeNotice(); + Const.groupMsg(event.getGroupId(), msg); } } }); @@ -100,10 +99,12 @@ public void onMessage(GroupIncreaseNoticeEvent event) { dispatchers.addListener(new SimpleEventListener() { @Override public void onMessage(GroupDecreaseNoticeEvent event) { - if (IMcBot.config.getCommon().getGroupIdList().contains(event.getGroupId()) - && IMcBot.config.getStatus().isREnable() - && IMcBot.config.getStatus().isSQqLeaveEnable()) { - IMcBot.bot.sendGroupMsg(event.getGroupId(), MsgUtils.builder().text(String.valueOf(event.getUserId())).build() + "\n" +IMcBot.config.getCmd().getLeaveNotice(), false); + if (ModConfig.INSTANCE.getCommon().getGroupIdList().contains(event.getGroupId()) + && ModConfig.INSTANCE.getStatus().isSEnable() + && ModConfig.INSTANCE.getStatus().isSQqLeaveEnable()) { + + var msg = MsgUtils.builder().text(String.valueOf(event.getUserId())).build() + "\n" +ModConfig.INSTANCE.getCmd().getLeaveNotice(); + Const.groupMsg(event.getGroupId(), msg); } } }); @@ -114,31 +115,31 @@ private static void GuildChatHandler(EventBus dispatchers) { dispatchers.addListener(new SimpleEventListener() { @Override public void onMessage(GuildMessageEvent event) { - if (event.getGuildId().equals(IMcBot.config.getCommon().getGuildId()) - && IMcBot.config.getCommon().getChannelIdList().contains(event.getChannelId()) - && !event.getMessage().startsWith(IMcBot.config.getCmd().getCmdStart())//过滤命令前缀 - && IMcBot.config.getStatus().isREnable()//总接受开关 - && IMcBot.config.getStatus().isRChatEnable()//接受聊天开关 - && event.getUserId() != IMcBot.config.getCommon().getBotId() + if (event.getGuildId().equals(ModConfig.INSTANCE.getCommon().getGuildId()) + && ModConfig.INSTANCE.getCommon().getChannelIdList().contains(event.getChannelId()) + && !event.getMessage().startsWith(ModConfig.INSTANCE.getCmd().getCmdStart())//过滤命令前缀 + && ModConfig.INSTANCE.getStatus().isREnable()//总接受开关 + && ModConfig.INSTANCE.getStatus().isRChatEnable()//接受聊天开关 + && event.getUserId() != ModConfig.INSTANCE.getCommon().getBotId() ) { String send = CQUtils.replace(event.getMessage());//暂时匹配仅符合字符串聊天内容与图片 - if (IMcBot.config.getCmd().isQqChatPrefixOn()) { + if (ModConfig.INSTANCE.getCmd().isQqChatPrefixOn()) { val split = event.getMessage().split(" "); - if (IMcBot.config.getCmd().getQqChatPrefix().equals(split[0])) //指定前缀发送 + if (ModConfig.INSTANCE.getCmd().getQqChatPrefix().equals(split[0])) //指定前缀发送 send = split[1]; else return; } - String nick = IMcBot.bot.getGuildMemberProfile(event.getGuildId(), String.valueOf(event.getUserId())).getData().getNickname(); - String guildNick = IMcBot.config.getCmd().isGroupNickOn() - ? nick == null ? event.getSender().getNickname() : nick + var nick = IMcBot.bot.getGuildMemberProfile(event.getGuildId(), String.valueOf(event.getUserId())); + String guildNick = ModConfig.INSTANCE.getCmd().isGroupNickOn() + ? nick == null ? event.getSender().getNickname() : nick.getData().getNickname() : event.getSender().getNickname(); - String toSend = IMcBot.config.getCmd().isGamePrefixOn() - ? IMcBot.config.getCmd().isIdGamePrefixOn() - ? String.format("§b[§l%s§r(§5%s§b)]§a<%s>§f %s", IMcBot.config.getCmd().getGuildGamePrefix(), event.getChannelId(), guildNick, send) - : String.format("§b[§l%s§b]§a<%s>§f %s", IMcBot.config.getCmd().getGuildGamePrefix(), guildNick, send) + String toSend = ModConfig.INSTANCE.getCmd().isGamePrefixOn() + ? ModConfig.INSTANCE.getCmd().isIdGamePrefixOn() + ? String.format("§b[§l%s§r(§5%s§b)]§a<%s>§f %s", ModConfig.INSTANCE.getCmd().getGuildGamePrefix(), event.getChannelId(), guildNick, send) + : String.format("§b[§l%s§b]§a<%s>§f %s", ModConfig.INSTANCE.getCmd().getGuildGamePrefix(), guildNick, send) : String.format("§a<%s>§f %s", guildNick, send); ITickEvent.getSendQueue().add(toSend); @@ -151,10 +152,10 @@ private static void GuildCmdsHandler(EventBus dispatchers) { dispatchers.addListener(new SimpleEventListener() { @Override public void onMessage(GuildMessageEvent event) { - if (IMcBot.config.getCommon().getChannelIdList().contains(event.getChannelId()) - && event.getMessage().startsWith(IMcBot.config.getCmd().getCmdStart())//命令前缀 - && IMcBot.config.getStatus().isREnable()//总接受开关 - && IMcBot.config.getStatus().isRCmdEnable()//接受命令开关 + if (ModConfig.INSTANCE.getCommon().getChannelIdList().contains(event.getChannelId()) + && event.getMessage().startsWith(ModConfig.INSTANCE.getCmd().getCmdStart())//命令前缀 + && ModConfig.INSTANCE.getStatus().isREnable()//总接受开关 + && ModConfig.INSTANCE.getStatus().isRCmdEnable()//接受命令开关 ) { CmdApi.invokeCommandGuild(event); } @@ -168,17 +169,16 @@ private static void LifeCycleHandler(EventBus dispatchers) { @Override public void onMessage(LifecycleMetaEvent event) { if (!event.getSubType().equals("connect")) return; - if (!IMcBot.config.getCommon().getGroupIdList().isEmpty() + if (!ModConfig.INSTANCE.getCommon().getGroupIdList().isEmpty() ) { - for (val id : IMcBot.config.getCommon().getGroupIdList()){ - IMcBot.bot.sendGroupMsg(id, "▌ 群服互联已连接 ┈━═☆", false); - } + var msg = "▌ 群服互联已连接 ┈━═☆"; + Const.sendGroupMsg(msg); + } - if (!IMcBot.config.getCommon().getChannelIdList().isEmpty() + if (!ModConfig.INSTANCE.getCommon().getChannelIdList().isEmpty() ) { - for (val id : IMcBot.config.getCommon().getChannelIdList()){ - IMcBot.bot.sendGuildMsg(IMcBot.config.getCommon().getGuildId() , id, "▌ 群服互联已连接 ┈━═☆"); - } + var msg = "▌ 群服互联已连接 ┈━═☆"; + Const.sendGuildMsg(msg); } } }); diff --git a/forge/src/main/java/cn/evole/mods/mcbot/init/event/IChatEvent.java b/forge/src/main/java/cn/evole/mods/mcbot/init/event/IChatEvent.java index 740eedcb..921697d6 100644 --- a/forge/src/main/java/cn/evole/mods/mcbot/init/event/IChatEvent.java +++ b/forge/src/main/java/cn/evole/mods/mcbot/init/event/IChatEvent.java @@ -1,9 +1,9 @@ package cn.evole.mods.mcbot.init.event; -import cn.evole.mods.mcbot.IMcBot; +import cn.evole.mods.mcbot.Const; +import cn.evole.mods.mcbot.init.config.ModConfig; import lombok.val; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.level.Level; /** * Description: @@ -12,40 +12,39 @@ * Version: 1.0 */ public class IChatEvent { - public static void register(Level level, Player player, String message) { - val split = message.split(" "); - if (IMcBot.config != null - && IMcBot.config.getStatus().isSChatEnable() - && IMcBot.config.getStatus().isSEnable() - && !message.contains("CICode") - && !level.isClientSide - ) { - if (IMcBot.config.getCommon().isGuildOn() && !IMcBot.config.getCommon().getChannelIdList().isEmpty()) { - for (String id : IMcBot.config.getCommon().getChannelIdList()) - IMcBot.bot.sendGuildMsg(IMcBot.config.getCommon().getGuildId(), - id, - String.format(IMcBot.config.getCmd().isMcPrefixOn() - ? "[" + IMcBot.config.getCmd().getMcPrefix() + "]<%s> %s" - : "<%s> %s", - player.getDisplayName().getString(), - IMcBot.config.getCmd().isMcChatPrefixOn() - && IMcBot.config.getCmd().getMcChatPrefix().equals(split[0]) ? split[1] : message)); - } - if (IMcBot.config.getCommon().isGroupOn()&& !IMcBot.config.getCommon().getGroupIdList().isEmpty()){ - for (long id : IMcBot.config.getCommon().getGroupIdList()) - IMcBot.bot.sendGroupMsg( - id, - String.format(IMcBot.config.getCmd().isMcPrefixOn() - ? "[" + IMcBot.config.getCmd().getMcPrefix() + "]<%s> %s" - : "<%s> %s", - player.getDisplayName().getString(), - IMcBot.config.getCmd().isMcChatPrefixOn() - && IMcBot.config.getCmd().getMcChatPrefix().equals(split[0]) ? split[1] : message), - false); - } + public static void register(Player player, String message) { + val split = message.split(" "); + if (ModConfig.INSTANCE != null + && ModConfig.INSTANCE.getStatus().isSChatEnable() + && ModConfig.INSTANCE.getStatus().isSEnable() + && !message.contains("CICode") + && !player.getCommandSenderWorld().isClientSide + ) { + if (ModConfig.INSTANCE.getCommon().isGuildOn() && !ModConfig.INSTANCE.getCommon().getChannelIdList().isEmpty()) { + var msg = String.format(ModConfig.INSTANCE.getCmd().isMcPrefixOn() + ? "[" + ModConfig.INSTANCE.getCmd().getMcPrefix() + "]<%s> %s" + : "<%s> %s", + player.getDisplayName().getString(), + ModConfig.INSTANCE.getCmd().isMcChatPrefixOn() + && ModConfig.INSTANCE.getCmd().getMcChatPrefix().equals(split[0]) ? split[1] : message); + + Const.sendGuildMsg(msg); + + } else { + var msg = String.format(ModConfig.INSTANCE.getCmd().isMcPrefixOn() + ? "[" + ModConfig.INSTANCE.getCmd().getMcPrefix() + "]<%s> %s" + : "<%s> %s", + player.getDisplayName().getString(), + ModConfig.INSTANCE.getCmd().isMcChatPrefixOn() + && ModConfig.INSTANCE.getCmd().getMcChatPrefix().equals(split[0]) ? split[1] : message); + + Const.sendGroupMsg(msg); } + + } + } } diff --git a/forge/src/main/java/cn/evole/mods/mcbot/init/event/ICmdEvent.java b/forge/src/main/java/cn/evole/mods/mcbot/init/event/ICmdEvent.java index d85cd5ce..904972b3 100644 --- a/forge/src/main/java/cn/evole/mods/mcbot/init/event/ICmdEvent.java +++ b/forge/src/main/java/cn/evole/mods/mcbot/init/event/ICmdEvent.java @@ -9,6 +9,7 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder; import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; /** @@ -25,90 +26,91 @@ public static LiteralArgumentBuilder literal(String name) { public static RequiredArgumentBuilder argument(String arg, ArgumentType type) { return RequiredArgumentBuilder.argument(arg, type); } - + public static void register(CommandDispatcher dispatcher){ dispatcher.register( - literal("mcbot") + Commands.literal("mcbot") .requires(source -> source.hasPermission(2)) - .then(literal("connect") - .then(literal("cqhttp") + .then(Commands.literal("connect") + .then(Commands.literal("cqhttp") .executes(ConnectCommand::cqhttpCommonExecute) - .then(argument("parameter", StringArgumentType.greedyString()) + .then(Commands.argument("parameter", StringArgumentType.greedyString()) .executes(ConnectCommand::cqhttpExecute) ) ) - .then(literal("mirai") + .then(Commands.literal("mirai") .executes(ConnectCommand::miraiCommonExecute) - .then(argument("parameter", StringArgumentType.greedyString()) + .then(Commands.argument("parameter", StringArgumentType.greedyString()) .executes(ConnectCommand::miraiExecute) ) ) + ) - .then(literal("customs").executes(ListCustomCommand::execute)) - .then(literal("reload").executes(ReloadConfigCmd::execute)) - .then(literal("disconnect").executes(DisconnectCommand::execute)) - .then(literal("addChannelId") - .then(argument("ChannelId", StringArgumentType.greedyString()) + .then(Commands.literal("customs").executes(ListCustomCommand::execute)) + .then(Commands.literal("reload").executes(ReloadConfigCmd::execute)) + .then(Commands.literal("disconnect").executes(DisconnectCommand::execute)) + .then(Commands.literal("addChannelId") + .then(Commands.argument("ChannelId", StringArgumentType.greedyString()) .executes(AddChannelIDCommand::execute))) - .then(literal("delChannelId") - .then(argument("ChannelId", StringArgumentType.greedyString()) - .executes(RemoveChannelIDCommand::execute))) - .then(literal("setGuild") - .then(argument("GuildId", StringArgumentType.greedyString()) + .then(Commands.literal("delChannelId") + .then(Commands.argument("ChannelId", StringArgumentType.greedyString()) + .executes(DelChannelIDCommand::execute))) + .then(Commands.literal("setGuild") + .then(Commands.argument("GuildId", StringArgumentType.greedyString()) .executes(GuildIDCommand::execute))) - .then(literal("help").executes(HelpCommand::execute)) - .then(literal("debug") - .then(argument("enabled", BoolArgumentType.bool()) + .then(Commands.literal("help").executes(HelpCommand::execute)) + .then(Commands.literal("debug") + .then(Commands.argument("enabled", BoolArgumentType.bool()) .executes(DebugCommand::execute))) - .then(literal("addGroup") - .then(argument("GroupId", LongArgumentType.longArg()) + .then(Commands.literal("addGroup") + .then(Commands.argument("GroupId", LongArgumentType.longArg()) .executes(AddGroupIDCommand::execute))) - .then(literal("delGroup") - .then(argument("GroupId", LongArgumentType.longArg()) - .executes(RemoveGroupIDCommand::execute))) - .then(literal("setBot") - .then(argument("BotId", LongArgumentType.longArg()) + .then(Commands.literal("delGroup") + .then(Commands.argument("GroupId", LongArgumentType.longArg()) + .executes(DelGroupIDCommand::execute))) + .then(Commands.literal("setBot") + .then(Commands.argument("BotId", LongArgumentType.longArg()) .executes(BotIDCommand::execute))) - .then(literal("setAuthKey") - .then(argument("AuthKey", StringArgumentType.string()) + .then(Commands.literal("setAuthKey") + .then(Commands.argument("AuthKey", StringArgumentType.string()) .executes(AuthKeyCommand::execute))) - .then(literal("status").executes(StatusCommand::execute)) + .then(Commands.literal("status").executes(StatusCommand::execute)) - .then(literal("receive") - .then(literal("all") - .then(argument("enabled", BoolArgumentType.bool()) + .then(Commands.literal("receive") + .then(Commands.literal("all") + .then(Commands.argument("enabled", BoolArgumentType.bool()) .executes(ReceiveCommand::allExecute))) - .then(literal("chat") - .then(argument("enabled", BoolArgumentType.bool()) + .then(Commands.literal("chat") + .then(Commands.argument("enabled", BoolArgumentType.bool()) .executes(ReceiveCommand::chatExecute))) - .then(literal("cmd") - .then(argument("enabled", BoolArgumentType.bool()) + .then(Commands.literal("cmd") + .then(Commands.argument("enabled", BoolArgumentType.bool()) .executes(ReceiveCommand::cmdExecute)))) - .then(literal("send") - .then(literal("all") - .then(argument("enabled", BoolArgumentType.bool()) + .then(Commands.literal("send") + .then(Commands.literal("all") + .then(Commands.argument("enabled", BoolArgumentType.bool()) .executes(SendCommand::allExecute))) - .then(literal("join") - .then(argument("enabled", BoolArgumentType.bool()) + .then(Commands.literal("join") + .then(Commands.argument("enabled", BoolArgumentType.bool()) .executes(SendCommand::joinExecute))) - .then(literal("leave") - .then(argument("enabled", BoolArgumentType.bool()) + .then(Commands.literal("leave") + .then(Commands.argument("enabled", BoolArgumentType.bool()) .executes(SendCommand::leaveExecute))) - .then(literal("death") - .then(argument("enabled", BoolArgumentType.bool()) + .then(Commands.literal("death") + .then(Commands.argument("enabled", BoolArgumentType.bool()) .executes(SendCommand::deathExecute))) - .then(literal("chat") - .then(argument("enabled", BoolArgumentType.bool()) + .then(Commands.literal("chat") + .then(Commands.argument("enabled", BoolArgumentType.bool()) .executes(SendCommand::chatExecute))) - .then(literal("achievements") - .then(argument("enabled", BoolArgumentType.bool()) + .then(Commands.literal("achievements") + .then(Commands.argument("enabled", BoolArgumentType.bool()) .executes(SendCommand::achievementsExecute))) - .then(literal("qqWelcome") - .then(argument("enabled", BoolArgumentType.bool()) + .then(Commands.literal("qqWelcome") + .then(Commands.argument("enabled", BoolArgumentType.bool()) .executes(SendCommand::qqWelcomeExecute))) - .then(literal("qqLeave") - .then(argument("enabled", BoolArgumentType.bool()) + .then(Commands.literal("qqLeave") + .then(Commands.argument("enabled", BoolArgumentType.bool()) .executes(SendCommand::qqLeaveExecute))) ) ); diff --git a/forge/src/main/java/cn/evole/mods/mcbot/init/event/IPlayerEvent.java b/forge/src/main/java/cn/evole/mods/mcbot/init/event/IPlayerEvent.java index d7e1de2d..14abc56f 100644 --- a/forge/src/main/java/cn/evole/mods/mcbot/init/event/IPlayerEvent.java +++ b/forge/src/main/java/cn/evole/mods/mcbot/init/event/IPlayerEvent.java @@ -1,7 +1,10 @@ package cn.evole.mods.mcbot.init.event; -import cn.evole.mods.mcbot.IMcBot; +import cn.evole.mods.mcbot.Const; +import cn.evole.mods.mcbot.init.config.ModConfig; +import cn.evole.mods.mcbot.util.locale.I18n; import net.minecraft.advancements.Advancement; +import net.minecraft.advancements.DisplayInfo; import net.minecraft.network.chat.Component; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.damagesource.DamageSource; @@ -10,13 +13,8 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; -//#if MC >= 11800 -import net.minecraftforge.common.ForgeI18n; -//#elseif MC < 11700 -//$$ import net.minecraftforge.fml.ForgeI18n; -//#else -//$$ import net.minecraftforge.fmllegacy.ForgeI18n; -//#endif + + /** * Description: * Author: cnlimiter @@ -24,91 +22,75 @@ * Version: 1.0 */ public class IPlayerEvent { - public static void loggedIn(Level level, Player player) { - if (IMcBot.config.getStatus().isSJoinEnable() - && IMcBot.config.getStatus().isSEnable() - && !level.isClientSide - ) { - if (IMcBot.config.getCommon().isGuildOn() && !IMcBot.config.getCommon().getChannelIdList().isEmpty()) { - for (String id : IMcBot.config.getCommon().getChannelIdList()) - IMcBot.bot.sendGuildMsg(IMcBot.config.getCommon().getGuildId(), id, player.getDisplayName().getString() + " 加入了服务器"); - } else { - for (long id : IMcBot.config.getCommon().getGroupIdList()) - IMcBot.bot.sendGroupMsg(id, player.getDisplayName().getString() + " 加入了服务器", false); - } + public static void loggedIn(Level world, Player player) { + if (ModConfig.INSTANCE.getStatus().isSJoinEnable() && ModConfig.INSTANCE.getStatus().isSEnable()) { + var msg = player.getDisplayName().getString() + " 加入了服务器"; + send(msg); } } - public static void loggedOut(Level level, Player player) { - if (IMcBot.config.getStatus().isSLeaveEnable() - && IMcBot.config.getStatus().isSEnable() - && !level.isClientSide - ) { - if (IMcBot.config.getCommon().isGuildOn() && !IMcBot.config.getCommon().getChannelIdList().isEmpty()) { - for (String id : IMcBot.config.getCommon().getChannelIdList()) - IMcBot.bot.sendGuildMsg(IMcBot.config.getCommon().getGuildId(), id, player.getDisplayName().getString() + " 离开了服务器"); - } else { - for (long id : IMcBot.config.getCommon().getGroupIdList()) - IMcBot.bot.sendGroupMsg(id, player.getDisplayName().getString() + " 离开了服务器", false); - } - } + public static void loggedOut(Level world, Player player) { + if (ModConfig.INSTANCE.getStatus().isSLeaveEnable() && ModConfig.INSTANCE.getStatus().isSEnable()) { + var msg = player.getDisplayName().getString() + " 离开了服务器"; + send(msg); + } } - public static void death(Level level, DamageSource source, ServerPlayer player) { - if (player != null - && IMcBot.config.getStatus().isSDeathEnable() - && IMcBot.config.getStatus().isSEnable() - && !level.isClientSide - ) { - LivingEntity livingEntity2 = player.getKillCredit(); - String msg = ""; + public static void death(DamageSource source, ServerPlayer player) { + if (player != null && ModConfig.INSTANCE.getStatus().isSDeathEnable() && ModConfig.INSTANCE.getStatus().isSEnable()) { + LivingEntity livingEntity2 = player.getKillCredit(); + String message = ""; - //#if MC >= 11904 - String string = "mcbot.death.attack." + source.type().msgId(); - //#else - //$$ String string = "mcbot.death.attack." + source.getMsgId(); - //#endif - - if (source.getEntity() == null && source.getDirectEntity() == null) { - String string2 = string + ".player"; - msg = livingEntity2 != null ? ForgeI18n.parseMessage(string2, player.getDisplayName().getString(), livingEntity2.getDisplayName().getString()) : ForgeI18n.parseMessage(string, player.getDisplayName().getString()); - } else {//支持物品造成的死亡信息 - assert source.getDirectEntity() != null; - Component component = source.getEntity() == null ? source.getDirectEntity().getDisplayName() : source.getEntity().getDisplayName(); - Entity sourceEntity = source.getEntity(); - ItemStack itemStack; - if (sourceEntity instanceof LivingEntity livingEntity3) { - itemStack = livingEntity3.getMainHandItem(); - } else { - itemStack = ItemStack.EMPTY; - } - msg = !itemStack.isEmpty() && itemStack.hasCustomHoverName() ? ForgeI18n.parseMessage(string + ".item", player.getDisplayName().getString(), component.getString(), itemStack.getDisplayName().getString()) : ForgeI18n.parseMessage(string,player.getDisplayName().getString(), component.getString()); - } + //#if MC >= 11904 + String string = "mcbot.death.attack." + source.type().msgId(); + //#else + //$$ String string = "mcbot.death.attack." + source.getMsgId(); + //#endif - if (IMcBot.config.getCommon().isGuildOn() && !IMcBot.config.getCommon().getChannelIdList().isEmpty()) { - for (String id : IMcBot.config.getCommon().getChannelIdList()) - IMcBot.bot.sendGuildMsg(IMcBot.config.getCommon().getGuildId(), id, String.format(msg, player.getDisplayName().getString())); + if (source.getEntity() == null && source.getDirectEntity() == null) { + String string2 = string + ".player"; + message = livingEntity2 != null ? I18n.get(string2, player.getDisplayName().getString(), livingEntity2.getDisplayName().getString()) : I18n.get(string, player.getDisplayName().getString()); + } else {//支持物品造成的死亡信息 + assert source.getDirectEntity() != null; + Component component = source.getEntity() == null ? source.getDirectEntity().getDisplayName() : source.getEntity().getDisplayName(); + Entity sourceEntity = source.getEntity(); + ItemStack itemStack; + if (sourceEntity instanceof LivingEntity livingEntity3) { + itemStack = livingEntity3.getMainHandItem(); } else { - for (long id : IMcBot.config.getCommon().getGroupIdList()) - IMcBot.bot.sendGroupMsg(id, String.format(msg, player.getDisplayName().getString()), false); + itemStack = ItemStack.EMPTY; } + message = !itemStack.isEmpty() && itemStack.hasCustomHoverName() ? I18n.get(string + ".item", player.getDisplayName().getString(), component.getString(), itemStack.getDisplayName().getString()) : I18n.get(string,player.getDisplayName().getString(), component.getString()); } + var msg = String.format(message, player.getDisplayName().getString()); + send(msg); + } } - public static void advancement(Level level, Player player, Advancement advancement) { - if (IMcBot.config.getStatus().isSAdvanceEnable() - && advancement.getDisplay() != null - && IMcBot.config.getStatus().isSEnable() - && !level.isClientSide - ) { - String msg = ForgeI18n.parseMessage("mcbot.chat.type.advancement." + advancement.getDisplay().getFrame().getName(), player.getDisplayName().getString(), ForgeI18n.parseMessage(advancement.getDisplay().getTitle().getString())); + public static void advancement(Player player, Advancement advancement) { + //#if MC <= 12001 + boolean displayExist = advancement.getDisplay() != null; + //#else + //$$ boolean displayExist = advancement.display().isPresent(); + //#endif - if (IMcBot.config.getCommon().isGuildOn() && !IMcBot.config.getCommon().getChannelIdList().isEmpty()) { - for (String id : IMcBot.config.getCommon().getChannelIdList()) - IMcBot.bot.sendGuildMsg(IMcBot.config.getCommon().getGuildId(), id, msg); - } else { - for (long id : IMcBot.config.getCommon().getGroupIdList()) - IMcBot.bot.sendGroupMsg(id, msg, false); - } - } + if (ModConfig.INSTANCE.getStatus().isSAdvanceEnable() && displayExist && ModConfig.INSTANCE.getStatus().isSEnable()) { + //#if MC <= 12001 + DisplayInfo display = advancement.getDisplay(); + //#else + //$$ DisplayInfo display = advancement.display().get(); + //#endif + + String message = I18n.get("mcbot.chat.type.advancement." + display.getFrame().getName(), player.getDisplayName().getString(), I18n.get(display.getTitle().getString())); + var msg = String.format(message, player.getDisplayName().getString()); + send(msg); + } + } + + private static void send(String msg){ + if (ModConfig.INSTANCE.getCommon().isGuildOn() && !ModConfig.INSTANCE.getCommon().getChannelIdList().isEmpty()) { + Const.sendGuildMsg(msg); + } else { + Const.sendGroupMsg(msg); + } } } diff --git a/forge/src/main/java/cn/evole/mods/mcbot/init/event/ITickEvent.java b/forge/src/main/java/cn/evole/mods/mcbot/init/event/ITickEvent.java index b7f9f4c1..edcd7041 100644 --- a/forge/src/main/java/cn/evole/mods/mcbot/init/event/ITickEvent.java +++ b/forge/src/main/java/cn/evole/mods/mcbot/init/event/ITickEvent.java @@ -1,15 +1,14 @@ package cn.evole.mods.mcbot.init.event; +import net.minecraft.server.MinecraftServer; +import java.util.LinkedList; +import java.util.Queue; +import cn.evole.mods.mcbot.init.config.ModConfig; //#if MC >= 11900 import net.minecraft.network.chat.Component; //#else //$$ import net.minecraft.network.chat.TextComponent; //#endif -import net.minecraft.server.MinecraftServer; -import cn.evole.mods.mcbot.IMcBot; -import java.util.LinkedList; -import java.util.Queue; - //#if MC <= 11802 //$$ import java.util.UUID; //$$ import net.minecraft.network.chat.ChatType; @@ -32,18 +31,18 @@ public static Queue getSendQueue() { public static void register(MinecraftServer server) { - String toSend = SEND_QUEUE.poll(); - if (IMcBot.config != null - && server.isDedicatedServer() - && toSend != null - ) { - //#if MC >= 11900 - server.getPlayerList().broadcastSystemMessage(Component.literal(toSend), false); - //#elseif MC <= 11502 - //$$ server.getPlayerList().broadcastMessage(new TextComponent(toSend), false); - //#else - //$$ server.getPlayerList().broadcastMessage(new TextComponent(toSend), ChatType.SYSTEM, Util.NIL_UUID); - //#endif - } + String toSend = SEND_QUEUE.poll(); + if (ModConfig.INSTANCE != null + && server.isDedicatedServer() + && toSend != null + ) { + //#if MC >= 11900 + server.getPlayerList().broadcastSystemMessage(Component.literal(toSend), false); + //#elseif MC <= 11502 + //$$ server.getPlayerList().broadcastMessage(new TextComponent(toSend), false); + //#else + //$$ server.getPlayerList().broadcastMessage(new TextComponent(toSend), ChatType.SYSTEM, Util.NIL_UUID); + //#endif + } } } diff --git a/forge/src/main/java/cn/evole/mods/mcbot/init/handler/CustomCmdHandler.java b/forge/src/main/java/cn/evole/mods/mcbot/init/handler/CustomCmdHandler.java index ebec08df..811aec7a 100644 --- a/forge/src/main/java/cn/evole/mods/mcbot/init/handler/CustomCmdHandler.java +++ b/forge/src/main/java/cn/evole/mods/mcbot/init/handler/CustomCmdHandler.java @@ -9,6 +9,7 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; import lombok.val; +import net.minecraftforge.fml.loading.FMLPaths; import org.apache.commons.io.IOUtils; import org.apache.commons.io.filefilter.FileFilterUtils; @@ -27,9 +28,11 @@ * Version: 1.0 */ public class CustomCmdHandler { - private final Gson GSON ; + public static final CustomCmdHandler INSTANCE = new CustomCmdHandler(); + private static final Gson GSON = (new GsonBuilder()).setPrettyPrinting().create(); + + private static final File dir = FMLPaths.CONFIGDIR.get().resolve("mcbot/cmds/").toFile(); - private final File dir; private final Map customCmdMap = new LinkedHashMap<>(); public List getCustomCmds() { @@ -44,11 +47,6 @@ public Map getCustomCmdMap() { return customCmdMap; } - public CustomCmdHandler(Path configDir){ - this.dir = configDir.resolve("cmds/").toFile(); - this.GSON = (new GsonBuilder()).setPrettyPrinting().create(); - } - public void load() { val stopwatch = Stopwatch.createStarted(); diff --git a/forge/src/main/java/cn/evole/mods/mcbot/util/locale/I18n.java b/forge/src/main/java/cn/evole/mods/mcbot/util/locale/I18n.java index eec484bf..44add026 100644 --- a/forge/src/main/java/cn/evole/mods/mcbot/util/locale/I18n.java +++ b/forge/src/main/java/cn/evole/mods/mcbot/util/locale/I18n.java @@ -2,10 +2,13 @@ import cn.evole.mods.mcbot.Const; import cn.evole.mods.mcbot.IMcBot; +import cn.evole.mods.mcbot.init.config.ModConfig; import cn.evole.onebot.sdk.util.FileUtils; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import net.minecraft.locale.Language; +import net.minecraftforge.fml.loading.FMLLoader; +import net.minecraftforge.fml.loading.FMLPaths; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.exception.ExceptionUtils; @@ -20,7 +23,8 @@ public class I18n { private static Map translations; public static Path LANG_FOLDER; - public static Path LANG_FILE; + public static String LANG_FILE; + public static String DEFAULT_LANG_FILE; @@ -28,32 +32,31 @@ public static void init(Path folder) { translations = new HashMap<>(); LANG_FOLDER = folder.resolve("lang"); FileUtils.checkFolder(LANG_FOLDER); - LANG_FILE = LANG_FOLDER.resolve(IMcBot.config.getCommon().getLanguageSelect() + ".json"); + LANG_FILE = "/lang/" + ModConfig.INSTANCE.getCommon().getLanguageSelect() + ".json"; + DEFAULT_LANG_FILE = "/lang/en_us.json"; + Path optional = FMLLoader.getLoadingModList().getModFileById("mcbot").getFile().findResource(LANG_FILE); - Optional optional = Optional.of(LANG_FILE); - - if (optional.isEmpty()) { + if (optional == null) { Const.LOGGER.warn("-----------------------------------------"); - Const.LOGGER.warn("McBot cannot find translations for \"" + IMcBot.config.getCommon().getLanguageSelect() + "\" and uses \"en_us\" by default!"); + Const.LOGGER.warn("McBot cannot find translations for \"" + ModConfig.INSTANCE.getCommon().getLanguageSelect() + "\" and uses \"en_us\" by default!"); Const.LOGGER.warn(""); Const.LOGGER.warn("You are welcome to contribute translations!"); Const.LOGGER.warn("Contributing: https://github.com/cnlimiter/McBot#Contributing"); Const.LOGGER.warn("-----------------------------------------"); -// optional = ForgeMod.getModContainer("mcbot").orElseThrow() -// .findPath("/lang/en_us.json"); + optional = FMLLoader.getLoadingModList().getModFileById("mcbot").getFile().findResource(DEFAULT_LANG_FILE); } - if (optional.isPresent()) { - try { - String content = IOUtils.toString(Files.newInputStream(optional.get()), StandardCharsets.UTF_8); - translations = new Gson().fromJson(content, new TypeToken>() { - }.getType()); - } catch (Exception e) { - Const.LOGGER.error(ExceptionUtils.getStackTrace(e)); - } + try { + String content = IOUtils.toString(Files.newInputStream(optional), StandardCharsets.UTF_8); + translations = new Gson().fromJson(content, new TypeToken>() { + }.getType()); + } catch (Exception e) { + Const.LOGGER.error(ExceptionUtils.getStackTrace(e)); } + + } public static String get(String key, Object... args) { diff --git a/forge/src/main/java/cn/evole/mods/mcbot/util/onebot/BotUtils.java b/forge/src/main/java/cn/evole/mods/mcbot/util/onebot/BotUtils.java index 04c75e33..1d9e47dc 100644 --- a/forge/src/main/java/cn/evole/mods/mcbot/util/onebot/BotUtils.java +++ b/forge/src/main/java/cn/evole/mods/mcbot/util/onebot/BotUtils.java @@ -26,7 +26,7 @@ public class BotUtils { private static boolean isVar(String msg) { AtomicBoolean match = new AtomicBoolean(false); - IMcBot.CMD.getCustomCmds().forEach( + CustomCmdHandler.INSTANCE.getCustomCmds().forEach( cmd -> { if (cmd.getCmdContent().contains("%")) {//是否变量模板 if (msg.contains(cmd.getCmdAlies()))//去除命令符号 diff --git a/forge/src/main/java/cn/evole/mods/mcbot/util/onebot/CQUtils.java b/forge/src/main/java/cn/evole/mods/mcbot/util/onebot/CQUtils.java index 392bbe62..cef8833b 100644 --- a/forge/src/main/java/cn/evole/mods/mcbot/util/onebot/CQUtils.java +++ b/forge/src/main/java/cn/evole/mods/mcbot/util/onebot/CQUtils.java @@ -2,6 +2,7 @@ import cn.evole.mods.mcbot.Const; import cn.evole.mods.mcbot.IMcBot; +import cn.evole.mods.mcbot.init.config.ModConfig; import cn.evole.onebot.sdk.util.BotUtils; import lombok.val; @@ -31,7 +32,7 @@ public static boolean hasImg(String msg) { } public static String replace(String msg) { - if (IMcBot.config.getBotConfig().isMiraiHttp()){ + if (ModConfig.INSTANCE.getBotConfig().isMiraiHttp()){ return msg; } @@ -51,7 +52,7 @@ public static String replace(String msg) { val data = matcher.group(2); switch (type) { case "image": { - if (IMcBot.config.getCommon().isImageOn() && Const.isLoad("chatimage")) { + if (ModConfig.INSTANCE.getCommon().isImageOn() && Const.isLoad("chatimage")) { val url = Arrays.stream(data.split(","))//具体数据分割 .filter(it -> it.startsWith("url"))//非空判断 .map(it -> it.substring(it.indexOf('=') + 1))