/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.mojang.datafixers.kinds.App * com.mojang.datafixers.kinds.Applicative * com.mojang.serialization.Codec * com.mojang.serialization.MapCodec * com.mojang.serialization.codecs.RecordCodecBuilder * org.jspecify.annotations.Nullable */ package net.minecraft.server.jsonrpc.api; import com.mojang.datafixers.kinds.App; import com.mojang.datafixers.kinds.Applicative; import com.mojang.serialization.Codec; import com.mojang.serialization.MapCodec; import com.mojang.serialization.codecs.RecordCodecBuilder; import java.util.List; import java.util.Optional; import net.minecraft.resources.Identifier; import net.minecraft.server.jsonrpc.api.ParamInfo; import net.minecraft.server.jsonrpc.api.ResultInfo; import org.jspecify.annotations.Nullable; public record MethodInfo(String description, Optional> params, Optional> result) { public MethodInfo(String description, @Nullable ParamInfo paramInfo, @Nullable ResultInfo resultInfo) { this(description, Optional.ofNullable(paramInfo), Optional.ofNullable(resultInfo)); } private static Optional> toOptional(List> list) { return list.isEmpty() ? Optional.empty() : Optional.of(list.getFirst()); } private static List> toList(Optional> opt) { if (opt.isPresent()) { return List.of(opt.get()); } return List.of(); } private static Codec>> paramsTypedCodec() { return ParamInfo.typedCodec().codec().listOf().xmap(MethodInfo::toOptional, MethodInfo::toList); } private static MapCodec> typedCodec() { return RecordCodecBuilder.mapCodec(i -> i.group((App)Codec.STRING.fieldOf("description").forGetter(MethodInfo::description), (App)MethodInfo.paramsTypedCodec().fieldOf("params").forGetter(MethodInfo::params), (App)ResultInfo.typedCodec().optionalFieldOf("result").forGetter(MethodInfo::result)).apply((Applicative)i, MethodInfo::new)); } public Named named(Identifier name) { return new Named(name, this); } public record Named(Identifier name, MethodInfo contents) { public static final Codec> CODEC = Named.typedCodec(); public static Codec> typedCodec() { return RecordCodecBuilder.create(i -> i.group((App)Identifier.CODEC.fieldOf("name").forGetter(Named::name), (App)MethodInfo.typedCodec().forGetter(Named::contents)).apply((Applicative)i, Named::new)); } } }