-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
修复可能的机器人连接问题 添加统计OP使用指令功能
- Loading branch information
Showing
11 changed files
with
110 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 6 additions & 15 deletions
21
src/main/java/top/infsky/mcstats/command/ConnectCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,20 @@ | ||
package top.infsky.mcstats.command; | ||
|
||
import cn.evole.onebot.client.connection.ConnectFactory; | ||
import com.mojang.brigadier.context.CommandContext; | ||
import com.mojang.brigadier.exceptions.CommandSyntaxException; | ||
import net.minecraft.commands.CommandSourceStack; | ||
import net.minecraft.network.chat.Component; | ||
import top.infsky.mcstats.config.ModConfig; | ||
import top.infsky.mcstats.log.LogUtils; | ||
import top.infsky.mcstats.mcbot.McBot; | ||
|
||
public class ConnectCommand { | ||
public static int execute(CommandContext<CommandSourceStack> context) throws CommandSyntaxException { | ||
LogUtils.LOGGER.info("连接QQ机器人"); | ||
context.getSource().sendSuccess(() -> Component.literal("正在尝试连接QQ机器人"), true); | ||
try { | ||
McBot.app = new Thread(() -> { | ||
McBot.service = new ConnectFactory(ModConfig.INSTANCE.getBotConfig().toBot(), McBot.blockingQueue);//创建websocket连接 | ||
McBot.bot = McBot.service.ws.createBot();//创建机器人实例 | ||
}, "BotServer"); | ||
McBot.app.start(); | ||
LogUtils.LOGGER.info("QQ机器人已连接"); | ||
context.getSource().sendSuccess(() -> Component.literal("连接成功。"), true); | ||
} catch (Exception e) { | ||
LogUtils.LOGGER.error("§c机器人服务端配置不正确"); | ||
if (McBot.init()) { | ||
context.getSource().sendSuccess(() -> Component.literal("连接成功"), true); | ||
return 1; | ||
} else { | ||
context.getSource().sendSuccess(() -> Component.literal("连接失败,请检查日志"), true); | ||
} | ||
return 1; | ||
return -1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package top.infsky.mcstats.mixins; | ||
|
||
import net.minecraft.commands.CommandSourceStack; | ||
import net.minecraft.commands.Commands; | ||
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.CallbackInfoReturnable; | ||
import top.infsky.mcstats.McStats; | ||
import top.infsky.mcstats.config.ModConfig; | ||
|
||
import java.util.Objects; | ||
|
||
@Mixin(Commands.class) | ||
public class MixinCommand { | ||
@Inject(method = "performPrefixedCommand", at = @At("HEAD")) | ||
public void performPrefixedCommand(CommandSourceStack commandSourceStack, String string, CallbackInfoReturnable<Integer> cir) { | ||
if (!commandSourceStack.hasPermission(2)) return; | ||
if (!ModConfig.INSTANCE.getCommon().getCommandStatsList().contains(string.substring(1))) return; | ||
|
||
try { | ||
if (McStats.getStatsData() != null) { | ||
McStats.getStatsData().getPlayerDataMap().get(Objects.requireNonNull(commandSourceStack.getPlayer()).getUUID()).OPCommandUsed.add(string.substring(1)); | ||
} | ||
} catch (NullPointerException ignored) {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"required": true, | ||
"package": "top.infsky.mcstats.mixins", | ||
"compatibilityLevel": "JAVA_17", | ||
"mixins": [ | ||
"MixinCommand" | ||
], | ||
"injectors": { | ||
"defaultRequire": 1 | ||
} | ||
} |