From 5b2182003a142a882b5aaac51b61d040edf64a43 Mon Sep 17 00:00:00 2001 From: Aizistral Date: Sat, 25 Jun 2022 17:25:12 +0200 Subject: Document test mod --- src/test/java/com/aizistral/nochatreports/debug/ReportWriter.java | 7 +++++++ .../nochatreports/debug/mixins/MixinAbuseReportSenderServices.java | 6 ++++++ .../com/aizistral/nochatreports/debug/mixins/MixinPlayerEntry.java | 7 +++++++ 3 files changed, 20 insertions(+) diff --git a/src/test/java/com/aizistral/nochatreports/debug/ReportWriter.java b/src/test/java/com/aizistral/nochatreports/debug/ReportWriter.java index 5e8ee0f..bc663d3 100644 --- a/src/test/java/com/aizistral/nochatreports/debug/ReportWriter.java +++ b/src/test/java/com/aizistral/nochatreports/debug/ReportWriter.java @@ -8,6 +8,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.Date; +import com.aizistral.nochatreports.debug.mixins.MixinAbuseReportSenderServices; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.ibm.icu.text.SimpleDateFormat; @@ -17,6 +18,12 @@ import com.mojang.authlib.yggdrasil.request.AbuseReportRequest; import net.fabricmc.loader.api.FabricLoader; +/** + * Allows to save chat reports locally. See {@link MixinAbuseReportSenderServices} for details. + * + * @author Aizistral + */ + public class ReportWriter { private static final ObjectMapper MAPPER = ObjectMapper.create(); private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); diff --git a/src/test/java/com/aizistral/nochatreports/debug/mixins/MixinAbuseReportSenderServices.java b/src/test/java/com/aizistral/nochatreports/debug/mixins/MixinAbuseReportSenderServices.java index 9ce6933..aa16ae1 100644 --- a/src/test/java/com/aizistral/nochatreports/debug/mixins/MixinAbuseReportSenderServices.java +++ b/src/test/java/com/aizistral/nochatreports/debug/mixins/MixinAbuseReportSenderServices.java @@ -21,6 +21,12 @@ public class MixinAbuseReportSenderServices { @Shadow @Final private ReportEnvironment environment; + /** + * @reason Write report locally instead of trying to send it to Mojang. + * Allows to intercept and examine contents of the report. + * @author Aizistral + */ + @Overwrite public CompletableFuture send(UUID uuid, AbuseReport abuseReport) { AbuseReportRequest abuseReportRequest = new AbuseReportRequest(uuid, diff --git a/src/test/java/com/aizistral/nochatreports/debug/mixins/MixinPlayerEntry.java b/src/test/java/com/aizistral/nochatreports/debug/mixins/MixinPlayerEntry.java index 1f671ca..e7e4cfc 100644 --- a/src/test/java/com/aizistral/nochatreports/debug/mixins/MixinPlayerEntry.java +++ b/src/test/java/com/aizistral/nochatreports/debug/mixins/MixinPlayerEntry.java @@ -10,6 +10,13 @@ import net.minecraft.client.multiplayer.chat.report.AbuseReportSender; @Mixin(PlayerEntry.class) public class MixinPlayerEntry { + /** + * @reason Always allow to report players on server, even if services are + * unreachable (which they are in IDE). Useful when used along with + * {@link MixinAbuseReportSenderServices}. + * @author Aizistral + */ + @Redirect(method = "", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/chat/report/AbuseReportSender;isEnabled()Z")) private boolean forceEnableReporting(AbuseReportSender sender) { -- cgit v1.2.3