diff --git a/src/main/java/top/infsky/mcstats/command/HelpCommand.java b/src/main/java/top/infsky/mcstats/command/HelpCommand.java index 9ad106b..12e7b28 100644 --- a/src/main/java/top/infsky/mcstats/command/HelpCommand.java +++ b/src/main/java/top/infsky/mcstats/command/HelpCommand.java @@ -3,6 +3,7 @@ import com.mojang.brigadier.context.CommandContext; import net.minecraft.commands.CommandSourceStack; import net.minecraft.network.chat.Component; +import net.minecraft.world.level.GameRules; public class HelpCommand { private static final String opHelpMsg = """ @@ -20,7 +21,15 @@ public class HelpCommand { §r/mcstats report §f- §7显示当日截止目前的统计信息§r """; public static int execute(CommandContext context) { - context.getSource().sendSuccess(() -> Component.literal(context.getSource().hasPermission(2) ? opHelpMsg : memberHelpMsg), false); + if (context.getSource().hasPermission(2)) { + context.getSource().sendSuccess(() -> Component.literal(opHelpMsg), false); + } else { + final boolean tmpRule = context.getSource().getLevel().getGameRules().getRule(GameRules.RULE_SENDCOMMANDFEEDBACK).get(); + context.getSource().getLevel().getGameRules().getRule(GameRules.RULE_SENDCOMMANDFEEDBACK).set(true, context.getSource().getServer()); + context.getSource().sendSuccess(() -> Component.literal(memberHelpMsg), false); + context.getSource().getLevel().getGameRules().getRule(GameRules.RULE_SENDCOMMANDFEEDBACK).set(tmpRule, context.getSource().getServer()); + } + return 1; } } diff --git a/src/main/java/top/infsky/mcstats/command/ReportCommand.java b/src/main/java/top/infsky/mcstats/command/ReportCommand.java index 4a2713d..ecb198e 100644 --- a/src/main/java/top/infsky/mcstats/command/ReportCommand.java +++ b/src/main/java/top/infsky/mcstats/command/ReportCommand.java @@ -1,16 +1,19 @@ package top.infsky.mcstats.command; import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.minecraft.commands.CommandSourceStack; import net.minecraft.network.chat.Component; +import net.minecraft.world.level.GameRules; import top.infsky.mcstats.McStats; import top.infsky.mcstats.log.LogUtils; public class ReportCommand { public static int execute(CommandContext context) { LogUtils.LOGGER.info("通过指令输出报告 report"); + final boolean tmpRule = context.getSource().getLevel().getGameRules().getRule(GameRules.RULE_SENDCOMMANDFEEDBACK).get(); + context.getSource().getLevel().getGameRules().getRule(GameRules.RULE_SENDCOMMANDFEEDBACK).set(true, context.getSource().getServer()); context.getSource().sendSuccess(() -> Component.literal(McStats.getStatsData().getReport()), false); + context.getSource().getLevel().getGameRules().getRule(GameRules.RULE_SENDCOMMANDFEEDBACK).set(tmpRule, context.getSource().getServer()); return 1; } } diff --git a/src/main/java/top/infsky/mcstats/command/ReportQQCommand.java b/src/main/java/top/infsky/mcstats/command/ReportQQCommand.java index 07fd5b9..fc1c582 100644 --- a/src/main/java/top/infsky/mcstats/command/ReportQQCommand.java +++ b/src/main/java/top/infsky/mcstats/command/ReportQQCommand.java @@ -1,16 +1,17 @@ package top.infsky.mcstats.command; 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.McStats; import top.infsky.mcstats.log.LogUtils; +import top.infsky.mcstats.mcbot.McBot; public class ReportQQCommand { - public static int execute(CommandContext context) throws CommandSyntaxException { + public static int execute(CommandContext context) { LogUtils.LOGGER.info("通过指令输出报告 reportQQ"); - McStats.getStatsData().report(); + context.getSource().sendSuccess(() -> Component.literal("将当日截止目前的统计信息发送到QQ"), true); + McBot.sendGroupMsg(McStats.getStatsData().getReport()); return 1; } } diff --git a/src/main/java/top/infsky/mcstats/data/FamilyReport.java b/src/main/java/top/infsky/mcstats/data/FamilyReport.java index 0354e1e..29dfb27 100644 --- a/src/main/java/top/infsky/mcstats/data/FamilyReport.java +++ b/src/main/java/top/infsky/mcstats/data/FamilyReport.java @@ -94,6 +94,6 @@ public static String getOnlinePlayerList(Map dataMap) { for (PlayerData player : dataMap.values()) { back.append(" ").append(player.getPlayer().getName().getString()).append("\n"); } - return back.substring(0, back.length() - 2); + return back.toString(); } }