| 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.authlib.minecraft.report.ReportedEntity;
|
| 6 | import com.mojang.datafixers.util.Either;
|
| 7 | import java.time.Instant;
|
| 8 | import java.util.UUID;
|
| 9 | import net.fabricmc.api.EnvType;
|
| 10 | import net.fabricmc.api.Environment;
|
| 11 | import net.minecraft.client.gui.screens.Screen;
|
| 12 | import net.minecraft.client.gui.screens.reporting.NameReportScreen;
|
| 13 | import org.apache.commons.lang3.StringUtils;
|
| 14 | import org.jspecify.annotations.Nullable;
|
| 15 |
|
| 16 | @Environment(EnvType.CLIENT)
|
| 17 | public class NameReport extends Report {
|
| 18 | private final String reportedName;
|
| 19 |
|
| 20 | private NameReport(final UUID reportId, final Instant createdAt, final UUID reportedProfileId, final String reportedName) {
|
| 21 | super(reportId, createdAt, reportedProfileId);
|
| 22 | this.reportedName = reportedName;
|
| 23 | }
|
| 24 |
|
| 25 | public String getReportedName() {
|
| 26 | return this.reportedName;
|
| 27 | }
|
| 28 |
|
| 29 | public NameReport copy() {
|
| 30 | NameReport result = new NameReport(this.reportId, this.createdAt, this.reportedProfileId, this.reportedName);
|
| 31 | result.comments = this.comments;
|
| 32 | result.attested = this.attested;
|
| 33 | return result;
|
| 34 | }
|
| 35 |
|
| 36 | @Override
|
| 37 | public Screen createScreen(final Screen lastScreen, final ReportingContext context) {
|
| 38 | return new NameReportScreen(lastScreen, context, this);
|
| 39 | }
|
| 40 |
|
| 41 | @Environment(EnvType.CLIENT)
|
| 42 | public static class Builder extends Report.Builder<NameReport> {
|
| 43 | public Builder(final NameReport report, final AbuseReportLimits limits) {
|
| 44 | super(report, limits);
|
| 45 | }
|
| 46 |
|
| 47 | public Builder(final UUID reportedProfileId, final String reportedName, final AbuseReportLimits limits) {
|
| 48 | super(new NameReport(UUID.randomUUID(), Instant.now(), reportedProfileId, reportedName), limits);
|
| 49 | }
|
| 50 |
|
| 51 | @Override
|
| 52 | public boolean hasContent() {
|
| 53 | return StringUtils.isNotEmpty(this.comments());
|
| 54 | }
|
| 55 |
|
| 56 | @Override
|
| 57 | public Report.@Nullable CannotBuildReason checkBuildable() {
|
| 58 | return this.report.comments.length() > this.limits.maxOpinionCommentsLength() ? Report.CannotBuildReason.COMMENT_TOO_LONG : super.checkBuildable();
|
| 59 | }
|
| 60 |
|
| 61 | @Override
|
| 62 | public Either<Report.Result, Report.CannotBuildReason> build(final ReportingContext reportingContext) {
|
| 63 | Report.CannotBuildReason error = this.checkBuildable();
|
| 64 | if (error != null) {
|
| 65 | return Either.right(error);
|
| 66 | }
|
| 67 |
|
| 68 | ReportedEntity reportedEntity = new ReportedEntity(this.report.reportedProfileId);
|
| 69 | AbuseReport abuseReport = AbuseReport.name(this.report.comments, reportedEntity, this.report.createdAt);
|
| 70 | return Either.left(new Report.Result(this.report.reportId, ReportType.USERNAME, abuseReport));
|
| 71 | }
|
| 72 | }
|
| 73 | }
|
| 74 |
|