| 1 | package net.minecraft.client.multiplayer.chat.report;
|
| 2 |
|
| 3 | import com.mojang.authlib.minecraft.report.AbuseReport;
|
| 4 | import com.mojang.authlib.minecraft.report.AbuseReportLimits;
|
| 5 | import com.mojang.datafixers.util.Either;
|
| 6 | import java.time.Instant;
|
| 7 | import java.util.UUID;
|
| 8 | import net.fabricmc.api.EnvType;
|
| 9 | import net.fabricmc.api.Environment;
|
| 10 | import net.minecraft.client.gui.components.Tooltip;
|
| 11 | import net.minecraft.client.gui.screens.Screen;
|
| 12 | import net.minecraft.network.chat.Component;
|
| 13 | import org.jspecify.annotations.Nullable;
|
| 14 |
|
| 15 | @Environment(EnvType.CLIENT)
|
| 16 | public abstract class Report {
|
| 17 | protected final UUID reportId;
|
| 18 | protected final Instant createdAt;
|
| 19 | protected final UUID reportedProfileId;
|
| 20 | protected String comments = "";
|
| 21 | protected @Nullable ReportReason reason;
|
| 22 | protected boolean attested;
|
| 23 |
|
| 24 | public Report(final UUID reportId, final Instant createdAt, final UUID reportedProfileId) {
|
| 25 | this.reportId = reportId;
|
| 26 | this.createdAt = createdAt;
|
| 27 | this.reportedProfileId = reportedProfileId;
|
| 28 | }
|
| 29 |
|
| 30 | public boolean isReportedPlayer(final UUID playerId) {
|
| 31 | return playerId.equals(this.reportedProfileId);
|
| 32 | }
|
| 33 |
|
| 34 | public abstract Report copy();
|
| 35 |
|
| 36 | public abstract Screen createScreen(Screen lastScreen, ReportingContext context);
|
| 37 |
|
| 38 | @Environment(EnvType.CLIENT)
|
| 39 | public abstract static class Builder<R extends Report> {
|
| 40 | protected final R report;
|
| 41 | protected final AbuseReportLimits limits;
|
| 42 |
|
| 43 | protected Builder(final R report, final AbuseReportLimits limits) {
|
| 44 | this.report = report;
|
| 45 | this.limits = limits;
|
| 46 | }
|
| 47 |
|
| 48 | public R report() {
|
| 49 | return this.report;
|
| 50 | }
|
| 51 |
|
| 52 | public UUID reportedProfileId() {
|
| 53 | return this.report.reportedProfileId;
|
| 54 | }
|
| 55 |
|
| 56 | public String comments() {
|
| 57 | return this.report.comments;
|
| 58 | }
|
| 59 |
|
| 60 | public boolean attested() {
|
| 61 | return this.report().attested;
|
| 62 | }
|
| 63 |
|
| 64 | public void setComments(final String comments) {
|
| 65 | this.report.comments = comments;
|
| 66 | }
|
| 67 |
|
| 68 | public @Nullable ReportReason reason() {
|
| 69 | return this.report.reason;
|
| 70 | }
|
| 71 |
|
| 72 | public void setReason(final ReportReason reason) {
|
| 73 | this.report.reason = reason;
|
| 74 | }
|
| 75 |
|
| 76 | public void setAttested(final boolean attested) {
|
| 77 | this.report.attested = attested;
|
| 78 | }
|
| 79 |
|
| 80 | public abstract boolean hasContent();
|
| 81 |
|
| 82 | public Report.@Nullable CannotBuildReason checkBuildable() {
|
| 83 | return !this.report().attested ? Report.CannotBuildReason.NOT_ATTESTED : null;
|
| 84 | }
|
| 85 |
|
| 86 | public abstract Either<Report.Result, Report.CannotBuildReason> build(ReportingContext reportingContext);
|
| 87 | }
|
| 88 |
|
| 89 | @Environment(EnvType.CLIENT)
|
| 90 | public record CannotBuildReason(Component message) {
|
| 91 | public static final Report.CannotBuildReason NO_REASON = new Report.CannotBuildReason(Component.translatable("gui.abuseReport.send.no_reason"));
|
| 92 | public static final Report.CannotBuildReason NO_REPORTED_MESSAGES = new Report.CannotBuildReason(
|
| 93 | Component.translatable("gui.chatReport.send.no_reported_messages")
|
| 94 | );
|
| 95 | public static final Report.CannotBuildReason TOO_MANY_MESSAGES = new Report.CannotBuildReason(Component.translatable("gui.chatReport.send.too_many_messages"));
|
| 96 | public static final Report.CannotBuildReason COMMENT_TOO_LONG = new Report.CannotBuildReason(Component.translatable("gui.abuseReport.send.comment_too_long"));
|
| 97 | public static final Report.CannotBuildReason NOT_ATTESTED = new Report.CannotBuildReason(Component.translatable("gui.abuseReport.send.not_attested"));
|
| 98 |
|
| 99 | public Tooltip tooltip() {
|
| 100 | return Tooltip.create(this.message);
|
| 101 | }
|
| 102 | }
|
| 103 |
|
| 104 | @Environment(EnvType.CLIENT)
|
| 105 | public record Result(UUID id, ReportType reportType, AbuseReport report) {
|
| 106 | }
|
| 107 | }
|
| 108 |
|