From 38e070db3bdf8acd7be7ea1f902e9bbdc12c4ca4 Mon Sep 17 00:00:00 2001 From: cnlimiter Date: Mon, 12 Feb 2024 17:21:12 +0800 Subject: [PATCH] ci(fabric): release --- .github/workflows/fabric.yml | 14 +++- .github/workflows/release.yml | 48 ++++++++++++ fabric/build.gradle | 8 +- fabric/common.gradle | 4 +- fabric/gradle.properties | 4 +- fabric/settings.gradle | 3 - .../main/java/cn/evole/mods/mcbot/Const.java | 66 ++-------------- .../main/java/cn/evole/mods/mcbot/McBot.java | 8 +- .../cn/evole/mods/mcbot/cmds/BotCmdRun.java | 38 ++++------ .../java/cn/evole/mods/mcbot/cmds/CmdApi.java | 4 +- .../mcbot/command/AddChannelIDCommand.java | 9 +-- .../mods/mcbot/command/AddGroupIDCommand.java | 13 ++-- .../mods/mcbot/command/AuthKeyCommand.java | 9 +-- .../mods/mcbot/command/BotIDCommand.java | 9 +-- .../mods/mcbot/command/ConnectCommand.java | 40 +++++----- .../mods/mcbot/command/DebugCommand.java | 13 ++-- .../mcbot/command/DelChannelIDCommand.java | 9 +-- .../mods/mcbot/command/DelGroupIDCommand.java | 9 +-- .../mods/mcbot/command/DisconnectCommand.java | 13 ++-- .../mods/mcbot/command/GuildIDCommand.java | 9 +-- .../evole/mods/mcbot/command/HelpCommand.java | 22 ++---- .../mods/mcbot/command/ListCustomCommand.java | 10 +-- .../mods/mcbot/command/ReConnectCommand.java | 14 ++-- .../mods/mcbot/command/ReceiveCommand.java | 29 ++++--- .../mods/mcbot/command/ReloadConfigCmd.java | 17 ++--- .../evole/mods/mcbot/command/SendCommand.java | 69 +++++++++-------- .../mods/mcbot/command/StatusCommand.java | 9 +-- .../mods/mcbot/init/config/BotConfig.java | 4 +- .../mods/mcbot/init/config/CmdConfig.java | 6 +- .../mods/mcbot/init/config/CommonConfig.java | 9 ++- .../mods/mcbot/init/config/ModConfig.java | 8 +- .../mods/mcbot/init/config/StatusConfig.java | 6 +- .../mods/mcbot/init/event/IBotEvent.java | 13 ++-- .../mods/mcbot/init/event/IChatEvent.java | 58 +++++++------- .../mods/mcbot/init/event/ICmdEvent.java | 11 +++ .../mods/mcbot/init/event/IPlayerEvent.java | 76 +++++++++---------- .../mods/mcbot/init/event/ITickEvent.java | 43 +++++------ .../mods/mcbot/init/mixins/MixinLanguage.java | 51 ++++++++++++- .../init/mixins/MixinPlayerAdvancements.java | 20 +++++ .../mcbot/init/mixins/MixinPlayerList.java | 15 +++- .../init/mixins/MixinServerGamePktImpl.java | 52 ++++++++++--- .../mcbot/init/mixins/MixinSystemCmd.java | 51 ++++++++----- .../evole/mods/mcbot/util/MessageThread.java | 64 ++++++++++++++++ fabric/versions/1.14.4/gradle.properties | 10 --- .../versions/1.14.4/src/test/java/Test.java | 20 ----- fabric/versions/1.15.2/gradle.properties | 10 --- .../mods/mcbot/init/mixins/MixinLanguage.java | 68 ----------------- .../init/mixins/MixinPlayerAdvancements.java | 35 --------- .../init/mixins/MixinServerGamePktImpl.java | 30 -------- .../init/mixins/MixinServerGamePktImpl.java | 29 ------- fabric/versions/1.17.1/gradle.properties | 10 --- .../init/mixins/MixinServerGamePktImpl.java | 31 -------- .../mcbot/init/mixins/MixinSystemCmd.java | 68 ----------------- .../mods/mcbot/init/mixins/MixinLanguage.java | 70 ----------------- .../init/mixins/MixinPlayerAdvancements.java | 35 --------- .../init/mixins/MixinServerGamePktImpl.java | 31 -------- .../mcbot/init/mixins/MixinSystemCmd.java | 7 +- .../init/mixins/MixinPlayerAdvancements.java | 36 --------- .../init/mixins/MixinServerGamePktImpl.java | 31 -------- .../mcbot/init/mixins/MixinSystemCmd.java | 5 +- .../mcbot/init/mixins/MixinSystemCmd.java | 43 +++++------ .../mods/mcbot/init/mixins/MixinLanguage.java | 16 ++++ .../mcbot/init/mixins/MixinPlayerList.java | 32 -------- fabric/versions/mainProject | 2 +- .../src/main/resources/fabric.mod.json | 9 --- 65 files changed, 614 insertions(+), 1001 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 fabric/src/main/java/cn/evole/mods/mcbot/util/MessageThread.java delete mode 100644 fabric/versions/1.14.4/gradle.properties delete mode 100644 fabric/versions/1.14.4/src/test/java/Test.java delete mode 100644 fabric/versions/1.15.2/gradle.properties delete mode 100644 fabric/versions/1.15.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinLanguage.java delete mode 100644 fabric/versions/1.15.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinPlayerAdvancements.java delete mode 100644 fabric/versions/1.15.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinServerGamePktImpl.java delete mode 100644 fabric/versions/1.16.5/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinServerGamePktImpl.java delete mode 100644 fabric/versions/1.17.1/gradle.properties delete mode 100644 fabric/versions/1.17.1/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinServerGamePktImpl.java delete mode 100644 fabric/versions/1.17.1/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinSystemCmd.java delete mode 100644 fabric/versions/1.18.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinLanguage.java delete mode 100644 fabric/versions/1.18.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinPlayerAdvancements.java delete mode 100644 fabric/versions/1.18.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinServerGamePktImpl.java delete mode 100644 fabric/versions/1.19.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinPlayerAdvancements.java delete mode 100644 fabric/versions/1.19.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinServerGamePktImpl.java rename fabric/versions/{1.15.2 => 1.19.3}/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinSystemCmd.java (53%) create mode 100644 fabric/versions/1.20.1/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinLanguage.java delete mode 100644 fabric/versions/1.20.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinPlayerList.java diff --git a/.github/workflows/fabric.yml b/.github/workflows/fabric.yml index 154469ca..52f639b5 100644 --- a/.github/workflows/fabric.yml +++ b/.github/workflows/fabric.yml @@ -16,21 +16,29 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - name: Checkout code + uses: actions/checkout@v4 + with: + show-progress: false + - name: Set up JDK 17 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: '17' - distribution: 'temurin' + distribution: 'dragonwell' + - name: Validate Gradle Wrapper uses: gradle/wrapper-validation-action@v1 + - name: Make Gradle Wrapper Executable run: chmod +x ./fabric/gradlew + - name: Build uses: gradle/gradle-build-action@v2 with: arguments: build build-root-directory: fabric + - name: Find Correct JAR id: findjar run: | diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..759afa65 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,48 @@ +name: Fabric Release + +on: + push: + tags: + - 'v*' + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + show-progress: false + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'dragonwell' + + - name: Validate Gradle Wrapper + uses: gradle/wrapper-validation-action@v1 + + - name: Make Gradle Wrapper Executable + run: chmod +x ./fabric/gradlew + + - name: Build + uses: gradle/gradle-build-action@v2 + with: + arguments: buildNeeded + build-root-directory: forge + + - name: Find Correct JAR + id: findjar + run: | + output="$(find fabric/wrapper/build/libs/ ! -name "*-sources.jar" -type f -printf "%f\n")" + echo "::set-output name=jarname::$output" + + - name: Release + uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/') + with: + files: fabric/wrapper/build/libs/${{ steps.findjar.outputs.jarname }} + body: Please refer to [CHANGELOG.md](https://github.com/Nova-Committee/re-avaritia/blob/master/CHANGELOG.md) for details. \ No newline at end of file diff --git a/fabric/build.gradle b/fabric/build.gradle index 0486e71c..6713a6c8 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -4,10 +4,7 @@ plugins { } preprocess { - def mc1144 = createNode("1.14.4", 1_14_04, "yarn") - def mc1152 = createNode("1.15.2", 1_15_02, "yarn") def mc1165 = createNode("1.16.5", 1_16_05, "yarn") - def mc1171 = createNode("1.17.1", 1_17_01, "yarn") def mc1182 = createNode("1.18.2", 1_18_02, "yarn") def mc1192 = createNode("1.19.2", 1_19_02, "yarn") def mc1193 = createNode("1.19.3", 1_19_03, "yarn") @@ -15,10 +12,7 @@ preprocess { def mc1201 = createNode("1.20.1", 1_20_01, "yarn") def mc1202 = createNode("1.20.2", 1_20_02, "yarn") - mc1144.link(mc1152, null) - mc1152.link(mc1165, null) - mc1165.link(mc1171, null) - mc1171.link(mc1182, null) + mc1165.link(mc1182, null) mc1182.link(mc1192, null) mc1192.link(mc1193, null) mc1193.link(mc1194, null) diff --git a/fabric/common.gradle b/fabric/common.gradle index edf624e7..82d21a21 100644 --- a/fabric/common.gradle +++ b/fabric/common.gradle @@ -41,8 +41,8 @@ remapJar { remapperIsolation = true } -sourceCompatibility = JavaVersion.VERSION_17 -targetCompatibility = JavaVersion.VERSION_17 +sourceCompatibility = JavaVersion.VERSION_1_8 +targetCompatibility = JavaVersion.VERSION_1_8 version = project.mod_version group = project.maven_group diff --git a/fabric/gradle.properties b/fabric/gradle.properties index 74414b74..7be16358 100644 --- a/fabric/gradle.properties +++ b/fabric/gradle.properties @@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx8G # Mod Properties -mod_version=2.1.9 +mod_version=2.1.9.1 maven_group=cn.evole.mods archives_base_name=McBot-fabric @@ -12,4 +12,4 @@ minecraft_version=1.20.1 loader_version=0.14.21 fabric_version=0.83.1+1.20.1 onebot_client_version=0.3.8 -toml_version=0.1.1 +toml_version=0.1.4 diff --git a/fabric/settings.gradle b/fabric/settings.gradle index 2e271182..e1364071 100644 --- a/fabric/settings.gradle +++ b/fabric/settings.gradle @@ -21,10 +21,7 @@ pluginManagement { } def versions = Arrays.asList( - "1.14.4", - "1.15.2", "1.16.5", - "1.17.1", "1.18.2", "1.19.2", "1.19.3", diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/Const.java b/fabric/src/main/java/cn/evole/mods/mcbot/Const.java index 90bdebbe..3562ea39 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/Const.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/Const.java @@ -1,17 +1,16 @@ package cn.evole.mods.mcbot; import cn.evole.mods.mcbot.init.config.ModConfig; -import cn.evole.onebot.sdk.util.BotUtils; -import com.google.gson.JsonArray; import net.fabricmc.loader.api.FabricLoader; +import cn.evole.mods.mcbot.util.MessageThread; +import cn.evole.onebot.sdk.util.BotUtils; import java.nio.file.Path; - //#if MC >= 11700 -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +//$$ import org.slf4j.Logger; +//$$ import org.slf4j.LoggerFactory; //#else -//$$ import org.apache.logging.log4j.Logger; -//$$ import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; //#endif /** @@ -23,9 +22,9 @@ public class Const { public static final String MODID = "mcbot"; //#if MC >= 11700 - public static final Logger LOGGER = LoggerFactory.getLogger("McBot"); + //$$ public static final Logger LOGGER = LoggerFactory.getLogger("McBot"); //#else - //$$ public static final Logger LOGGER = LogManager.getLogger("McBot"); + public static final Logger LOGGER = LogManager.getLogger("McBot"); //#endif public static boolean isShutdown = false; public static Path configDir = FabricLoader.getInstance().getConfigDir(); @@ -70,54 +69,5 @@ public static void guildMsg(String guildId, String channelId, String message){ } } -class MessageThread extends Thread { - private long groupIDInt; - private String guildIDString; - private String messageString; - private JsonArray messageArray; - private boolean autoEscape; - private String channelIDString; - private final short mode; - - MessageThread(long groupId, String msg, boolean autoEscape) { - this.mode = 0; - this.groupIDInt = groupId; - this.messageString = msg; - this.autoEscape = autoEscape; - } - MessageThread(long groupId, JsonArray msg, boolean autoEscape) { - this.mode = 1; - this.groupIDInt = groupId; - this.messageArray = msg; - this.autoEscape = autoEscape; - } - MessageThread(String guildID, String channelID, String message) { - this.mode = 2; - this.guildIDString = guildID; - this.channelIDString = channelID; - this.messageString = message; - } - MessageThread(String guildID, String channelID, JsonArray message) { - this.mode = 3; - this.guildIDString = guildID; - this.channelIDString = channelID; - this.messageArray = message; - } - - public void run() { - switch (mode) { - case 0 -> McBot.bot.sendGroupMsg(groupIDInt, messageString, autoEscape); - case 1 -> McBot.bot.sendGroupMsg(groupIDInt, messageArray, autoEscape); - case 2 -> McBot.bot.sendGuildMsg(guildIDString, channelIDString, messageString); - case 3 -> McBot.bot.sendGuildMsg(guildIDString, channelIDString, messageArray); - } - } - - public void start() { - Const.LOGGER.info(String.format("转发游戏消息: %s", messageString!= null ? messageString : messageArray)); - Thread thread = new Thread(this, "MessageThread"); - thread.start(); - } -} diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/McBot.java b/fabric/src/main/java/cn/evole/mods/mcbot/McBot.java index 150c507f..81f95fe4 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/McBot.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/McBot.java @@ -11,9 +11,9 @@ import cn.evole.onebot.sdk.util.FileUtils; import net.fabricmc.api.ModInitializer; //#if MC >= 11900 -import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; +//$$ import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; //#else -//$$ import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback; +import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback; //#endif import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; @@ -45,9 +45,9 @@ public MinecraftServer getServer() { public void onInitialize() { init(); //#if MC >= 11900 - CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> ICmdEvent.register(dispatcher)); + //$$ CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> ICmdEvent.register(dispatcher)); //#else - //$$ CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> ICmdEvent.register(dispatcher)); + CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> ICmdEvent.register(dispatcher)); //#endif ServerLifecycleEvents.SERVER_STARTING.register(this::onServerStarting); diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/cmds/BotCmdRun.java b/fabric/src/main/java/cn/evole/mods/mcbot/cmds/BotCmdRun.java index 0b73712f..3f606809 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/cmds/BotCmdRun.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/cmds/BotCmdRun.java @@ -14,16 +14,13 @@ import java.util.ArrayList; import java.util.List; import java.util.function.Supplier; -//#if MC >= 11900 +//#if MC < 11900 import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TextComponent; //#else -//$$ import net.minecraft.network.chat.TextComponent; //$$ import net.minecraft.network.chat.Component; //#endif -//#if MC < 11600 -//$$ import net.minecraft.world.level.dimension.DimensionType; -//#endif /** @@ -34,15 +31,12 @@ */ public class BotCmdRun extends CommandSourceStack { - //#if MC >= 11900 - public static BotCmdRun CUSTOM = new BotCmdRun(CommandSource.NULL, Vec3.ZERO, Vec2.ZERO, McBot.SERVER.overworld(), 4, "Bot", Component.literal("Bot"), McBot.SERVER, null); - public static BotCmdRun OP = new BotCmdRun(CommandSource.NULL, Vec3.ZERO, Vec2.ZERO, McBot.SERVER.overworld(), 4, "OP", Component.literal("OP"), McBot.SERVER, null); - //#elseif MC < 11600 - //$$ public static BotCmdRun CUSTOM = new BotCmdRun(CommandSource.NULL, Vec3.ZERO, Vec2.ZERO, McBot.SERVER.getLevel(DimensionType.OVERWORLD), 4, "Bot", new TextComponent("Bot"), McBot.SERVER, null); - //$$ public static BotCmdRun OP = new BotCmdRun(CommandSource.NULL, Vec3.ZERO, Vec2.ZERO, McBot.SERVER.getLevel(DimensionType.OVERWORLD), 4, "OP", new TextComponent("OP"), McBot.SERVER, null); + //#if MC < 11900 + public static BotCmdRun CUSTOM = new BotCmdRun(CommandSource.NULL, Vec3.ZERO, Vec2.ZERO, McBot.SERVER.overworld(), 4, "Bot", new TextComponent("Bot"), McBot.SERVER, null); + public static BotCmdRun OP = new BotCmdRun(CommandSource.NULL, Vec3.ZERO, Vec2.ZERO, McBot.SERVER.overworld(), 4, "OP", new TextComponent("OP"), McBot.SERVER, null); //#else - //$$ public static BotCmdRun CUSTOM = new BotCmdRun(CommandSource.NULL, Vec3.ZERO, Vec2.ZERO, McBot.SERVER.overworld(), 4, "Bot", new TextComponent("Bot"), McBot.SERVER, null); - //$$ public static BotCmdRun OP = new BotCmdRun(CommandSource.NULL, Vec3.ZERO, Vec2.ZERO, McBot.SERVER.overworld(), 4, "OP", new TextComponent("OP"), McBot.SERVER, null); + //$$ public static BotCmdRun CUSTOM = new BotCmdRun(CommandSource.NULL, Vec3.ZERO, Vec2.ZERO, McBot.SERVER.overworld(), 4, "Bot", Component.literal("Bot"), McBot.SERVER, null); + //$$ public static BotCmdRun OP = new BotCmdRun(CommandSource.NULL, Vec3.ZERO, Vec2.ZERO, McBot.SERVER.overworld(), 4, "OP", Component.literal("OP"), McBot.SERVER, null); //#endif @@ -53,17 +47,17 @@ public BotCmdRun(CommandSource commandSource, Vec3 vec3, Vec2 vec2, ServerLevel } //#if MC >= 12000 - @Override - public void sendSuccess(Supplier supplier, boolean bl) { - super.sendSuccess(supplier, bl); - this.outPut.add(supplier.get().getString()); - } - //#else //$$ @Override - //$$ public void sendSuccess(@NotNull Component component, boolean p_81356_) { - //$$ super.sendSuccess(component, p_81356_); - //$$ this.outPut.add(component.getString()); + //$$ public void sendSuccess(Supplier supplier, boolean bl) { + //$$ super.sendSuccess(supplier, bl); + //$$ this.outPut.add(supplier.get().getString()); //$$ } + //#else + @Override + public void sendSuccess(@NotNull Component component, boolean p_81356_) { + super.sendSuccess(component, p_81356_); + this.outPut.add(component.getString()); + } //#endif } diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/cmds/CmdApi.java b/fabric/src/main/java/cn/evole/mods/mcbot/cmds/CmdApi.java index 17bd60d0..39cbdbd9 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/cmds/CmdApi.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/cmds/CmdApi.java @@ -17,9 +17,9 @@ public class CmdApi { private static StringBuilder CmdMain(String cmd, boolean isOp) { StringBuilder result = new StringBuilder(); //#if MC >= 11900 - McBot.SERVER.getCommands().performPrefixedCommand(isOp ? BotCmdRun.OP : BotCmdRun.CUSTOM, cmd);//优雅 + //$$ McBot.SERVER.getCommands().performPrefixedCommand(isOp ? BotCmdRun.OP : BotCmdRun.CUSTOM, cmd);//优雅 //#else - //$$ McBot.SERVER.getCommands().performCommand(isOp ? BotCmdRun.OP : BotCmdRun.CUSTOM, cmd); + McBot.SERVER.getCommands().performCommand(isOp ? BotCmdRun.OP : BotCmdRun.CUSTOM, cmd); //#endif for (String s : (isOp ? BotCmdRun.OP.outPut : BotCmdRun.CUSTOM.outPut)) { result.append(s.replaceAll("§\\S", "")).append("\n"); diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/command/AddChannelIDCommand.java b/fabric/src/main/java/cn/evole/mods/mcbot/command/AddChannelIDCommand.java index c54d3a12..6ef841f3 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/command/AddChannelIDCommand.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/command/AddChannelIDCommand.java @@ -5,10 +5,9 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import lombok.val; import net.minecraft.commands.CommandSourceStack; -//#if MC >= 11900 import net.minecraft.network.chat.Component; -//#else -//$$ import net.minecraft.network.chat.TextComponent; +//#if MC <11900 +import net.minecraft.network.chat.TextComponent; //#endif public class AddChannelIDCommand { @@ -20,9 +19,9 @@ public static int execute(CommandContext context) throws Com if (ModConfig.INSTANCE.getCommon().getChannelIdList().contains(id)) { //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("子频道号:" + id + "已经出现了!"), true); + //$$ context.getSource().sendSuccess(()->Component.literal("子频道号:" + id + "已经出现了!"), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent("子频道号:" + id + "已经出现了!"), true); + context.getSource().sendSuccess(new TextComponent("子频道号:" + id + "已经出现了!"), true); //#else //$$ context.getSource().sendSuccess(Component.literal("子频道号:" + id + "已经出现了!"), true); //#endif diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/command/AddGroupIDCommand.java b/fabric/src/main/java/cn/evole/mods/mcbot/command/AddGroupIDCommand.java index 9ceea7a9..36aacf23 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/command/AddGroupIDCommand.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/command/AddGroupIDCommand.java @@ -5,10 +5,9 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import lombok.val; import net.minecraft.commands.CommandSourceStack; -//#if MC >= 11900 import net.minecraft.network.chat.Component; -//#else -//$$ import net.minecraft.network.chat.TextComponent; +//#if MC <11900 +import net.minecraft.network.chat.TextComponent; //#endif public class AddGroupIDCommand { @@ -18,18 +17,18 @@ public static int execute(CommandContext context) throws Com val id = context.getArgument("GroupId", Long.class); if (ModConfig.INSTANCE.getCommon().getGroupIdList().contains(id)) { //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("QQ群号:" + id + "已经出现了!"), true); + //$$ context.getSource().sendSuccess(()->Component.literal("QQ群号:" + id + "已经出现了!"), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent("QQ群号:" + id + "已经出现了!"), true); + context.getSource().sendSuccess(new TextComponent("QQ群号:" + id + "已经出现了!"), true); //#else //$$ context.getSource().sendSuccess(Component.literal("QQ群号:" + id + "已经出现了!"), true); //#endif } else { ModConfig.INSTANCE.getCommon().addGroupId(id); //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("已成功添加QQ群号:" + id + "!"), true); + //$$ context.getSource().sendSuccess(()->Component.literal("已成功添加QQ群号:" + id + "!"), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent("已成功添加QQ群号:" + id + "!"), true); + context.getSource().sendSuccess(new TextComponent("已成功添加QQ群号:" + id + "!"), true); //#else //$$ context.getSource().sendSuccess(Component.literal("已成功添加QQ群号:" + id + "!"), true); //#endif diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/command/AuthKeyCommand.java b/fabric/src/main/java/cn/evole/mods/mcbot/command/AuthKeyCommand.java index 82ed79a2..dbbc5e2e 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/command/AuthKeyCommand.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/command/AuthKeyCommand.java @@ -5,10 +5,9 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import lombok.val; import net.minecraft.commands.CommandSourceStack; -//#if MC >= 11900 import net.minecraft.network.chat.Component; -//#else -//$$ import net.minecraft.network.chat.TextComponent; +//#if MC <11900 +import net.minecraft.network.chat.TextComponent; //#endif public class AuthKeyCommand { @@ -17,9 +16,9 @@ public static int execute(CommandContext context) throws Com val id = context.getArgument("AuthKey", String.class); ModConfig.INSTANCE.getBotConfig().setToken(id); //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("已设置框架的AuthKey为:" + id), true); + //$$ context.getSource().sendSuccess(()->Component.literal("已设置框架的AuthKey为:" + id), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent("已设置Mirai框架的VerifyKey为:" + id), true); + context.getSource().sendSuccess(new TextComponent("已设置Mirai框架的VerifyKey为:" + id), true); //#else //$$ context.getSource().sendSuccess(Component.literal("已设置Mirai框架的VerifyKey为:" + id), true); //#endif diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/command/BotIDCommand.java b/fabric/src/main/java/cn/evole/mods/mcbot/command/BotIDCommand.java index c2428a4e..fd171084 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/command/BotIDCommand.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/command/BotIDCommand.java @@ -4,10 +4,9 @@ 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; -//#else -//$$ import net.minecraft.network.chat.TextComponent; +//#if MC <11900 +import net.minecraft.network.chat.TextComponent; //#endif public class BotIDCommand { @@ -17,9 +16,9 @@ public static int execute(CommandContext context) throws Com long id = context.getArgument("BotId", Long.class); ModConfig.INSTANCE.getCommon().setBotId(id); //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("已设置机器人QQ号为:" + id + "!"), true); + //$$ context.getSource().sendSuccess(()->Component.literal("已设置机器人QQ号为:" + id + "!"), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent("已设置机器人QQ号为:" + id + "!"), true); + context.getSource().sendSuccess(new TextComponent("已设置机器人QQ号为:" + id + "!"), true); //#else //$$ context.getSource().sendSuccess(Component.literal("已设置机器人QQ号为:" + id + "!"), true); //#endif diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/command/ConnectCommand.java b/fabric/src/main/java/cn/evole/mods/mcbot/command/ConnectCommand.java index 0f2b3ca9..965b1726 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/command/ConnectCommand.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/command/ConnectCommand.java @@ -10,14 +10,12 @@ import lombok.val; import net.minecraft.ChatFormatting; import net.minecraft.commands.CommandSourceStack; -//#if MC >= 11900 +import java.util.regex.Pattern; import net.minecraft.network.chat.Component; -//#else -//$$ import net.minecraft.network.chat.TextComponent; +//#if MC <11900 +import net.minecraft.network.chat.TextComponent; //#endif -import java.util.regex.Pattern; - public class ConnectCommand { public static int cqhttpExecute(CommandContext context) throws CommandSyntaxException { @@ -29,9 +27,9 @@ public static int cqhttpExecute(CommandContext context) thro if (matcher.find()) { ModConfig.INSTANCE.getBotConfig().setUrl("ws://" + parameter); //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("尝试链接框架" + ChatFormatting.LIGHT_PURPLE + "cqhttp"), true); + //$$ context.getSource().sendSuccess(()->Component.literal("尝试链接框架" + ChatFormatting.LIGHT_PURPLE + "cqhttp"), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent("尝试链接框架" + ChatFormatting.LIGHT_PURPLE + "cqhttp"), true); + context.getSource().sendSuccess(new TextComponent("尝试链接框架" + ChatFormatting.LIGHT_PURPLE + "cqhttp"), true); //#else //$$ context.getSource().sendSuccess(Component.literal("尝试链接框架" + ChatFormatting.LIGHT_PURPLE + "cqhttp"), true); //#endif @@ -53,9 +51,9 @@ public static int cqhttpExecute(CommandContext context) thro } else { //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal(ChatFormatting.RED + "参数错误❌"), true); + //$$ context.getSource().sendSuccess(()->Component.literal(ChatFormatting.RED + "参数错误❌"), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent(ChatFormatting.RED + "参数错误❌"), true); + context.getSource().sendSuccess(new TextComponent(ChatFormatting.RED + "参数错误❌"), true); //#else //$$ context.getSource().sendSuccess(Component.literal(ChatFormatting.RED + "参数错误❌"), true); //#endif @@ -71,9 +69,9 @@ public static int miraiExecute(CommandContext context) throw if (matcher.find()) { ModConfig.INSTANCE.getBotConfig().setUrl("ws://" + parameter); //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("尝试链接框架" + ChatFormatting.LIGHT_PURPLE + "mirai"), true); + //$$ context.getSource().sendSuccess(()->Component.literal("尝试链接框架" + ChatFormatting.LIGHT_PURPLE + "mirai"), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent("尝试链接框架" + ChatFormatting.LIGHT_PURPLE + "mirai"), true); + context.getSource().sendSuccess(new TextComponent("尝试链接框架" + ChatFormatting.LIGHT_PURPLE + "mirai"), true); //#else //$$ context.getSource().sendSuccess(Component.literal("尝试链接框架" + ChatFormatting.LIGHT_PURPLE + "mirai"), true); //#endif @@ -94,9 +92,9 @@ public static int miraiExecute(CommandContext context) throw } else { //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal(ChatFormatting.RED + "参数错误❌"), true); + //$$ context.getSource().sendSuccess(()->Component.literal(ChatFormatting.RED + "参数错误❌"), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent(ChatFormatting.RED + "参数错误❌"), true); + context.getSource().sendSuccess(new TextComponent(ChatFormatting.RED + "参数错误❌"), true); //#else //$$ context.getSource().sendSuccess(Component.literal(ChatFormatting.RED + "参数错误❌"), true); //#endif @@ -106,17 +104,17 @@ public static int miraiExecute(CommandContext context) throw public static int cqhttpCommonExecute(CommandContext context) throws CommandSyntaxException { //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("尝试链接框架" + ChatFormatting.LIGHT_PURPLE + "cqhttp"), true); + //$$ context.getSource().sendSuccess(()->Component.literal("尝试链接框架" + ChatFormatting.LIGHT_PURPLE + "cqhttp"), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent("尝试链接框架" + ChatFormatting.LIGHT_PURPLE + "cqhttp"), true); + context.getSource().sendSuccess(new TextComponent("尝试链接框架" + ChatFormatting.LIGHT_PURPLE + "cqhttp"), true); //#else //$$ context.getSource().sendSuccess(Component.literal("尝试链接框架" + ChatFormatting.LIGHT_PURPLE + "cqhttp"), true); //#endif ModConfig.INSTANCE.getBotConfig().setMiraiHttp(false); try { McBot.app = new Thread(() -> { - McBot.service = new ConnectFactory(ModConfig.INSTANCE.getBotConfig().toBot(), McBot.blockingQueue);//创建websocket连接 - McBot.bot = McBot.service.ws.createBot();//创建机器人实例 + McBot.service = new ConnectFactory(ModConfig.INSTANCE.getBotConfig().toBot(), McBot.blockingQueue);//创建websocket连接 + McBot.bot = McBot.service.ws.createBot();//创建机器人实例 }, "BotServer"); McBot.app.start(); } catch (Exception e) { @@ -131,17 +129,17 @@ public static int cqhttpCommonExecute(CommandContext context public static int miraiCommonExecute(CommandContext context) throws CommandSyntaxException { //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("尝试链接框架" + ChatFormatting.LIGHT_PURPLE + "mirai"), true); + //$$ context.getSource().sendSuccess(()->Component.literal("尝试链接框架" + ChatFormatting.LIGHT_PURPLE + "mirai"), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent("尝试链接框架" + ChatFormatting.LIGHT_PURPLE + "mirai"), true); + context.getSource().sendSuccess(new TextComponent("尝试链接框架" + ChatFormatting.LIGHT_PURPLE + "mirai"), true); //#else //$$ context.getSource().sendSuccess(Component.literal("尝试链接框架" + ChatFormatting.LIGHT_PURPLE + "mirai"), true); //#endif ModConfig.INSTANCE.getBotConfig().setMiraiHttp(true); try { McBot.app = new Thread(() -> { - McBot.service = new ConnectFactory(ModConfig.INSTANCE.getBotConfig().toBot(), McBot.blockingQueue);//创建websocket连接 - McBot.bot = McBot.service.ws.createBot();//创建机器人实例 + McBot.service = new ConnectFactory(ModConfig.INSTANCE.getBotConfig().toBot(), McBot.blockingQueue);//创建websocket连接 + McBot.bot = McBot.service.ws.createBot();//创建机器人实例 }, "BotServer"); McBot.app.start(); } catch (Exception e) { diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/command/DebugCommand.java b/fabric/src/main/java/cn/evole/mods/mcbot/command/DebugCommand.java index e08079b4..15442a94 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/command/DebugCommand.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/command/DebugCommand.java @@ -5,10 +5,9 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.minecraft.ChatFormatting; import net.minecraft.commands.CommandSourceStack; -//#if MC >= 11900 import net.minecraft.network.chat.Component; -//#else -//$$ import net.minecraft.network.chat.TextComponent; +//#if MC <11900 +import net.minecraft.network.chat.TextComponent; //#endif /** * @author cnlimiter @@ -21,17 +20,17 @@ public static int execute(CommandContext context) throws Com ModConfig.INSTANCE.getCommon().setDebug(isEnabled); if (isEnabled) { //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("已开启开发者模式"), true); + //$$ context.getSource().sendSuccess(()->Component.literal("已开启开发者模式"), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent("已开启开发者模式"), true); + context.getSource().sendSuccess(new TextComponent("已开启开发者模式"), true); //#else //$$ context.getSource().sendSuccess(Component.literal("已开启开发者模式"), true); //#endif } else { //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("已关闭开发者模式"), true); + //$$ context.getSource().sendSuccess(()->Component.literal("已关闭开发者模式"), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent("已关闭开发者模式"), true); + context.getSource().sendSuccess(new TextComponent("已关闭开发者模式"), true); //#else //$$ context.getSource().sendSuccess(Component.literal("已关闭开发者模式"), true); //#endif diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/command/DelChannelIDCommand.java b/fabric/src/main/java/cn/evole/mods/mcbot/command/DelChannelIDCommand.java index 5c45da7c..f12dadde 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/command/DelChannelIDCommand.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/command/DelChannelIDCommand.java @@ -5,10 +5,9 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import lombok.val; import net.minecraft.commands.CommandSourceStack; -//#if MC >= 11900 import net.minecraft.network.chat.Component; -//#else -//$$ import net.minecraft.network.chat.TextComponent; +//#if MC <11900 +import net.minecraft.network.chat.TextComponent; //#endif public class DelChannelIDCommand { @@ -19,9 +18,9 @@ public static int execute(CommandContext context) throws Com ModConfig.INSTANCE.getCommon().removeChannelId(id); } else { //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("子频道号:" + id + "并未出现!"), true); + //$$ context.getSource().sendSuccess(()->Component.literal("子频道号:" + id + "并未出现!"), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent("子频道号:" + id + "并未出现!"), true); + context.getSource().sendSuccess(new TextComponent("子频道号:" + id + "并未出现!"), true); //#else //$$ context.getSource().sendSuccess(Component.literal("子频道号:" + id + "并未出现!"), true); //#endif diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/command/DelGroupIDCommand.java b/fabric/src/main/java/cn/evole/mods/mcbot/command/DelGroupIDCommand.java index 44d9d836..11853c21 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/command/DelGroupIDCommand.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/command/DelGroupIDCommand.java @@ -5,10 +5,9 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import lombok.val; import net.minecraft.commands.CommandSourceStack; -//#if MC >= 11900 import net.minecraft.network.chat.Component; -//#else -//$$ import net.minecraft.network.chat.TextComponent; +//#if MC <11900 +import net.minecraft.network.chat.TextComponent; //#endif public class DelGroupIDCommand { @@ -19,9 +18,9 @@ public static int execute(CommandContext context) throws Com ModConfig.INSTANCE.getCommon().removeGroupId(id); } else { //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("QQ群号:" + id + "并未出现!"), true); + //$$ context.getSource().sendSuccess(()->Component.literal("QQ群号:" + id + "并未出现!"), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent("QQ群号:" + id + "并未出现!"), true); + context.getSource().sendSuccess(new TextComponent("QQ群号:" + id + "并未出现!"), true); //#else //$$ context.getSource().sendSuccess(Component.literal("QQ群号:" + id + "并未出现!"), true); //#endif diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/command/DisconnectCommand.java b/fabric/src/main/java/cn/evole/mods/mcbot/command/DisconnectCommand.java index 0b194a25..1851db7f 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/command/DisconnectCommand.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/command/DisconnectCommand.java @@ -6,10 +6,9 @@ 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; -//#else -//$$ import net.minecraft.network.chat.TextComponent; +//#if MC <11900 +import net.minecraft.network.chat.TextComponent; //#endif public class DisconnectCommand { @@ -19,17 +18,17 @@ public static int execute(CommandContext context) throws Com McBot.service.stop(); if (!McBot.service.ws.isOpen()) { //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("WebSocket已断开连接"), true); + //$$ context.getSource().sendSuccess(()->Component.literal("WebSocket已断开连接"), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent("WebSocket已断开连接"), true); + context.getSource().sendSuccess(new TextComponent("WebSocket已断开连接"), true); //#else //$$ context.getSource().sendSuccess(Component.literal("WebSocket已断开连接"), true); //#endif } else { //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("WebSocket目前未连接"), true); + //$$ context.getSource().sendSuccess(()->Component.literal("WebSocket目前未连接"), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent("WebSocket目前未连接"), true); + context.getSource().sendSuccess(new TextComponent("WebSocket目前未连接"), true); //#else //$$ context.getSource().sendSuccess(Component.literal("WebSocket目前未连接"), true); //#endif diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/command/GuildIDCommand.java b/fabric/src/main/java/cn/evole/mods/mcbot/command/GuildIDCommand.java index 58054277..a8c23d12 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/command/GuildIDCommand.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/command/GuildIDCommand.java @@ -5,10 +5,9 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import lombok.val; import net.minecraft.commands.CommandSourceStack; -//#if MC >= 11900 import net.minecraft.network.chat.Component; -//#else -//$$ import net.minecraft.network.chat.TextComponent; +//#if MC <11900 +import net.minecraft.network.chat.TextComponent; //#endif public class GuildIDCommand { @@ -18,9 +17,9 @@ public static int execute(CommandContext context) throws Com ModConfig.INSTANCE.getCommon().setGuildOn(true); ModConfig.INSTANCE.getCommon().setGuildId(id); //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("已设置互通的频道号为:" + id), true); + //$$ context.getSource().sendSuccess(()->Component.literal("已设置互通的频道号为:" + id), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent("已设置互通的频道号为:" + id), true); + context.getSource().sendSuccess(new TextComponent("已设置互通的频道号为:" + id), true); //#else //$$ context.getSource().sendSuccess(Component.literal("已设置互通的频道号为:" + id), true); //#endif diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/command/HelpCommand.java b/fabric/src/main/java/cn/evole/mods/mcbot/command/HelpCommand.java index bd294a7a..a4681bdb 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/command/HelpCommand.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/command/HelpCommand.java @@ -1,7 +1,6 @@ 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; @@ -9,10 +8,9 @@ import net.minecraft.commands.CommandSourceStack; import net.minecraft.network.chat.Style; import net.minecraft.network.chat.ClickEvent; -//#if MC >= 11900 import net.minecraft.network.chat.Component; -//#else -//$$ import net.minecraft.network.chat.TextComponent; +//#if MC <11900 +import net.minecraft.network.chat.TextComponent; //#endif public class HelpCommand { @@ -53,21 +51,17 @@ public static int execute(CommandContext context) throws Com val url = "https://github.com/Nova-Committee/Bot-Connect/issues/new"; val end = "提交问题"; //#if MC >= 11900 - var urlC = Component.literal(url).setStyle(Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://github.com/Nova-Committee/Bot-Connect/issues/new"))); - var endC = Component.literal(end); - //#elseif MC < 11600 - //$$ Style style = new Style(); - //$$ var urlC = new TextComponent(url).setStyle(style.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://github.com/Nova-Committee/Bot-Connect/issues/new"))); - //$$ var endC = new TextComponent(end); + //$$ val urlC = Component.literal(url).setStyle(Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://github.com/Nova-Committee/Bot-Connect/issues/new"))); + //$$ val endC = Component.literal(end); //#else - //$$ var urlC = new TextComponent(url).setStyle(Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://github.com/Nova-Committee/Bot-Connect/issues/new"))); - //$$ var endC = new TextComponent(end); + val urlC = new TextComponent(url).setStyle(Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://github.com/Nova-Committee/Bot-Connect/issues/new"))); + val endC = new TextComponent(end); //#endif //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal(toSend).append(urlC).append(endC), true); + //$$ context.getSource().sendSuccess(()->Component.literal(toSend).append(urlC).append(endC), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent(toSend).append(urlC).append(endC), true); + context.getSource().sendSuccess(new TextComponent(toSend).append(urlC).append(endC), true); //#else //$$ context.getSource().sendSuccess(Component.literal(toSend).append(urlC).append(endC), true); //#endif diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/command/ListCustomCommand.java b/fabric/src/main/java/cn/evole/mods/mcbot/command/ListCustomCommand.java index 4b7fcb1d..b37ffa98 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/command/ListCustomCommand.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/command/ListCustomCommand.java @@ -1,15 +1,15 @@ package cn.evole.mods.mcbot.command; + import cn.evole.mods.mcbot.init.config.ModConfig; import cn.evole.mods.mcbot.init.handler.CustomCmdHandler; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.minecraft.commands.CommandSourceStack; -//#if MC >= 11900 import net.minecraft.network.chat.Component; -//#else -//$$ import net.minecraft.network.chat.TextComponent; +//#if MC <11900 +import net.minecraft.network.chat.TextComponent; //#endif public class ListCustomCommand { @@ -20,9 +20,9 @@ public static int execute(CommandContext context) throws Com out.append(s).append("\n"); } //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal(out.toString()), true); + //$$ context.getSource().sendSuccess(()->Component.literal(out.toString()), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent(out.toString()), true); + context.getSource().sendSuccess(new TextComponent(out.toString()), true); //#else //$$ context.getSource().sendSuccess(Component.literal(out.toString()), true); //#endif diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/command/ReConnectCommand.java b/fabric/src/main/java/cn/evole/mods/mcbot/command/ReConnectCommand.java index 4c3fbd88..dadda88f 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/command/ReConnectCommand.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/command/ReConnectCommand.java @@ -1,14 +1,12 @@ 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 net.minecraft.commands.CommandSourceStack; -//#if MC >= 11900 import net.minecraft.network.chat.Component; -//#else -//$$ import net.minecraft.network.chat.TextComponent; +//#if MC <11900 +import net.minecraft.network.chat.TextComponent; //#endif public class ReConnectCommand { @@ -18,17 +16,17 @@ public static int execute(CommandContext context) throws Com ModConfig.INSTANCE.getBotConfig().setReconnect(isEnabled); if (isEnabled) { //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("已设置自动重连"), true); + //$$ context.getSource().sendSuccess(()->Component.literal("已设置自动重连"), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent("已设置自动重连"), true); + context.getSource().sendSuccess(new TextComponent("已设置自动重连"), true); //#else //$$ context.getSource().sendSuccess(Component.literal("已设置自动重连"), true); //#endif } else { //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("已关闭自动重连"), true); + //$$ context.getSource().sendSuccess(()->Component.literal("已关闭自动重连"), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent("已关闭自动重连"), true); + context.getSource().sendSuccess(new TextComponent("已关闭自动重连"), true); //#else //$$ context.getSource().sendSuccess(Component.literal("已关闭自动重连"), true); //#endif diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/command/ReceiveCommand.java b/fabric/src/main/java/cn/evole/mods/mcbot/command/ReceiveCommand.java index 9e824621..c91c387d 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/command/ReceiveCommand.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/command/ReceiveCommand.java @@ -4,10 +4,9 @@ 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; -//#else -//$$ import net.minecraft.network.chat.TextComponent; +//#if MC <11900 +import net.minecraft.network.chat.TextComponent; //#endif public class ReceiveCommand { @@ -17,17 +16,17 @@ public static int allExecute(CommandContext context) throws ModConfig.INSTANCE.getStatus().setREnable(isEnabled); if (isEnabled) { //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("全局接收群消息开关已被设置为打开"), true); + //$$ context.getSource().sendSuccess(()->Component.literal("全局接收群消息开关已被设置为打开"), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent("全局接收群消息开关已被设置为打开"), true); + context.getSource().sendSuccess(new TextComponent("全局接收群消息开关已被设置为打开"), true); //#else //$$ context.getSource().sendSuccess(Component.literal("全局接收群消息开关已被设置为打开"), true); //#endif } else { //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("全局接收群消息开关已被设置为关闭"), true); + //$$ context.getSource().sendSuccess(()->Component.literal("全局接收群消息开关已被设置为关闭"), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent("全局接收群消息开关已被设置为关闭"), true); + context.getSource().sendSuccess(new TextComponent("全局接收群消息开关已被设置为关闭"), true); //#else //$$ context.getSource().sendSuccess(Component.literal("全局接收群消息开关已被设置为关闭"), true); //#endif @@ -42,17 +41,17 @@ public static int chatExecute(CommandContext context) throws if (isEnabled) { ModConfig.INSTANCE.getStatus().setREnable(true); //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("接收群内聊天消息开关已被设置为打开"), true); + //$$ context.getSource().sendSuccess(()->Component.literal("接收群内聊天消息开关已被设置为打开"), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent("接收群内聊天消息开关已被设置为打开"), true); + context.getSource().sendSuccess(new TextComponent("接收群内聊天消息开关已被设置为打开"), true); //#else //$$ context.getSource().sendSuccess(Component.literal("接收群内聊天消息开关已被设置为打开"), true); //#endif } else { //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("接收群内聊天消息开关已被设置为关闭"), true); + //$$ context.getSource().sendSuccess(()->Component.literal("接收群内聊天消息开关已被设置为关闭"), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent("接收群内聊天消息开关已被设置为关闭"), true); + context.getSource().sendSuccess(new TextComponent("接收群内聊天消息开关已被设置为关闭"), true); //#else //$$ context.getSource().sendSuccess(Component.literal("接收群内聊天消息开关已被设置为关闭"), true); //#endif @@ -68,17 +67,17 @@ public static int cmdExecute(CommandContext context) throws if (isEnabled) { ModConfig.INSTANCE.getStatus().setREnable(true); //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("接收群内命令消息开关已被设置为打开"), true); + //$$ context.getSource().sendSuccess(()->Component.literal("接收群内命令消息开关已被设置为打开"), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent("接收群内命令消息开关已被设置为打开"), true); + context.getSource().sendSuccess(new TextComponent("接收群内命令消息开关已被设置为打开"), true); //#else //$$ context.getSource().sendSuccess(Component.literal("接收群内命令消息开关已被设置为打开"), true); //#endif } else { //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("接收群内命令消息开关已被设置为关闭"), true); + //$$ context.getSource().sendSuccess(()->Component.literal("接收群内命令消息开关已被设置为关闭"), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent("接收群内命令消息开关已被设置为关闭"), true); + context.getSource().sendSuccess(new TextComponent("接收群内命令消息开关已被设置为关闭"), true); //#else //$$ context.getSource().sendSuccess(Component.literal("接收群内命令消息开关已被设置为关闭"), true); //#endif diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/command/ReloadConfigCmd.java b/fabric/src/main/java/cn/evole/mods/mcbot/command/ReloadConfigCmd.java index 0525b36e..b647fc40 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/command/ReloadConfigCmd.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/command/ReloadConfigCmd.java @@ -4,10 +4,9 @@ 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; -//#else -//$$ import net.minecraft.network.chat.TextComponent; +//#if MC <11900 +import net.minecraft.network.chat.TextComponent; //#endif /** * Description: @@ -21,25 +20,25 @@ public static int execute(CommandContext context) throws Com ModConfig.INSTANCE.reload(); if (ModConfig.INSTANCE == null) { //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("重载配置失败"), true); + //$$ context.getSource().sendSuccess(()->Component.literal("重载配置失败"), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent("重载配置失败"), true); + context.getSource().sendSuccess(new TextComponent("重载配置失败"), true); //#else //$$ context.getSource().sendSuccess(Component.literal("重载配置失败"), true); //#endif } //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("重载配置成功"), true); + //$$ context.getSource().sendSuccess(()->Component.literal("重载配置成功"), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent("重载配置成功"), true); + context.getSource().sendSuccess(new TextComponent("重载配置成功"), true); //#else //$$ context.getSource().sendSuccess(Component.literal("重载配置成功"), true); //#endif } catch (Exception e) { //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("重载配置失败"), true); + //$$ context.getSource().sendSuccess(()->Component.literal("重载配置失败"), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent("重载配置失败"), true); + context.getSource().sendSuccess(new TextComponent("重载配置失败"), true); //#else //$$ context.getSource().sendSuccess(Component.literal("重载配置失败"), true); //#endif diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/command/SendCommand.java b/fabric/src/main/java/cn/evole/mods/mcbot/command/SendCommand.java index d16ece1e..afcc01fb 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/command/SendCommand.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/command/SendCommand.java @@ -4,10 +4,9 @@ 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; -//#else -//$$ import net.minecraft.network.chat.TextComponent; +//#if MC <11900 +import net.minecraft.network.chat.TextComponent; //#endif @@ -20,17 +19,17 @@ public static int qqLeaveExecute(CommandContext context) thr if (isEnabled) { ModConfig.INSTANCE.getStatus().setSEnable(true); //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("发送离开QQ群的消息开关已被设置为打开"), true); + //$$ context.getSource().sendSuccess(()->Component.literal("发送离开QQ群的消息开关已被设置为打开"), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent("发送新人加入QQ群的消息开关已被设置为打开"), true); + context.getSource().sendSuccess(new TextComponent("发送新人加入QQ群的消息开关已被设置为打开"), true); //#else //$$ context.getSource().sendSuccess(Component.literal("发送新人加入QQ群的消息开关已被设置为打开"), true); //#endif } else { //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("发送离开QQ群的消息开关已被设置为关闭"), true); + //$$ context.getSource().sendSuccess(()->Component.literal("发送离开QQ群的消息开关已被设置为关闭"), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent("发送新人加入QQ群的消息开关已被设置为关闭"), true); + context.getSource().sendSuccess(new TextComponent("发送新人加入QQ群的消息开关已被设置为关闭"), true); //#else //$$ context.getSource().sendSuccess(Component.literal("发送新人加入QQ群的消息开关已被设置为关闭"), true); //#endif @@ -46,17 +45,17 @@ public static int qqWelcomeExecute(CommandContext context) t if (isEnabled) { ModConfig.INSTANCE.getStatus().setSEnable(true); //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("发送新人加入QQ群的消息开关已被设置为打开"), true); + //$$ context.getSource().sendSuccess(()->Component.literal("发送新人加入QQ群的消息开关已被设置为打开"), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent("发送新人加入QQ群的消息开关已被设置为打开"), true); + context.getSource().sendSuccess(new TextComponent("发送新人加入QQ群的消息开关已被设置为打开"), true); //#else //$$ context.getSource().sendSuccess(Component.literal("发送新人加入QQ群的消息开关已被设置为打开"), true); //#endif } else { //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("发送新人加入QQ群的消息开关已被设置为关闭"), true); + //$$ context.getSource().sendSuccess(()->Component.literal("发送新人加入QQ群的消息开关已被设置为关闭"), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent("发送新人加入QQ群的消息开关已被设置为关闭"), true); + context.getSource().sendSuccess(new TextComponent("发送新人加入QQ群的消息开关已被设置为关闭"), true); //#else //$$ context.getSource().sendSuccess(Component.literal("发送新人加入QQ群的消息开关已被设置为关闭"), true); //#endif @@ -70,17 +69,17 @@ public static int allExecute(CommandContext context) throws ModConfig.INSTANCE.getStatus().setSEnable(isEnabled); if (isEnabled) { //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("全局发送消息开关已被设置为打开"), true); + //$$ context.getSource().sendSuccess(()->Component.literal("全局发送消息开关已被设置为打开"), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent("全局发送消息开关已被设置为打开"), true); + context.getSource().sendSuccess(new TextComponent("全局发送消息开关已被设置为打开"), true); //#else //$$ context.getSource().sendSuccess(Component.literal("全局发送消息开关已被设置为打开"), true); //#endif } else { //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("全局发送消息开关已被设置为关闭"), true); + //$$ context.getSource().sendSuccess(()->Component.literal("全局发送消息开关已被设置为关闭"), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent("全局发送消息开关已被设置为关闭"), true); + context.getSource().sendSuccess(new TextComponent("全局发送消息开关已被设置为关闭"), true); //#else //$$ context.getSource().sendSuccess(Component.literal("全局发送消息开关已被设置为关闭"), true); //#endif @@ -95,17 +94,17 @@ public static int joinExecute(CommandContext context) throws if (isEnabled) { ModConfig.INSTANCE.getStatus().setSEnable(true); //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("发送玩家加入游戏消息开关已被设置为打开"), true); + //$$ context.getSource().sendSuccess(()->Component.literal("发送玩家加入游戏消息开关已被设置为打开"), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent("发送玩家加入游戏消息开关已被设置为打开"), true); + context.getSource().sendSuccess(new TextComponent("发送玩家加入游戏消息开关已被设置为打开"), true); //#else //$$ context.getSource().sendSuccess(Component.literal("发送玩家加入游戏消息开关已被设置为打开"), true); //#endif } else { //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("发送玩家加入游戏消息开关已被设置为关闭"), true); + //$$ context.getSource().sendSuccess(()->Component.literal("发送玩家加入游戏消息开关已被设置为关闭"), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent("发送玩家加入游戏消息开关已被设置为关闭"), true); + context.getSource().sendSuccess(new TextComponent("发送玩家加入游戏消息开关已被设置为关闭"), true); //#else //$$ context.getSource().sendSuccess(Component.literal("发送玩家加入游戏消息开关已被设置为关闭"), true); //#endif @@ -120,17 +119,17 @@ public static int leaveExecute(CommandContext context) throw if (isEnabled) { ModConfig.INSTANCE.getStatus().setSEnable(true); //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("发送玩家离开游戏消息开关已被设置为打开"), true); + //$$ context.getSource().sendSuccess(()->Component.literal("发送玩家离开游戏消息开关已被设置为打开"), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent("发送玩家离开游戏消息开关已被设置为打开"), true); + context.getSource().sendSuccess(new TextComponent("发送玩家离开游戏消息开关已被设置为打开"), true); //#else //$$ context.getSource().sendSuccess(Component.literal("发送玩家离开游戏消息开关已被设置为打开"), true); //#endif } else { //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("发送玩家离开游戏消息开关已被设置为关闭"), true); + //$$ context.getSource().sendSuccess(()->Component.literal("发送玩家离开游戏消息开关已被设置为关闭"), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent("发送玩家离开游戏消息开关已被设置为关闭"), true); + context.getSource().sendSuccess(new TextComponent("发送玩家离开游戏消息开关已被设置为关闭"), true); //#else //$$ context.getSource().sendSuccess(Component.literal("发送玩家离开游戏消息开关已被设置为关闭"), true); //#endif @@ -145,17 +144,17 @@ public static int deathExecute(CommandContext context) throw if (isEnabled) { ModConfig.INSTANCE.getStatus().setSEnable(true); //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("发送玩家死亡游戏消息开关已被设置为打开"), true); + //$$ context.getSource().sendSuccess(()->Component.literal("发送玩家死亡游戏消息开关已被设置为打开"), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent("发送玩家死亡游戏消息开关已被设置为打开"), true); + context.getSource().sendSuccess(new TextComponent("发送玩家死亡游戏消息开关已被设置为打开"), true); //#else //$$ context.getSource().sendSuccess(Component.literal("发送玩家死亡游戏消息开关已被设置为打开"), true); //#endif } else { //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("发送玩家死亡游戏消息开关已被设置为关闭"), true); + //$$ context.getSource().sendSuccess(()->Component.literal("发送玩家死亡游戏消息开关已被设置为关闭"), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent("发送玩家死亡游戏消息开关已被设置为关闭"), true); + context.getSource().sendSuccess(new TextComponent("发送玩家死亡游戏消息开关已被设置为关闭"), true); //#else //$$ context.getSource().sendSuccess(Component.literal("发送玩家死亡游戏消息开关已被设置为关闭"), true); //#endif @@ -170,17 +169,17 @@ public static int chatExecute(CommandContext context) throws if (isEnabled) { ModConfig.INSTANCE.getStatus().setSEnable(true); //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("发送玩家聊天游戏消息开关已被设置为打开"), true); + //$$ context.getSource().sendSuccess(()->Component.literal("发送玩家聊天游戏消息开关已被设置为打开"), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent("发送玩家聊天游戏消息开关已被设置为打开"), true); + context.getSource().sendSuccess(new TextComponent("发送玩家聊天游戏消息开关已被设置为打开"), true); //#else //$$ context.getSource().sendSuccess(Component.literal("发送玩家聊天游戏消息开关已被设置为打开"), true); //#endif } else { //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("发送玩家聊天游戏消息开关已被设置为关闭"), true); + //$$ context.getSource().sendSuccess(()->Component.literal("发送玩家聊天游戏消息开关已被设置为关闭"), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent("发送玩家聊天游戏消息开关已被设置为关闭"), true); + context.getSource().sendSuccess(new TextComponent("发送玩家聊天游戏消息开关已被设置为关闭"), true); //#else //$$ context.getSource().sendSuccess(Component.literal("发送玩家聊天游戏消息开关已被设置为关闭"), true); //#endif @@ -195,17 +194,17 @@ public static int achievementsExecute(CommandContext context if (isEnabled) { ModConfig.INSTANCE.getStatus().setSEnable(true); //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("发送玩家成就游戏消息开关已被设置为打开"), true); + //$$ context.getSource().sendSuccess(()->Component.literal("发送玩家成就游戏消息开关已被设置为打开"), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent("发送玩家成就游戏消息开关已被设置为打开"), true); + context.getSource().sendSuccess(new TextComponent("发送玩家成就游戏消息开关已被设置为打开"), true); //#else //$$ context.getSource().sendSuccess(Component.literal("发送玩家成就游戏消息开关已被设置为打开"), true); //#endif } else { //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal("发送玩家成就游戏消息开关已被设置为关闭"), true); + //$$ context.getSource().sendSuccess(()->Component.literal("发送玩家成就游戏消息开关已被设置为关闭"), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent("发送玩家成就游戏消息开关已被设置为关闭"), true); + context.getSource().sendSuccess(new TextComponent("发送玩家成就游戏消息开关已被设置为关闭"), true); //#else //$$ context.getSource().sendSuccess(Component.literal("发送玩家成就游戏消息开关已被设置为关闭"), true); //#endif diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/command/StatusCommand.java b/fabric/src/main/java/cn/evole/mods/mcbot/command/StatusCommand.java index fa94bee6..49d36222 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/command/StatusCommand.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/command/StatusCommand.java @@ -7,10 +7,9 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import lombok.val; import net.minecraft.commands.CommandSourceStack; -//#if MC >= 11900 import net.minecraft.network.chat.Component; -//#else -//$$ import net.minecraft.network.chat.TextComponent; +//#if MC <11900 +import net.minecraft.network.chat.TextComponent; //#endif public class StatusCommand { @@ -61,9 +60,9 @@ public static int execute(CommandContext context) throws Com + "发送群成员进群消息状态:" + sQqWelcomeEnabled + "\n" + "发送群成员退群消息状态:" + sQqLeaveEnabled + "\n"; //#if MC >= 12000 - context.getSource().sendSuccess(()->Component.literal(toSend), true); + //$$ context.getSource().sendSuccess(()->Component.literal(toSend), true); //#elseif MC < 11900 - //$$ context.getSource().sendSuccess(new TextComponent(toSend), true); + context.getSource().sendSuccess(new TextComponent(toSend), true); //#else //$$ context.getSource().sendSuccess(Component.literal(toSend), true); //#endif diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/init/config/BotConfig.java b/fabric/src/main/java/cn/evole/mods/mcbot/init/config/BotConfig.java index dec007c5..3e61caff 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/init/config/BotConfig.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/init/config/BotConfig.java @@ -1,9 +1,9 @@ package cn.evole.mods.mcbot.init.config; -import cn.evole.libs.tomlj.TomlTable; +import cn.evole.config.toml.AutoLoadTomlConfig; import lombok.Getter; import lombok.Setter; -import cn.evole.config.toml.AutoLoadTomlConfig; +import org.tomlj.TomlTable; /** * Name: McBot-fabric / BotConfig diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/init/config/CmdConfig.java b/fabric/src/main/java/cn/evole/mods/mcbot/init/config/CmdConfig.java index 14553071..e890080d 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/init/config/CmdConfig.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/init/config/CmdConfig.java @@ -1,10 +1,10 @@ package cn.evole.mods.mcbot.init.config; -import cn.evole.libs.tomlj.TomlTable; -import lombok.Getter; -import lombok.Setter; import cn.evole.config.toml.AutoLoadTomlConfig; import cn.evole.config.toml.annotation.TableField; +import lombok.Getter; +import lombok.Setter; +import org.tomlj.TomlTable; /** * Name: McBot-fabric / CmdConfig diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/init/config/CommonConfig.java b/fabric/src/main/java/cn/evole/mods/mcbot/init/config/CommonConfig.java index 1d44c1d5..4e3b561d 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/init/config/CommonConfig.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/init/config/CommonConfig.java @@ -1,12 +1,13 @@ package cn.evole.mods.mcbot.init.config; -import cn.evole.libs.tomlj.TomlTable; -import lombok.Getter; -import lombok.Setter; import cn.evole.config.toml.AutoLoadTomlConfig; import cn.evole.config.toml.annotation.TableField; +import lombok.Getter; +import lombok.Setter; +import org.tomlj.TomlTable; -import java.util.*; +import java.util.ArrayList; +import java.util.List; /** * Name: McBot-fabric / CommonConfig diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/init/config/ModConfig.java b/fabric/src/main/java/cn/evole/mods/mcbot/init/config/ModConfig.java index 17199dea..5a582e2a 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/init/config/ModConfig.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/init/config/ModConfig.java @@ -1,13 +1,13 @@ package cn.evole.mods.mcbot.init.config; -import cn.evole.libs.tomlj.TomlTable; -import cn.evole.mods.mcbot.McBot; -import lombok.Getter; -import lombok.Setter; 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.mods.mcbot.McBot; +import lombok.Getter; +import lombok.Setter; +import org.tomlj.TomlTable; /** * Description: diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/init/config/StatusConfig.java b/fabric/src/main/java/cn/evole/mods/mcbot/init/config/StatusConfig.java index 4de0f5ef..9908fed2 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/init/config/StatusConfig.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/init/config/StatusConfig.java @@ -1,10 +1,10 @@ package cn.evole.mods.mcbot.init.config; -import cn.evole.libs.tomlj.TomlTable; -import lombok.Getter; -import lombok.Setter; import cn.evole.config.toml.AutoLoadTomlConfig; import cn.evole.config.toml.annotation.TableField; +import lombok.Getter; +import lombok.Setter; +import org.tomlj.TomlTable; /** * Name: McBot-fabric / StatusConfig diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/init/event/IBotEvent.java b/fabric/src/main/java/cn/evole/mods/mcbot/init/event/IBotEvent.java index 51f94f95..ccea8c75 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/init/event/IBotEvent.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/init/event/IBotEvent.java @@ -12,7 +12,6 @@ import cn.evole.onebot.sdk.event.meta.LifecycleMetaEvent; import cn.evole.onebot.sdk.event.notice.group.GroupDecreaseNoticeEvent; import cn.evole.onebot.sdk.event.notice.group.GroupIncreaseNoticeEvent; -import cn.evole.onebot.sdk.util.BotUtils; import cn.evole.onebot.sdk.util.MsgUtils; import lombok.val; @@ -53,7 +52,7 @@ public void onMessage(GroupMessageEvent event) { else return; } Const.LOGGER.info(send); - var nick = McBot.bot.getGroupMemberInfo(event.getGroupId(), event.getUserId(), true); + val nick = McBot.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(); @@ -91,7 +90,7 @@ public void onMessage(GroupIncreaseNoticeEvent event) { 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(); + val msg = MsgUtils.builder().at(event.getUserId()).build() + "\n" + ModConfig.INSTANCE.getCmd().getWelcomeNotice(); Const.groupMsg(event.getGroupId(), msg); } } @@ -104,7 +103,7 @@ public void onMessage(GroupDecreaseNoticeEvent event) { && ModConfig.INSTANCE.getStatus().isSEnable() && ModConfig.INSTANCE.getStatus().isSQqLeaveEnable()) { - var msg = MsgUtils.builder().text(String.valueOf(event.getUserId())).build() + "\n" +ModConfig.INSTANCE.getCmd().getLeaveNotice(); + val msg = MsgUtils.builder().text(String.valueOf(event.getUserId())).build() + "\n" +ModConfig.INSTANCE.getCmd().getLeaveNotice(); Const.groupMsg(event.getGroupId(), msg); } } @@ -131,7 +130,7 @@ public void onMessage(GuildMessageEvent event) { send = split[1]; else return; } - var nick = McBot.bot.getGuildMemberProfile(event.getGuildId(), String.valueOf(event.getUserId())); + val nick = McBot.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(); @@ -172,13 +171,13 @@ public void onMessage(LifecycleMetaEvent event) { if (!event.getSubType().equals("connect")) return; if (!ModConfig.INSTANCE.getCommon().getGroupIdList().isEmpty() ) { - var msg = "▌ 群服互联已连接 ┈━═☆"; + val msg = "▌ 群服互联已连接 ┈━═☆"; Const.sendGroupMsg(msg); } if (!ModConfig.INSTANCE.getCommon().getChannelIdList().isEmpty() ) { - var msg = "▌ 群服互联已连接 ┈━═☆"; + val msg = "▌ 群服互联已连接 ┈━═☆"; Const.sendGuildMsg(msg); } } diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/init/event/IChatEvent.java b/fabric/src/main/java/cn/evole/mods/mcbot/init/event/IChatEvent.java index 825bc7dd..f486cabf 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/init/event/IChatEvent.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/init/event/IChatEvent.java @@ -14,37 +14,37 @@ public class IChatEvent { 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); - - } - + 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()) { + val 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 { + val 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/fabric/src/main/java/cn/evole/mods/mcbot/init/event/ICmdEvent.java b/fabric/src/main/java/cn/evole/mods/mcbot/init/event/ICmdEvent.java index 83076114..904972b3 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/init/event/ICmdEvent.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/init/event/ICmdEvent.java @@ -2,9 +2,12 @@ import cn.evole.mods.mcbot.command.*; import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.arguments.BoolArgumentType; import com.mojang.brigadier.arguments.LongArgumentType; import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; @@ -16,6 +19,14 @@ * Version: 1.0 */ public class ICmdEvent { + public static LiteralArgumentBuilder literal(String name) { + return LiteralArgumentBuilder.literal(name); + } + + public static RequiredArgumentBuilder argument(String arg, ArgumentType type) { + return RequiredArgumentBuilder.argument(arg, type); + } + public static void register(CommandDispatcher dispatcher){ dispatcher.register( Commands.literal("mcbot") diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/init/event/IPlayerEvent.java b/fabric/src/main/java/cn/evole/mods/mcbot/init/event/IPlayerEvent.java index 9cba7648..fa3c1d16 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/init/event/IPlayerEvent.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/init/event/IPlayerEvent.java @@ -1,13 +1,11 @@ package cn.evole.mods.mcbot.init.event; import cn.evole.mods.mcbot.Const; -import cn.evole.mods.mcbot.McBot; import cn.evole.mods.mcbot.init.config.ModConfig; import cn.evole.mods.mcbot.util.locale.I18n; -import cn.evole.onebot.sdk.util.BotUtils; +import lombok.val; import net.minecraft.advancements.Advancement; import net.minecraft.advancements.DisplayInfo; -import net.minecraft.advancements.FrameType; import net.minecraft.network.chat.Component; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.damagesource.DamageSource; @@ -27,45 +25,45 @@ public class IPlayerEvent { public static void loggedIn(Level world, Player player) { if (ModConfig.INSTANCE.getStatus().isSJoinEnable() && ModConfig.INSTANCE.getStatus().isSEnable()) { - var msg = player.getDisplayName().getString() + " 加入了服务器"; + val msg = player.getDisplayName().getString() + " 加入了服务器"; send(msg); } } public static void loggedOut(Level world, Player player) { if (ModConfig.INSTANCE.getStatus().isSLeaveEnable() && ModConfig.INSTANCE.getStatus().isSEnable()) { - var msg = player.getDisplayName().getString() + " 离开了服务器"; + val msg = player.getDisplayName().getString() + " 离开了服务器"; send(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 (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 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"; - 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 { - 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()); + 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) { + itemStack = ((LivingEntity)sourceEntity).getMainHandItem(); + } else { + itemStack = ItemStack.EMPTY; } - var msg = String.format(message, player.getDisplayName().getString()); - send(msg); + 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()); } + val msg = String.format(message, player.getDisplayName().getString()); + send(msg); + } } public static void advancement(Player player, Advancement advancement) { @@ -75,17 +73,17 @@ public static void advancement(Player player, Advancement advancement) { //$$ boolean displayExist = advancement.display().isPresent(); //#endif - if (ModConfig.INSTANCE.getStatus().isSAdvanceEnable() && displayExist && ModConfig.INSTANCE.getStatus().isSEnable()) { - //#if MC <= 12001 - DisplayInfo display = advancement.getDisplay(); - //#else - //$$ DisplayInfo display = advancement.display().get(); - //#endif + 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); - } + String message = I18n.get("mcbot.chat.type.advancement." + display.getFrame().getName(), player.getDisplayName().getString(), I18n.get(display.getTitle().getString())); + val msg = String.format(message, player.getDisplayName().getString()); + send(msg); + } } private static void send(String msg){ diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/init/event/ITickEvent.java b/fabric/src/main/java/cn/evole/mods/mcbot/init/event/ITickEvent.java index 951c504b..6220c766 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/init/event/ITickEvent.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/init/event/ITickEvent.java @@ -1,20 +1,16 @@ package cn.evole.mods.mcbot.init.event; -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 java.util.LinkedList; import java.util.Queue; - +import cn.evole.mods.mcbot.init.config.ModConfig; +import net.minecraft.network.chat.Component; +//#if MC < 11900 +import net.minecraft.network.chat.TextComponent; +//#endif //#if MC <= 11802 -//$$ import java.util.UUID; -//$$ import net.minecraft.network.chat.ChatType; -//$$ import net.minecraft.Util; +import net.minecraft.network.chat.ChatType; +import net.minecraft.Util; //#endif @@ -33,18 +29,17 @@ public static Queue getSendQueue() { public static void register(MinecraftServer server) { - 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 - } + String toSend = SEND_QUEUE.poll(); + if (ModConfig.INSTANCE != null + && server != null + && server.isDedicatedServer() + && toSend != null + ) { + //#if MC >= 11900 + //$$ server.getPlayerList().broadcastSystemMessage(Component.literal(toSend), false); + //#else + server.getPlayerList().broadcastMessage(new TextComponent(toSend), ChatType.SYSTEM, Util.NIL_UUID); + //#endif + } } } diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinLanguage.java b/fabric/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinLanguage.java index 9c3e9591..b7a21601 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinLanguage.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinLanguage.java @@ -1,9 +1,29 @@ -//#if MC >= 11900 package cn.evole.mods.mcbot.init.mixins; import net.minecraft.locale.Language; import org.spongepowered.asm.mixin.Mixin; +import cn.evole.mods.mcbot.Const; +import com.google.gson.Gson; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.locale.Language; +import net.minecraft.util.GsonHelper; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyVariable; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Optional; +import java.util.regex.Pattern; /** * Author cnlimiter * CreateTime 2023/5/19 0:53 @@ -12,5 +32,32 @@ */ @Mixin(Language.class) public abstract class MixinLanguage { + //#if MC >= 11800 + //$$ @Final @Shadow + //$$ private static Gson GSON; + //$$ @Final @Shadow + //$$ private static Pattern UNSUPPORTED_FORMAT_PATTERN; + //$$ @ModifyVariable(method = "loadDefault", at = @At("STORE"), ordinal = 0) + //$$ private static Map mapInjected(Map originalMap) { + //$$ LinkedHashMap map = new LinkedHashMap<>(originalMap); + //$$ FabricLoader.getInstance().getAllMods().forEach(modContainer -> { + //$$ Optional optional = modContainer.findPath("/assets/" + modContainer.getMetadata().getId() + "/lang/en_us.json"); + //$$ if (optional.isPresent()) { + //$$ try (InputStream inputStream = Files.newInputStream(optional.get())) { + //$$ JsonObject json = GSON.fromJson(new InputStreamReader(inputStream, StandardCharsets.UTF_8), JsonObject.class); + //$$ for (Map.Entry entry : json.entrySet()) { + //$$ String string = UNSUPPORTED_FORMAT_PATTERN.matcher(GsonHelper.convertToString(entry.getValue(), entry.getKey())).replaceAll("%$1s"); + //$$ if (!map.containsKey(entry.getKey())){//去重 + //$$ map.put(entry.getKey(), string); + //$$ } + //$$ } + //$$ } catch (Exception e) { + //$$ Const.LOGGER.error("Couldn't read strings from /assets/{}", modContainer.getMetadata().getId() + "/lang/en_us.json", e); + //$$ } + //$$ } + //$$ }); + //$$ return map; + //$$ } + //#endif + } -//#endif \ No newline at end of file diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinPlayerAdvancements.java b/fabric/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinPlayerAdvancements.java index d4bf4b16..d1860a4f 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinPlayerAdvancements.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinPlayerAdvancements.java @@ -1,7 +1,14 @@ package cn.evole.mods.mcbot.init.mixins; +import cn.evole.mods.mcbot.init.callbacks.IEvents; +import net.minecraft.advancements.Advancement; import net.minecraft.server.PlayerAdvancements; +import net.minecraft.server.level.ServerPlayer; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; /** * Author cnlimiter @@ -12,4 +19,17 @@ @Mixin(value = PlayerAdvancements.class, priority = 1001) public abstract class MixinPlayerAdvancements { + @Shadow + private ServerPlayer player; + //#if MC < 11900 + @Inject(method = "award", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;broadcastMessage(Lnet/minecraft/network/chat/Component;Lnet/minecraft/network/chat/ChatType;Ljava/util/UUID;)V", shift = At.Shift.AFTER)) + //#else + //$$ @Inject(method = "award", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;broadcastSystemMessage(Lnet/minecraft/network/chat/Component;Z)V", shift = At.Shift.AFTER)) + //#endif + public void PlayerAdvancements_award(Advancement advancement, String string, CallbackInfoReturnable cir) { + + ServerPlayer player = this.player; + + IEvents.PLAYER_ADVANCEMENT.invoker().onAdvancement(player, advancement); + } } diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinPlayerList.java b/fabric/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinPlayerList.java index c3cd8316..87749639 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinPlayerList.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinPlayerList.java @@ -9,6 +9,9 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +//#if MC >= 12002 +//$$ import net.minecraft.server.network.CommonListenerCookie; +//#endif /** * Author cnlimiter @@ -19,13 +22,23 @@ @Mixin(value = PlayerList.class, priority = 1001) public abstract class MixinPlayerList { + //#if MC < 12002 @Inject(method = "placeNewPlayer", at = @At(value = "TAIL")) public void PlayerList_placeNewPlayer(Connection connection, ServerPlayer player, CallbackInfo ci) { IEvents.PLAYER_LOGGED_IN.invoker().onPlayerLoggedIn(player.getCommandSenderWorld(), player); } - @Inject(method = "remove", at = @At(value = "HEAD")) public void PlayerList_remove(ServerPlayer player, CallbackInfo ci) { IEvents.PLAYER_LOGGED_OUT.invoker().onPlayerLoggedOut(player.getCommandSenderWorld(), player); } + //#else + //$$ @Inject(method = "placeNewPlayer", at = @At(value = "TAIL")) + //$$ public void PlayerList_placeNewPlayer(Connection connection, ServerPlayer player, CommonListenerCookie commonListenerCookie, CallbackInfo ci) { + //$$ IEvents.PLAYER_LOGGED_IN.invoker().onPlayerLoggedIn(player.getCommandSenderWorld(), player); + //$$ } + //$$ @Inject(method = "remove", at = @At(value = "HEAD")) + //$$ public void PlayerList_remove(ServerPlayer player, CallbackInfo ci) { + //$$ IEvents.PLAYER_LOGGED_OUT.invoker().onPlayerLoggedOut(player.getCommandSenderWorld(), player); + //$$ } + //#endif } \ No newline at end of file diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinServerGamePktImpl.java b/fabric/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinServerGamePktImpl.java index ee59caf7..fe77da25 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinServerGamePktImpl.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinServerGamePktImpl.java @@ -1,15 +1,17 @@ -//#if MC >= 11903 package cn.evole.mods.mcbot.init.mixins; -import cn.evole.mods.mcbot.init.callbacks.IEvents; -import net.minecraft.network.chat.PlayerChatMessage; -import net.minecraft.server.level.ServerPlayer; + import net.minecraft.server.network.ServerGamePacketListenerImpl; import org.spongepowered.asm.mixin.Mixin; +import cn.evole.mods.mcbot.init.callbacks.IEvents; +import net.minecraft.server.level.ServerPlayer; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - +import net.minecraft.server.network.TextFilter; +//#if MC >= 11902 +//$$ import net.minecraft.network.chat.PlayerChatMessage; +//#endif /** * Author cnlimiter * CreateTime 2023/5/19 0:54 @@ -19,13 +21,41 @@ @Mixin(value = ServerGamePacketListenerImpl.class, priority = 1001) public abstract class MixinServerGamePktImpl { + //#if MC < 11700 @Shadow public ServerPlayer player; - - @Inject(method = "broadcastChatMessage", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;broadcastChatMessage(Lnet/minecraft/network/chat/PlayerChatMessage;Lnet/minecraft/server/level/ServerPlayer;Lnet/minecraft/network/chat/ChatType$Bound;)V", shift = At.Shift.BEFORE)) - public void handleChat(PlayerChatMessage filteredText, CallbackInfo ci) { - String s1 = filteredText.decoratedContent().getString(); - IEvents.SERVER_CHAT.invoker().onChat(this.player, s1); + @Inject(method = "handleChat(Ljava/lang/String;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;broadcastMessage(Lnet/minecraft/network/chat/Component;Lnet/minecraft/network/chat/ChatType;Ljava/util/UUID;)V", shift = At.Shift.BEFORE)) + public void handleChat(String string, CallbackInfo ci) { + IEvents.SERVER_CHAT.invoker().onChat(this.player, string); } + //#elseif MC < 11900 + //$$ @Shadow + //$$ public ServerPlayer player; + //$$ @Inject(method = "handleChat(Lnet/minecraft/server/network/TextFilter$FilteredText;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;broadcastMessage(Lnet/minecraft/network/chat/Component;Ljava/util/function/Function;Lnet/minecraft/network/chat/ChatType;Ljava/util/UUID;)V", shift = At.Shift.BEFORE)) + //$$ public void handleChat(TextFilter.FilteredText filteredText, CallbackInfo ci) { + //$$ String s1 = filteredText.getRaw(); + //$$ IEvents.SERVER_CHAT.invoker().onChat(this.player, s1); + //$$ } + //#elseif MC < 11903 + //$$@Shadow + //$$public ServerPlayer player; + //$$@Inject(method = "broadcastChatMessage", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;broadcastChatMessage(Lnet/minecraft/network/chat/PlayerChatMessage;Lnet/minecraft/server/level/ServerPlayer;Lnet/minecraft/network/chat/ChatType$Bound;)V", shift = At.Shift.BEFORE)) + //$$public void handleChat(PlayerChatMessage filteredText, CallbackInfo ci) { + //$$ String s1 = filteredText.serverContent().getString(); + //$$ IEvents.SERVER_CHAT.invoker().onChat(this.player, s1); + //$$} + //#else + //$$@Shadow + //$$public ServerPlayer player; + //$$@Inject(method = "broadcastChatMessage", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;broadcastChatMessage(Lnet/minecraft/network/chat/PlayerChatMessage;Lnet/minecraft/server/level/ServerPlayer;Lnet/minecraft/network/chat/ChatType$Bound;)V", shift = At.Shift.BEFORE)) + //$$public void handleChat(PlayerChatMessage filteredText, CallbackInfo ci) { + //$$ String s1 = filteredText.decoratedContent().getString(); + //$$ IEvents.SERVER_CHAT.invoker().onChat(this.player, s1); + //$$} + //#endif + } -//#endif + + + + diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinSystemCmd.java b/fabric/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinSystemCmd.java index cdc4fd9c..bae6a49d 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinSystemCmd.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinSystemCmd.java @@ -1,16 +1,21 @@ -//#if MC >= 11903 +//#if MC < 11800 package cn.evole.mods.mcbot.init.mixins; import cn.evole.mods.mcbot.Const; import cn.evole.mods.mcbot.McBot; import cn.evole.mods.mcbot.init.config.ModConfig; import com.mojang.brigadier.CommandDispatcher; +import lombok.val; import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.Util; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; import net.minecraft.commands.arguments.MessageArgument; import net.minecraft.network.chat.ChatType; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TextComponent; import net.minecraft.server.players.PlayerList; +import net.minecraft.world.entity.Entity; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -30,26 +35,30 @@ public abstract class MixinSystemCmd { @Unique private static void say_register(CommandDispatcher dispatcher) { dispatcher.register((Commands.literal("say").requires((CommandSourceStack) -> CommandSourceStack.hasPermission(2))).then(Commands.argument("message", MessageArgument.message()).executes((commandContext) -> { - MessageArgument.resolveChatMessage(commandContext, "message", (playerChatMessage) -> { - CommandSourceStack CommandSourceStack = commandContext.getSource(); - PlayerList playerList = CommandSourceStack.getServer().getPlayerList(); - ///////////////////////// - if (FabricLoader.getInstance().isModLoaded("mcbot") - && ModConfig.INSTANCE != null - && ModConfig.INSTANCE.getStatus().isSChatEnable() - && ModConfig.INSTANCE.getStatus().isSEnable() - && ModConfig.INSTANCE.getCmd().isMcPrefixOn()) { - if (ModConfig.INSTANCE.getCommon().isGuildOn() && !ModConfig.INSTANCE.getCommon().getChannelIdList().isEmpty()) { - var msg = String.format("[" + ModConfig.INSTANCE.getCmd().getMcPrefix() + "] %s", new String(playerChatMessage.decoratedContent().getString().getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8)); - Const.sendGuildMsg(msg); - } else { - var msg = String.format("[" + ModConfig.INSTANCE.getCmd().getMcPrefix() + "] %s", new String(playerChatMessage.decoratedContent().getString().getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8)); - Const.sendGroupMsg(msg); - } + Component component = MessageArgument.getMessage(commandContext, "message"); + Component component2 = new TextComponent(String.format("[%s] %s", commandContext.getSource().getDisplayName().getString(), component.getString())); + Entity entity = commandContext.getSource().getEntity(); + + + if (FabricLoader.getInstance().isModLoaded("mcbot") + && ModConfig.INSTANCE != null + && ModConfig.INSTANCE.getStatus().isSChatEnable() + && ModConfig.INSTANCE.getStatus().isSEnable() + && ModConfig.INSTANCE.getCmd().isMcPrefixOn()) { + if (ModConfig.INSTANCE.getCommon().isGuildOn() && !ModConfig.INSTANCE.getCommon().getChannelIdList().isEmpty()) { + val msg = String.format("[" + ModConfig.INSTANCE.getCmd().getMcPrefix() + "] %s", new String(component.getString().getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8)); + Const.sendGuildMsg(msg); + } else { + val msg = String.format("[" + ModConfig.INSTANCE.getCmd().getMcPrefix() + "] %s", new String(component.getString().getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8)); + Const.sendGroupMsg(msg); } - ///////////////////////// - playerList.broadcastChatMessage(playerChatMessage, CommandSourceStack, ChatType.bind(ChatType.SAY_COMMAND, CommandSourceStack)); - }); + } + if (entity != null) { + commandContext.getSource().getServer().getPlayerList().broadcastMessage(component2, ChatType.SYSTEM, Util.NIL_UUID); + } else { + commandContext.getSource().getServer().getPlayerList().broadcastMessage(component2, ChatType.SYSTEM, Util.NIL_UUID); + } + return 1; }))); } @@ -59,4 +68,4 @@ private void sayRedirect(CommandDispatcher dispatcher) { say_register(dispatcher); } } -//#endif \ No newline at end of file +//#endif diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/util/MessageThread.java b/fabric/src/main/java/cn/evole/mods/mcbot/util/MessageThread.java new file mode 100644 index 00000000..96943c6d --- /dev/null +++ b/fabric/src/main/java/cn/evole/mods/mcbot/util/MessageThread.java @@ -0,0 +1,64 @@ +package cn.evole.mods.mcbot.util; + +import cn.evole.mods.mcbot.Const; +import cn.evole.mods.mcbot.McBot; +import com.google.gson.JsonArray; + +/** + * @Project: McBot-fabric + * @Author: xia-mc + * @CreateTime: 2024/2/12 16:11 + * @Description: + */ +public class MessageThread extends Thread { + private long groupIDInt; + private String guildIDString; + private String messageString; + private JsonArray messageArray; + private boolean autoEscape; + private String channelIDString; + private final short mode; + + public MessageThread(long groupId, String msg, boolean autoEscape) { + this.mode = 0; + this.groupIDInt = groupId; + this.messageString = msg; + this.autoEscape = autoEscape; + } + + public MessageThread(long groupId, JsonArray msg, boolean autoEscape) { + this.mode = 1; + this.groupIDInt = groupId; + this.messageArray = msg; + this.autoEscape = autoEscape; + } + + public MessageThread(String guildID, String channelID, String message) { + this.mode = 2; + this.guildIDString = guildID; + this.channelIDString = channelID; + this.messageString = message; + } + + public MessageThread(String guildID, String channelID, JsonArray message) { + this.mode = 3; + this.guildIDString = guildID; + this.channelIDString = channelID; + this.messageArray = message; + } + + public void run() { + switch (mode) { + case 0 :{McBot.bot.sendGroupMsg(groupIDInt, messageString, autoEscape); break;} + case 1 :{McBot.bot.sendGroupMsg(groupIDInt, messageArray, autoEscape); break;} + case 2 :{McBot.bot.sendGuildMsg(guildIDString, channelIDString, messageString); break;} + case 3 :{McBot.bot.sendGuildMsg(guildIDString, channelIDString, messageArray); break;} + } + } + + public void start() { + Const.LOGGER.info(String.format("转发游戏消息: %s", messageString != null ? messageString : messageArray)); + Thread thread = new Thread(this, "MessageThread"); + thread.start(); + } +} diff --git a/fabric/versions/1.14.4/gradle.properties b/fabric/versions/1.14.4/gradle.properties deleted file mode 100644 index d60e69bf..00000000 --- a/fabric/versions/1.14.4/gradle.properties +++ /dev/null @@ -1,10 +0,0 @@ -# Fabric Properties -# check these on https://fabricmc.net/develop -minecraft_version=1.14.4 -loader_version=0.14.21 - -# Fabric Mod Metadata -minecraft_dependency=1.14.x - -# Dependencies -fabric_version=0.28.5+1.14 \ No newline at end of file diff --git a/fabric/versions/1.14.4/src/test/java/Test.java b/fabric/versions/1.14.4/src/test/java/Test.java deleted file mode 100644 index e91337df..00000000 --- a/fabric/versions/1.14.4/src/test/java/Test.java +++ /dev/null @@ -1,20 +0,0 @@ -import net.minecraft.locale.Language; -import net.minecraft.network.chat.ClickEvent; -import net.minecraft.network.chat.Style; -import net.minecraft.server.MinecraftServer; -import net.minecraft.world.level.dimension.DimensionType; - -/** - * Author cnlimiter - * CreateTime 2023/5/19 23:21 - * Name Test - * Description - */ - -public class Test { - public void test(){ - MinecraftServer server; - //Style -// Language.getInstance().getElement() - } -} diff --git a/fabric/versions/1.15.2/gradle.properties b/fabric/versions/1.15.2/gradle.properties deleted file mode 100644 index 22e4db6c..00000000 --- a/fabric/versions/1.15.2/gradle.properties +++ /dev/null @@ -1,10 +0,0 @@ -# Fabric Properties -# check these on https://fabricmc.net/develop -minecraft_version=1.15.2 -loader_version=0.14.21 - -# Fabric Mod Metadata -minecraft_dependency=1.15.x - -# Dependencies -fabric_version=0.28.5+1.15 \ No newline at end of file diff --git a/fabric/versions/1.15.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinLanguage.java b/fabric/versions/1.15.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinLanguage.java deleted file mode 100644 index 3efc0ad9..00000000 --- a/fabric/versions/1.15.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinLanguage.java +++ /dev/null @@ -1,68 +0,0 @@ -//#if MC >= 11400 -package cn.evole.mods.mcbot.init.mixins; - -import com.google.gson.Gson; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.locale.Language; -import net.minecraft.util.GsonHelper; -import org.apache.logging.log4j.Logger; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import java.io.InputStream; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Map; -import java.util.Optional; -import java.util.regex.Pattern; - -/** - * Author cnlimiter - * CreateTime 2023/5/19 0:53 - * Name MixinLanguage - * Description - */ -@Mixin(Language.class) -public abstract class MixinLanguage { - - @Final - @Shadow - private static Logger LOGGER; - - @Final - @Shadow - private static Pattern UNSUPPORTED_FORMAT_PATTERN; - - @Final - @Shadow - private Map storage; - - @Inject(method = "", at = @At(value = "RETURN")) - private void Language(CallbackInfo ci) { - FabricLoader.getInstance().getAllMods().forEach(modContainer -> { - Optional optional = modContainer.findPath("/assets/" + modContainer.getMetadata().getId() + "/lang/en_us.json"); - if (optional.isPresent()) { - try (InputStream inputStream = Files.newInputStream(optional.get())) { - JsonObject json = new Gson().fromJson(new InputStreamReader(inputStream, StandardCharsets.UTF_8), JsonObject.class); - for (Map.Entry entry : json.entrySet()) { - String string = UNSUPPORTED_FORMAT_PATTERN.matcher(GsonHelper.convertToString(entry.getValue(), entry.getKey())).replaceAll("%$1s"); - if (!storage.containsKey(entry.getKey())){ - storage.put(entry.getKey(), string); - } - } - } catch (Exception e) { - LOGGER.error("Couldn't read strings from /assets/{}", modContainer.getMetadata().getId() + "/lang/en_us.json", e); - } - } - }); - } -} -//#endif \ No newline at end of file diff --git a/fabric/versions/1.15.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinPlayerAdvancements.java b/fabric/versions/1.15.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinPlayerAdvancements.java deleted file mode 100644 index d39bf3a3..00000000 --- a/fabric/versions/1.15.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinPlayerAdvancements.java +++ /dev/null @@ -1,35 +0,0 @@ -//#if MC >= 11400 -package cn.evole.mods.mcbot.init.mixins; -import cn.evole.mods.mcbot.init.callbacks.IEvents; -import net.minecraft.advancements.Advancement; -import net.minecraft.server.PlayerAdvancements; -import net.minecraft.server.level.ServerPlayer; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -/** - * Author cnlimiter - * CreateTime 2023/5/19 0:53 - * Name MixinPlayerAdvancements - * Description - */ - -@Mixin(value = PlayerAdvancements.class, priority = 1001) -public abstract class MixinPlayerAdvancements { - - @Shadow - private ServerPlayer player; - - @Inject(method = "award", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;broadcastMessage(Lnet/minecraft/network/chat/Component;)V", shift = At.Shift.AFTER)) - public void PlayerAdvancements_award(Advancement advancement, String string, CallbackInfoReturnable cir) { - - ServerPlayer player = this.player; - - IEvents.PLAYER_ADVANCEMENT.invoker().onAdvancement(player, advancement); - } - -} -//#endif \ No newline at end of file diff --git a/fabric/versions/1.15.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinServerGamePktImpl.java b/fabric/versions/1.15.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinServerGamePktImpl.java deleted file mode 100644 index 9be5d6d7..00000000 --- a/fabric/versions/1.15.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinServerGamePktImpl.java +++ /dev/null @@ -1,30 +0,0 @@ -//#if MC >= 11400 -package cn.evole.mods.mcbot.init.mixins; -import cn.evole.mods.mcbot.init.callbacks.IEvents; -import net.minecraft.network.protocol.game.ServerboundChatPacket; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.server.network.ServerGamePacketListenerImpl; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -/** - * Author cnlimiter - * CreateTime 2023/5/19 0:54 - * Name MixinServerGamePktImpl - * Description - */ - -@Mixin(value = ServerGamePacketListenerImpl.class, priority = 1001) -public abstract class MixinServerGamePktImpl { - @Shadow - public ServerPlayer player; - - @Inject(method = "handleChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;broadcastMessage(Lnet/minecraft/network/chat/Component;Z)V", shift = At.Shift.BEFORE)) - public void handleChat(ServerboundChatPacket serverboundChatPacket, CallbackInfo ci) { - IEvents.SERVER_CHAT.invoker().onChat(this.player, serverboundChatPacket.getMessage()); - } -} -//#endif diff --git a/fabric/versions/1.16.5/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinServerGamePktImpl.java b/fabric/versions/1.16.5/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinServerGamePktImpl.java deleted file mode 100644 index 1a1d3df8..00000000 --- a/fabric/versions/1.16.5/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinServerGamePktImpl.java +++ /dev/null @@ -1,29 +0,0 @@ -//#if MC >= 11600 -package cn.evole.mods.mcbot.init.mixins; -import cn.evole.mods.mcbot.init.callbacks.IEvents; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.server.network.ServerGamePacketListenerImpl; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -/** - * Author cnlimiter - * CreateTime 2023/5/19 0:54 - * Name MixinServerGamePktImpl - * Description - */ - -@Mixin(value = ServerGamePacketListenerImpl.class, priority = 1001) -public abstract class MixinServerGamePktImpl { - @Shadow - public ServerPlayer player; - - @Inject(method = "handleChat(Ljava/lang/String;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;broadcastMessage(Lnet/minecraft/network/chat/Component;Lnet/minecraft/network/chat/ChatType;Ljava/util/UUID;)V", shift = At.Shift.BEFORE)) - public void handleChat(String string, CallbackInfo ci) { - IEvents.SERVER_CHAT.invoker().onChat(this.player, string); - } -} -//#endif diff --git a/fabric/versions/1.17.1/gradle.properties b/fabric/versions/1.17.1/gradle.properties deleted file mode 100644 index 4acfe50d..00000000 --- a/fabric/versions/1.17.1/gradle.properties +++ /dev/null @@ -1,10 +0,0 @@ -# Fabric Properties -# check these on https://fabricmc.net/develop -minecraft_version=1.17.1 -loader_version=0.14.21 - -# Fabric Mod Metadata -minecraft_dependency=1.17.x - -# Dependencies -fabric_version=0.46.1+1.17 \ No newline at end of file diff --git a/fabric/versions/1.17.1/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinServerGamePktImpl.java b/fabric/versions/1.17.1/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinServerGamePktImpl.java deleted file mode 100644 index 8ff4ad29..00000000 --- a/fabric/versions/1.17.1/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinServerGamePktImpl.java +++ /dev/null @@ -1,31 +0,0 @@ -//#if MC >= 11700 -package cn.evole.mods.mcbot.init.mixins; -import cn.evole.mods.mcbot.init.callbacks.IEvents; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.server.network.ServerGamePacketListenerImpl; -import net.minecraft.server.network.TextFilter; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -/** - * Author cnlimiter - * CreateTime 2023/5/19 0:54 - * Name MixinServerGamePktImpl - * Description - */ - -@Mixin(value = ServerGamePacketListenerImpl.class, priority = 1001) -public abstract class MixinServerGamePktImpl { - @Shadow - public ServerPlayer player; - - @Inject(method = "handleChat(Lnet/minecraft/server/network/TextFilter$FilteredText;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;broadcastMessage(Lnet/minecraft/network/chat/Component;Ljava/util/function/Function;Lnet/minecraft/network/chat/ChatType;Ljava/util/UUID;)V", shift = At.Shift.BEFORE)) - public void handleChat(TextFilter.FilteredText filteredText, CallbackInfo ci) { - String s1 = filteredText.getRaw(); - IEvents.SERVER_CHAT.invoker().onChat(this.player, s1); - } -} -//#endif diff --git a/fabric/versions/1.17.1/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinSystemCmd.java b/fabric/versions/1.17.1/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinSystemCmd.java deleted file mode 100644 index ebdce1a5..00000000 --- a/fabric/versions/1.17.1/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinSystemCmd.java +++ /dev/null @@ -1,68 +0,0 @@ -//#if MC >= 11600 -package cn.evole.mods.mcbot.init.mixins; - -import cn.evole.mods.mcbot.Const; -import cn.evole.mods.mcbot.McBot; -import cn.evole.mods.mcbot.init.config.ModConfig; -import com.mojang.brigadier.CommandDispatcher; -import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.Util; -import net.minecraft.commands.CommandSourceStack; -import net.minecraft.commands.Commands; -import net.minecraft.commands.arguments.MessageArgument; -import net.minecraft.network.chat.ChatType; -import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.TextComponent; -import net.minecraft.world.entity.Entity; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -import java.nio.charset.StandardCharsets; - -/** - * Author cnlimiter - * CreateTime 2023/5/19 0:54 - * Name MixinSystemCmd - * Description - */ -@Mixin(value = Commands.class) -public abstract class MixinSystemCmd { - @Unique - private static void say_register(CommandDispatcher dispatcher) { - dispatcher.register((Commands.literal("say").requires((CommandSourceStack) -> CommandSourceStack.hasPermission(2))).then(Commands.argument("message", MessageArgument.message()).executes((commandContext) -> { - Component component = MessageArgument.getMessage(commandContext, "message"); - Component component2 = new TextComponent(String.format("[%s] %s", commandContext.getSource().getDisplayName().getString(), component.getString())); - Entity entity = commandContext.getSource().getEntity(); - - - if (FabricLoader.getInstance().isModLoaded("mcbot") - && ModConfig.INSTANCE != null - && ModConfig.INSTANCE.getStatus().isSChatEnable() - && ModConfig.INSTANCE.getStatus().isSEnable() - && ModConfig.INSTANCE.getCmd().isMcPrefixOn()) { - if (ModConfig.INSTANCE.getCommon().isGuildOn() && !ModConfig.INSTANCE.getCommon().getChannelIdList().isEmpty()) { - var msg = String.format("[" + ModConfig.INSTANCE.getCmd().getMcPrefix() + "] %s", new String(component.getString().getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8)); - Const.sendGuildMsg(msg); - } else { - var msg = String.format("[" + ModConfig.INSTANCE.getCmd().getMcPrefix() + "] %s", new String(component.getString().getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8)); - Const.sendGroupMsg(msg); - } - } - if (entity != null) { - commandContext.getSource().getServer().getPlayerList().broadcastMessage(component2, ChatType.CHAT, entity.getUUID()); - } else { - commandContext.getSource().getServer().getPlayerList().broadcastMessage(component2, ChatType.SYSTEM, Util.NIL_UUID); - } - - return 1; - }))); - } - - @Redirect(method = "", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/commands/SayCommand;register(Lcom/mojang/brigadier/CommandDispatcher;)V")) - private void sayRedirect(CommandDispatcher dispatcher) { - say_register(dispatcher); - } -} -//#endif diff --git a/fabric/versions/1.18.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinLanguage.java b/fabric/versions/1.18.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinLanguage.java deleted file mode 100644 index 0728fc0c..00000000 --- a/fabric/versions/1.18.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinLanguage.java +++ /dev/null @@ -1,70 +0,0 @@ -//#if MC >= 11600 -package cn.evole.mods.mcbot.init.mixins; - -import cn.evole.mods.mcbot.Const; -import com.google.gson.Gson; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.locale.Language; -import net.minecraft.util.GsonHelper; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.ModifyVariable; - -import java.io.InputStream; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Optional; -import java.util.regex.Pattern; - - -/** - * @author Xujiayao - */ -@Mixin(Language.class) -public abstract class MixinLanguage { - - @Final - @Shadow - private static Gson GSON; - - @Final - @Shadow - private static Pattern UNSUPPORTED_FORMAT_PATTERN; - - - @ModifyVariable(method = "loadDefault", at = @At("STORE"), ordinal = 0) - private static Map mapInjected(Map originalMap) { - - LinkedHashMap map = new LinkedHashMap<>(originalMap); - - - FabricLoader.getInstance().getAllMods().forEach(modContainer -> { - Optional optional = modContainer.findPath("/assets/" + modContainer.getMetadata().getId() + "/lang/en_us.json"); - - if (optional.isPresent()) { - try (InputStream inputStream = Files.newInputStream(optional.get())) { - JsonObject json = GSON.fromJson(new InputStreamReader(inputStream, StandardCharsets.UTF_8), JsonObject.class); - for (Map.Entry entry : json.entrySet()) { - String string = UNSUPPORTED_FORMAT_PATTERN.matcher(GsonHelper.convertToString(entry.getValue(), entry.getKey())).replaceAll("%$1s"); - if (!map.containsKey(entry.getKey())){//去重 - map.put(entry.getKey(), string); - } - } - } catch (Exception e) { - Const.LOGGER.error("Couldn't read strings from /assets/{}", modContainer.getMetadata().getId() + "/lang/en_us.json", e); - } - } - }); - - return map; - } -} -//#endif \ No newline at end of file diff --git a/fabric/versions/1.18.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinPlayerAdvancements.java b/fabric/versions/1.18.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinPlayerAdvancements.java deleted file mode 100644 index f5ee44c6..00000000 --- a/fabric/versions/1.18.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinPlayerAdvancements.java +++ /dev/null @@ -1,35 +0,0 @@ -//#if MC >= 11600 -package cn.evole.mods.mcbot.init.mixins; -import cn.evole.mods.mcbot.init.callbacks.IEvents; -import net.minecraft.advancements.Advancement; -import net.minecraft.server.PlayerAdvancements; -import net.minecraft.server.level.ServerPlayer; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -/** - * Author cnlimiter - * CreateTime 2023/5/19 0:53 - * Name MixinPlayerAdvancements - * Description - */ - -@Mixin(value = PlayerAdvancements.class, priority = 1001) -public abstract class MixinPlayerAdvancements { - - @Shadow - private ServerPlayer player; - - @Inject(method = "award", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;broadcastMessage(Lnet/minecraft/network/chat/Component;Lnet/minecraft/network/chat/ChatType;Ljava/util/UUID;)V", shift = At.Shift.AFTER)) - public void PlayerAdvancements_award(Advancement advancement, String string, CallbackInfoReturnable cir) { - - ServerPlayer player = this.player; - - IEvents.PLAYER_ADVANCEMENT.invoker().onAdvancement(player, advancement); - } - -} -//#endif \ No newline at end of file diff --git a/fabric/versions/1.18.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinServerGamePktImpl.java b/fabric/versions/1.18.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinServerGamePktImpl.java deleted file mode 100644 index fde07e40..00000000 --- a/fabric/versions/1.18.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinServerGamePktImpl.java +++ /dev/null @@ -1,31 +0,0 @@ -//#if MC >= 11800 -package cn.evole.mods.mcbot.init.mixins; -import cn.evole.mods.mcbot.init.callbacks.IEvents; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.server.network.ServerGamePacketListenerImpl; -import net.minecraft.server.network.TextFilter; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -/** - * Author cnlimiter - * CreateTime 2023/5/19 0:54 - * Name MixinServerGamePktImpl - * Description - */ - -@Mixin(value = ServerGamePacketListenerImpl.class, priority = 1001) -public abstract class MixinServerGamePktImpl { - @Shadow - public ServerPlayer player; - - @Inject(method = "handleChat(Lnet/minecraft/server/network/TextFilter$FilteredText;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;broadcastMessage(Lnet/minecraft/network/chat/Component;Ljava/util/function/Function;Lnet/minecraft/network/chat/ChatType;Ljava/util/UUID;)V", shift = At.Shift.BEFORE)) - public void handleChat(TextFilter.FilteredText filteredText, CallbackInfo ci) { - String s1 = filteredText.getRaw(); - IEvents.SERVER_CHAT.invoker().onChat(this.player, s1); - } -} -//#endif diff --git a/fabric/versions/1.18.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinSystemCmd.java b/fabric/versions/1.18.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinSystemCmd.java index 86b5a514..27f062be 100644 --- a/fabric/versions/1.18.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinSystemCmd.java +++ b/fabric/versions/1.18.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinSystemCmd.java @@ -1,10 +1,11 @@ -//#if MC >= 11800 +//#if MC >= 11600 package cn.evole.mods.mcbot.init.mixins; import cn.evole.mods.mcbot.Const; import cn.evole.mods.mcbot.McBot; import cn.evole.mods.mcbot.init.config.ModConfig; import com.mojang.brigadier.CommandDispatcher; +import lombok.val; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.Util; import net.minecraft.commands.CommandSourceStack; @@ -44,10 +45,10 @@ private static void say_register(CommandDispatcher dispatche && ModConfig.INSTANCE.getStatus().isSEnable() && ModConfig.INSTANCE.getCmd().isMcPrefixOn()) { if (ModConfig.INSTANCE.getCommon().isGuildOn() && !ModConfig.INSTANCE.getCommon().getChannelIdList().isEmpty()) { - var msg = String.format("[" + ModConfig.INSTANCE.getCmd().getMcPrefix() + "] %s", new String(component.getString().getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8)); + val msg = String.format("[" + ModConfig.INSTANCE.getCmd().getMcPrefix() + "] %s", new String(component.getString().getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8)); Const.sendGuildMsg(msg); } else { - var msg = String.format("[" + ModConfig.INSTANCE.getCmd().getMcPrefix() + "] %s", new String(component.getString().getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8)); + val msg = String.format("[" + ModConfig.INSTANCE.getCmd().getMcPrefix() + "] %s", new String(component.getString().getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8)); Const.sendGroupMsg(msg); } } diff --git a/fabric/versions/1.19.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinPlayerAdvancements.java b/fabric/versions/1.19.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinPlayerAdvancements.java deleted file mode 100644 index 99971291..00000000 --- a/fabric/versions/1.19.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinPlayerAdvancements.java +++ /dev/null @@ -1,36 +0,0 @@ -//#if MC >= 11900 -package cn.evole.mods.mcbot.init.mixins; - -import cn.evole.mods.mcbot.init.callbacks.IEvents; -import net.minecraft.advancements.Advancement; -import net.minecraft.server.PlayerAdvancements; -import net.minecraft.server.level.ServerPlayer; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -/** - * Author cnlimiter - * CreateTime 2023/5/19 0:53 - * Name MixinPlayerAdvancements - * Description - */ - -@Mixin(value = PlayerAdvancements.class, priority = 1001) -public abstract class MixinPlayerAdvancements { - - @Shadow - private ServerPlayer player; - - @Inject(method = "award", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;broadcastSystemMessage(Lnet/minecraft/network/chat/Component;Z)V", shift = At.Shift.AFTER)) - public void PlayerAdvancements_award(Advancement advancement, String string, CallbackInfoReturnable cir) { - - ServerPlayer player = this.player; - - IEvents.PLAYER_ADVANCEMENT.invoker().onAdvancement(player, advancement); - } - -} -//#endif \ No newline at end of file diff --git a/fabric/versions/1.19.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinServerGamePktImpl.java b/fabric/versions/1.19.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinServerGamePktImpl.java deleted file mode 100644 index e6e34188..00000000 --- a/fabric/versions/1.19.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinServerGamePktImpl.java +++ /dev/null @@ -1,31 +0,0 @@ -//#if MC >= 11900 -package cn.evole.mods.mcbot.init.mixins; -import cn.evole.mods.mcbot.init.callbacks.IEvents; -import net.minecraft.network.chat.PlayerChatMessage; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.server.network.ServerGamePacketListenerImpl; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -/** - * Author cnlimiter - * CreateTime 2023/5/19 0:54 - * Name MixinServerGamePktImpl - * Description - */ - -@Mixin(value = ServerGamePacketListenerImpl.class, priority = 1001) -public abstract class MixinServerGamePktImpl { - @Shadow - public ServerPlayer player; - - @Inject(method = "broadcastChatMessage", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;broadcastChatMessage(Lnet/minecraft/network/chat/PlayerChatMessage;Lnet/minecraft/server/level/ServerPlayer;Lnet/minecraft/network/chat/ChatType$Bound;)V", shift = At.Shift.BEFORE)) - public void handleChat(PlayerChatMessage filteredText, CallbackInfo ci) { - String s1 = filteredText.serverContent().getString(); - IEvents.SERVER_CHAT.invoker().onChat(this.player, s1); - } -} -//#endif diff --git a/fabric/versions/1.19.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinSystemCmd.java b/fabric/versions/1.19.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinSystemCmd.java index 2c57fa4d..cfefcd4d 100644 --- a/fabric/versions/1.19.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinSystemCmd.java +++ b/fabric/versions/1.19.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinSystemCmd.java @@ -5,6 +5,7 @@ import cn.evole.mods.mcbot.McBot; import cn.evole.mods.mcbot.init.config.ModConfig; import com.mojang.brigadier.CommandDispatcher; +import lombok.val; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; @@ -40,10 +41,10 @@ private static void say_register(CommandDispatcher dispatche && ModConfig.INSTANCE.getStatus().isSEnable() && ModConfig.INSTANCE.getCmd().isMcPrefixOn()) { if (ModConfig.INSTANCE.getCommon().isGuildOn() && !ModConfig.INSTANCE.getCommon().getChannelIdList().isEmpty()) { - var msg = String.format("[" + ModConfig.INSTANCE.getCmd().getMcPrefix() + "] %s", new String(playerChatMessage.serverContent().getString().getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8)); + val msg = String.format("[" + ModConfig.INSTANCE.getCmd().getMcPrefix() + "] %s", new String(playerChatMessage.serverContent().getString().getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8)); Const.sendGuildMsg(msg); } else { - var msg = String.format("[" + ModConfig.INSTANCE.getCmd().getMcPrefix() + "] %s", new String(playerChatMessage.serverContent().getString().getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8)); + val msg = String.format("[" + ModConfig.INSTANCE.getCmd().getMcPrefix() + "] %s", new String(playerChatMessage.serverContent().getString().getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8)); Const.sendGroupMsg(msg); } } diff --git a/fabric/versions/1.15.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinSystemCmd.java b/fabric/versions/1.19.3/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinSystemCmd.java similarity index 53% rename from fabric/versions/1.15.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinSystemCmd.java rename to fabric/versions/1.19.3/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinSystemCmd.java index effb1c6b..a4b10c6e 100644 --- a/fabric/versions/1.15.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinSystemCmd.java +++ b/fabric/versions/1.19.3/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinSystemCmd.java @@ -1,17 +1,16 @@ -//#if MC >= 11400 +//#if MC >= 11903 package cn.evole.mods.mcbot.init.mixins; import cn.evole.mods.mcbot.Const; -import cn.evole.mods.mcbot.McBot; import cn.evole.mods.mcbot.init.config.ModConfig; import com.mojang.brigadier.CommandDispatcher; +import lombok.val; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; import net.minecraft.commands.arguments.MessageArgument; -import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.TextComponent; -import net.minecraft.world.entity.Entity; +import net.minecraft.network.chat.ChatType; +import net.minecraft.server.players.PlayerList; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -30,30 +29,26 @@ public abstract class MixinSystemCmd { @Unique private static void say_register(CommandDispatcher dispatcher) { dispatcher.register((Commands.literal("say").requires((CommandSourceStack) -> CommandSourceStack.hasPermission(2))).then(Commands.argument("message", MessageArgument.message()).executes((commandContext) -> { - Component component = MessageArgument.getMessage(commandContext, "message"); - Component component2 = new TextComponent(String.format("[%s] %s", commandContext.getSource().getDisplayName().getString(), component.getString())); - Entity entity = commandContext.getSource().getEntity(); - - - if (FabricLoader.getInstance().isModLoaded("mcbot") + MessageArgument.resolveChatMessage(commandContext, "message", (playerChatMessage) -> { + CommandSourceStack CommandSourceStack = commandContext.getSource(); + PlayerList playerList = CommandSourceStack.getServer().getPlayerList(); + ///////////////////////// + if (FabricLoader.getInstance().isModLoaded("mcbot") && ModConfig.INSTANCE != null && ModConfig.INSTANCE.getStatus().isSChatEnable() && ModConfig.INSTANCE.getStatus().isSEnable() && ModConfig.INSTANCE.getCmd().isMcPrefixOn()) { - if (ModConfig.INSTANCE.getCommon().isGuildOn() && !ModConfig.INSTANCE.getCommon().getChannelIdList().isEmpty()) { - var msg = String.format("[" + ModConfig.INSTANCE.getCmd().getMcPrefix() + "] %s", new String(component.getString().getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8)); - Const.sendGuildMsg(msg); - } else { - var msg = String.format("[" + ModConfig.INSTANCE.getCmd().getMcPrefix() + "] %s", new String(component.getString().getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8)); - Const.sendGroupMsg(msg); + if (ModConfig.INSTANCE.getCommon().isGuildOn() && !ModConfig.INSTANCE.getCommon().getChannelIdList().isEmpty()) { + val msg = String.format("[" + ModConfig.INSTANCE.getCmd().getMcPrefix() + "] %s", new String(playerChatMessage.decoratedContent().getString().getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8)); + Const.sendGuildMsg(msg); + } else { + val msg = String.format("[" + ModConfig.INSTANCE.getCmd().getMcPrefix() + "] %s", new String(playerChatMessage.decoratedContent().getString().getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8)); + Const.sendGroupMsg(msg); + } } - } - if (entity != null) { - commandContext.getSource().getServer().getPlayerList().broadcastMessage(component2, false); - } else { - commandContext.getSource().getServer().getPlayerList().broadcastMessage(component2, false); - } - + ///////////////////////// + playerList.broadcastChatMessage(playerChatMessage, CommandSourceStack, ChatType.bind(ChatType.SAY_COMMAND, CommandSourceStack)); + }); return 1; }))); } diff --git a/fabric/versions/1.20.1/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinLanguage.java b/fabric/versions/1.20.1/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinLanguage.java new file mode 100644 index 00000000..9c3e9591 --- /dev/null +++ b/fabric/versions/1.20.1/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinLanguage.java @@ -0,0 +1,16 @@ +//#if MC >= 11900 +package cn.evole.mods.mcbot.init.mixins; + +import net.minecraft.locale.Language; +import org.spongepowered.asm.mixin.Mixin; + +/** + * Author cnlimiter + * CreateTime 2023/5/19 0:53 + * Name MixinLanguage + * Description + */ +@Mixin(Language.class) +public abstract class MixinLanguage { +} +//#endif \ No newline at end of file diff --git a/fabric/versions/1.20.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinPlayerList.java b/fabric/versions/1.20.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinPlayerList.java deleted file mode 100644 index bf13128d..00000000 --- a/fabric/versions/1.20.2/src/main/java/cn/evole/mods/mcbot/init/mixins/MixinPlayerList.java +++ /dev/null @@ -1,32 +0,0 @@ -package cn.evole.mods.mcbot.init.mixins; - - -import cn.evole.mods.mcbot.init.callbacks.IEvents; -import net.minecraft.network.Connection; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.server.network.CommonListenerCookie; -import net.minecraft.server.players.PlayerList; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -/** - * Author cnlimiter - * CreateTime 2023/5/19 0:51 - * Name MixinPlayerList - * Description - */ - -@Mixin(value = PlayerList.class, priority = 1001) -public abstract class MixinPlayerList { - @Inject(method = "placeNewPlayer", at = @At(value = "TAIL")) - public void PlayerList_placeNewPlayer(Connection connection, ServerPlayer player, CommonListenerCookie commonListenerCookie, CallbackInfo ci) { - IEvents.PLAYER_LOGGED_IN.invoker().onPlayerLoggedIn(player.getCommandSenderWorld(), player); - } - - @Inject(method = "remove", at = @At(value = "HEAD")) - public void PlayerList_remove(ServerPlayer player, CallbackInfo ci) { - IEvents.PLAYER_LOGGED_OUT.invoker().onPlayerLoggedOut(player.getCommandSenderWorld(), player); - } -} \ No newline at end of file diff --git a/fabric/versions/mainProject b/fabric/versions/mainProject index 1acb46a4..d88103e1 100644 --- a/fabric/versions/mainProject +++ b/fabric/versions/mainProject @@ -1 +1 @@ -1.20.1 \ No newline at end of file +1.16.5 \ No newline at end of file diff --git a/fabric/wrapper/src/main/resources/fabric.mod.json b/fabric/wrapper/src/main/resources/fabric.mod.json index 8d207432..9bae72e2 100644 --- a/fabric/wrapper/src/main/resources/fabric.mod.json +++ b/fabric/wrapper/src/main/resources/fabric.mod.json @@ -15,18 +15,9 @@ "icon": "assets/mcbot/icon.png", "environment": "server", "jars": [ - { - "file": "META-INF/jars/McBot-fabric-1.14.x-${version}.jar" - }, - { - "file": "META-INF/jars/McBot-fabric-1.15.x-${version}.jar" - }, { "file": "META-INF/jars/McBot-fabric-1.16.x-${version}.jar" }, - { - "file": "META-INF/jars/McBot-fabric-1.17.x-${version}.jar" - }, { "file": "META-INF/jars/McBot-fabric-1.18.2-${version}.jar" },