| 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.Objects;
|
| 9 | import java.util.UUID;
|
| 10 | import java.util.function.Supplier;
|
| 11 | import net.fabricmc.api.EnvType;
|
| 12 | import net.fabricmc.api.Environment;
|
| 13 | import net.minecraft.client.gui.screens.Screen;
|
| 14 | import net.minecraft.client.gui.screens.reporting.SkinReportScreen;
|
| 15 | import net.minecraft.core.ClientAsset.DownloadedTexture;
|
| 16 | import net.minecraft.world.entity.player.PlayerSkin;
|
| 17 | import org.apache.commons.lang3.StringUtils;
|
| 18 | import org.jspecify.annotations.Nullable;
|
| 19 |
|
| 20 | @Environment(EnvType.CLIENT)
|
| 21 | public class SkinReport extends Report {
|
| 22 | private final Supplier<PlayerSkin> skinGetter;
|
| 23 |
|
| 24 | private SkinReport(final UUID reportId, final Instant createdAt, final UUID reportedProfileId, final Supplier<PlayerSkin> skinGetter) {
|
| 25 | super(reportId, createdAt, reportedProfileId);
|
| 26 | this.skinGetter = skinGetter;
|
| 27 | }
|
| 28 |
|
| 29 | public Supplier<PlayerSkin> getSkinGetter() {
|
| 30 | return this.skinGetter;
|
| 31 | }
|
| 32 |
|
| 33 | public SkinReport copy() {
|
| 34 | SkinReport result = new SkinReport(this.reportId, this.createdAt, this.reportedProfileId, this.skinGetter);
|
| 35 | result.comments = this.comments;
|
| 36 | result.reason = this.reason;
|
| 37 | result.attested = this.attested;
|
| 38 | return result;
|
| 39 | }
|
| 40 |
|
| 41 | @Override
|
| 42 | public Screen createScreen(final Screen lastScreen, final ReportingContext context) {
|
| 43 | return new SkinReportScreen(lastScreen, context, this);
|
| 44 | }
|
| 45 |
|
| 46 | @Environment(EnvType.CLIENT)
|
| 47 | public static class Builder extends Report.Builder<SkinReport> {
|
| 48 | public Builder(final SkinReport report, final AbuseReportLimits limits) {
|
| 49 | super(report, limits);
|
| 50 | }
|
| 51 |
|
| 52 | public Builder(final UUID reportedProfileId, final Supplier<PlayerSkin> skin, final AbuseReportLimits limits) {
|
| 53 | super(new SkinReport(UUID.randomUUID(), Instant.now(), reportedProfileId, skin), limits);
|
| 54 | }
|
| 55 |
|
| 56 | @Override
|
| 57 | public boolean hasContent() {
|
| 58 | return StringUtils.isNotEmpty(this.comments()) || this.reason() != null;
|
| 59 | }
|
| 60 |
|
| 61 | @Override
|
| 62 | public Report.@Nullable CannotBuildReason checkBuildable() {
|
| 63 | if (this.report.reason == null) {
|
| 64 | return Report.CannotBuildReason.NO_REASON;
|
| 65 | } else {
|
| 66 | return this.report.comments.length() > this.limits.maxOpinionCommentsLength() ? Report.CannotBuildReason.COMMENT_TOO_LONG : super.checkBuildable();
|
| 67 | }
|
| 68 | }
|
| 69 |
|
| 70 | @Override
|
| 71 | public Either<Report.Result, Report.CannotBuildReason> build(final ReportingContext reportingContext) {
|
| 72 | Report.CannotBuildReason error = this.checkBuildable();
|
| 73 | if (error != null) {
|
| 74 | return Either.right(error);
|
| 75 | }
|
| 76 |
|
| 77 | String reason = Objects.requireNonNull(this.report.reason).backendName();
|
| 78 | ReportedEntity reportedEntity = new ReportedEntity(this.report.reportedProfileId);
|
| 79 | PlayerSkin skin = this.report.skinGetter.get();
|
| 80 | String skinUrl = skin.body() instanceof DownloadedTexture downloadedTexture ? downloadedTexture.url() : null;
|
| 81 | AbuseReport abuseReport = AbuseReport.skin(this.report.comments, reason, skinUrl, reportedEntity, this.report.createdAt);
|
| 82 | return Either.left(new Report.Result(this.report.reportId, ReportType.SKIN, abuseReport));
|
| 83 | }
|
| 84 | }
|
| 85 | }
|
| 86 |
|