Skip to content

Commit

Permalink
问题修复
Browse files Browse the repository at this point in the history
修复吞字bug
/mcstats reportqq现在将不会发送到游戏里
  • Loading branch information
xia-mc committed Mar 3, 2024
1 parent 4b2e245 commit 2ccc555
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
11 changes: 10 additions & 1 deletion src/main/java/top/infsky/mcstats/command/HelpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
Expand All @@ -20,7 +21,15 @@ public class HelpCommand {
§r/mcstats report §f- §7显示当日截止目前的统计信息§r
""";
public static int execute(CommandContext<CommandSourceStack> 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;
}
}
5 changes: 4 additions & 1 deletion src/main/java/top/infsky/mcstats/command/ReportCommand.java
Original file line number Diff line number Diff line change
@@ -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<CommandSourceStack> 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;
}
}
7 changes: 4 additions & 3 deletions src/main/java/top/infsky/mcstats/command/ReportQQCommand.java
Original file line number Diff line number Diff line change
@@ -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<CommandSourceStack> context) throws CommandSyntaxException {
public static int execute(CommandContext<CommandSourceStack> context) {
LogUtils.LOGGER.info("通过指令输出报告 reportQQ");
McStats.getStatsData().report();
context.getSource().sendSuccess(() -> Component.literal("将当日截止目前的统计信息发送到QQ"), true);
McBot.sendGroupMsg(McStats.getStatsData().getReport());
return 1;
}
}
2 changes: 1 addition & 1 deletion src/main/java/top/infsky/mcstats/data/FamilyReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,6 @@ public static String getOnlinePlayerList(Map<UUID, PlayerData> 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();
}
}

0 comments on commit 2ccc555

Please sign in to comment.