/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.google.gson.JsonElement * com.mojang.serialization.DynamicOps * com.mojang.serialization.JsonOps * org.jspecify.annotations.Nullable */ package net.minecraft.server.jsonrpc; import com.google.gson.JsonElement; import com.mojang.serialization.DynamicOps; import com.mojang.serialization.JsonOps; import net.minecraft.core.Holder; import net.minecraft.core.Registry; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.Identifier; import net.minecraft.server.jsonrpc.api.MethodInfo; import net.minecraft.server.jsonrpc.api.ParamInfo; import net.minecraft.server.jsonrpc.api.ResultInfo; import net.minecraft.server.jsonrpc.api.Schema; import org.jspecify.annotations.Nullable; public interface OutgoingRpcMethod { public static final String NOTIFICATION_PREFIX = "notification/"; public MethodInfo info(); public Attributes attributes(); default public @Nullable JsonElement encodeParams(Params params) { return null; } default public @Nullable Result decodeResult(JsonElement result) { return null; } public static OutgoingRpcMethodBuilder notification() { return new OutgoingRpcMethodBuilder(ParmeterlessNotification::new); } public static OutgoingRpcMethodBuilder notificationWithParams() { return new OutgoingRpcMethodBuilder(Notification::new); } public static OutgoingRpcMethodBuilder request() { return new OutgoingRpcMethodBuilder(ParameterlessMethod::new); } public static OutgoingRpcMethodBuilder requestWithParams() { return new OutgoingRpcMethodBuilder(Method::new); } public static class OutgoingRpcMethodBuilder { public static final Attributes DEFAULT_ATTRIBUTES = new Attributes(true); private final Factory method; private String description = ""; private @Nullable ParamInfo paramInfo; private @Nullable ResultInfo resultInfo; public OutgoingRpcMethodBuilder(Factory method) { this.method = method; } public OutgoingRpcMethodBuilder description(String description) { this.description = description; return this; } public OutgoingRpcMethodBuilder response(String resultName, Schema resultSchema) { this.resultInfo = new ResultInfo(resultName, resultSchema); return this; } public OutgoingRpcMethodBuilder param(String paramName, Schema paramSchema) { this.paramInfo = new ParamInfo(paramName, paramSchema); return this; } private OutgoingRpcMethod build() { MethodInfo methodInfo = new MethodInfo(this.description, this.paramInfo, this.resultInfo); return this.method.create(methodInfo, DEFAULT_ATTRIBUTES); } public Holder.Reference> register(String key) { return this.register(Identifier.withDefaultNamespace(OutgoingRpcMethod.NOTIFICATION_PREFIX + key)); } private Holder.Reference> register(Identifier id) { return Registry.registerForHolder(BuiltInRegistries.OUTGOING_RPC_METHOD, id, this.build()); } } @FunctionalInterface public static interface Factory { public OutgoingRpcMethod create(MethodInfo var1, Attributes var2); } public record Method(MethodInfo info, Attributes attributes) implements OutgoingRpcMethod { @Override public @Nullable JsonElement encodeParams(Params params) { if (this.info.params().isEmpty()) { throw new IllegalStateException("Method defined as having no parameters"); } return (JsonElement)this.info.params().get().schema().codec().encodeStart((DynamicOps)JsonOps.INSTANCE, params).getOrThrow(); } @Override public Result decodeResult(JsonElement result) { if (this.info.result().isEmpty()) { throw new IllegalStateException("Method defined as having no result"); } return (Result)this.info.result().get().schema().codec().parse((DynamicOps)JsonOps.INSTANCE, (Object)result).getOrThrow(); } } public record ParameterlessMethod(MethodInfo info, Attributes attributes) implements OutgoingRpcMethod { @Override public Result decodeResult(JsonElement result) { if (this.info.result().isEmpty()) { throw new IllegalStateException("Method defined as having no result"); } return (Result)this.info.result().get().schema().codec().parse((DynamicOps)JsonOps.INSTANCE, (Object)result).getOrThrow(); } } public record Notification(MethodInfo info, Attributes attributes) implements OutgoingRpcMethod { @Override public @Nullable JsonElement encodeParams(Params params) { if (this.info.params().isEmpty()) { throw new IllegalStateException("Method defined as having no parameters"); } return (JsonElement)this.info.params().get().schema().codec().encodeStart((DynamicOps)JsonOps.INSTANCE, params).getOrThrow(); } } public record ParmeterlessNotification(MethodInfo info, Attributes attributes) implements OutgoingRpcMethod { } public record Attributes(boolean discoverable) { } }