OutgoingRpcMethod.java
net.minecraft.server.jsonrpc.OutgoingRpcMethod
信息
- 全限定名:net.minecraft.server.jsonrpc.OutgoingRpcMethod
- 类型:public interface
- 包:net.minecraft.server.jsonrpc
- 源码路径:src/main/java/net/minecraft/server/jsonrpc/OutgoingRpcMethod.java
- 起始行号:L15
- 职责:
TODO
字段/常量
NOTIFICATION_PREFIX- 类型:
String - 修饰符:
package-private - 源码定位:
L16 - 说明:
TODO
- 类型:
内部类/嵌套类型
-
net.minecraft.server.jsonrpc.OutgoingRpcMethod.Attributes- 类型:
record - 修饰符:
public - 源码定位:
L46 - 说明:
TODO
- 类型:
-
net.minecraft.server.jsonrpc.OutgoingRpcMethod.Factory- 类型:
interface - 修饰符:
public - 源码定位:
L50 - 说明:
TODO
- 类型:
-
net.minecraft.server.jsonrpc.OutgoingRpcMethod.Method- 类型:
record - 修饰符:
public - 源码定位:
L54 - 说明:
TODO
- 类型:
-
net.minecraft.server.jsonrpc.OutgoingRpcMethod.Notification- 类型:
record - 修饰符:
public - 源码定位:
L74 - 说明:
TODO
- 类型:
-
net.minecraft.server.jsonrpc.OutgoingRpcMethod.OutgoingRpcMethodBuilder- 类型:
class - 修饰符:
public static - 源码定位:
L85 - 说明:
TODO
- 类型:
-
net.minecraft.server.jsonrpc.OutgoingRpcMethod.ParameterlessMethod- 类型:
record - 修饰符:
public - 源码定位:
L125 - 说明:
TODO
- 类型:
-
net.minecraft.server.jsonrpc.OutgoingRpcMethod.ParmeterlessNotification- 类型:
record - 修饰符:
public - 源码定位:
L137 - 说明:
TODO
- 类型:
构造器
- 无
方法
下面的方法块按源码顺序生成。
MethodInfo<Params,Result> info() @ L18
- 方法名:info
- 源码定位:L18
- 返回类型:MethodInfo<Params,Result>
- 修饰符:package-private
参数:
- 无
说明:
TODO
OutgoingRpcMethod.Attributes attributes() @ L20
- 方法名:attributes
- 源码定位:L20
- 返回类型:OutgoingRpcMethod.Attributes
- 修饰符:package-private
参数:
- 无
说明:
TODO
default JsonElement encodeParams(Params params) @ L22
- 方法名:encodeParams
- 源码定位:L22
- 返回类型:JsonElement
- 修饰符:default
参数:
- params: Params
说明:
TODO
default Result decodeResult(JsonElement result) @ L26
- 方法名:decodeResult
- 源码定位:L26
- 返回类型:Result
- 修饰符:default
参数:
- result: JsonElement
说明:
TODO
static OutgoingRpcMethod.OutgoingRpcMethodBuilder<Void,Void> notification() @ L30
- 方法名:notification
- 源码定位:L30
- 返回类型:OutgoingRpcMethod.OutgoingRpcMethodBuilder<Void,Void>
- 修饰符:static
参数:
- 无
说明:
TODO
static <Params> OutgoingRpcMethod.OutgoingRpcMethodBuilder<Params,Void> notificationWithParams() @ L34
- 方法名:notificationWithParams
- 源码定位:L34
- 返回类型:
OutgoingRpcMethod.OutgoingRpcMethodBuilder<Params,Void> - 修饰符:static
参数:
- 无
说明:
TODO
static <Result> OutgoingRpcMethod.OutgoingRpcMethodBuilder<Void,Result> request() @ L38
- 方法名:request
- 源码定位:L38
- 返回类型:
OutgoingRpcMethod.OutgoingRpcMethodBuilder<Void,Result> - 修饰符:static
参数:
- 无
说明:
TODO
static <Params,Result> OutgoingRpcMethod.OutgoingRpcMethodBuilder<Params,Result> requestWithParams() @ L42
- 方法名:requestWithParams
- 源码定位:L42
- 返回类型:<Params,Result> OutgoingRpcMethod.OutgoingRpcMethodBuilder<Params,Result>
- 修饰符:static
参数:
- 无
说明:
TODO
代码
public interface OutgoingRpcMethod<Params, Result> {
String NOTIFICATION_PREFIX = "notification/";
MethodInfo<Params, Result> info();
OutgoingRpcMethod.Attributes attributes();
default @Nullable JsonElement encodeParams(Params params) {
return null;
}
default @Nullable Result decodeResult(JsonElement result) {
return null;
}
static OutgoingRpcMethod.OutgoingRpcMethodBuilder<Void, Void> notification() {
return new OutgoingRpcMethod.OutgoingRpcMethodBuilder<>(OutgoingRpcMethod.ParmeterlessNotification::new);
}
static <Params> OutgoingRpcMethod.OutgoingRpcMethodBuilder<Params, Void> notificationWithParams() {
return new OutgoingRpcMethod.OutgoingRpcMethodBuilder<>(OutgoingRpcMethod.Notification::new);
}
static <Result> OutgoingRpcMethod.OutgoingRpcMethodBuilder<Void, Result> request() {
return new OutgoingRpcMethod.OutgoingRpcMethodBuilder<>(OutgoingRpcMethod.ParameterlessMethod::new);
}
static <Params, Result> OutgoingRpcMethod.OutgoingRpcMethodBuilder<Params, Result> requestWithParams() {
return new OutgoingRpcMethod.OutgoingRpcMethodBuilder<>(OutgoingRpcMethod.Method::new);
}
public record Attributes(boolean discoverable) {
}
@FunctionalInterface
public interface Factory<Params, Result> {
OutgoingRpcMethod<Params, Result> create(MethodInfo<Params, Result> info, OutgoingRpcMethod.Attributes attributes);
}
public record Method<Params, Result>(MethodInfo<Params, Result> info, OutgoingRpcMethod.Attributes attributes) implements OutgoingRpcMethod<Params, Result> {
@Override
public @Nullable JsonElement encodeParams(Params params) {
if (this.info.params().isEmpty()) {
throw new IllegalStateException("Method defined as having no parameters");
} else {
return this.info.params().get().schema().codec().encodeStart(JsonOps.INSTANCE, params).getOrThrow();
}
}
@Override
public Result decodeResult(JsonElement result) {
if (this.info.result().isEmpty()) {
throw new IllegalStateException("Method defined as having no result");
} else {
return this.info.result().get().schema().codec().parse(JsonOps.INSTANCE, result).getOrThrow();
}
}
}
public record Notification<Params>(MethodInfo<Params, Void> info, OutgoingRpcMethod.Attributes attributes) implements OutgoingRpcMethod<Params, Void> {
@Override
public @Nullable JsonElement encodeParams(Params params) {
if (this.info.params().isEmpty()) {
throw new IllegalStateException("Method defined as having no parameters");
} else {
return this.info.params().get().schema().codec().encodeStart(JsonOps.INSTANCE, params).getOrThrow();
}
}
}
public static class OutgoingRpcMethodBuilder<Params, Result> {
public static final OutgoingRpcMethod.Attributes DEFAULT_ATTRIBUTES = new OutgoingRpcMethod.Attributes(true);
private final OutgoingRpcMethod.Factory<Params, Result> method;
private String description = "";
private @Nullable ParamInfo<Params> paramInfo;
private @Nullable ResultInfo<Result> resultInfo;
public OutgoingRpcMethodBuilder(OutgoingRpcMethod.Factory<Params, Result> method) {
this.method = method;
}
public OutgoingRpcMethod.OutgoingRpcMethodBuilder<Params, Result> description(String description) {
this.description = description;
return this;
}
public OutgoingRpcMethod.OutgoingRpcMethodBuilder<Params, Result> response(String resultName, Schema<Result> resultSchema) {
this.resultInfo = new ResultInfo<>(resultName, resultSchema);
return this;
}
public OutgoingRpcMethod.OutgoingRpcMethodBuilder<Params, Result> param(String paramName, Schema<Params> paramSchema) {
this.paramInfo = new ParamInfo<>(paramName, paramSchema);
return this;
}
private OutgoingRpcMethod<Params, Result> build() {
MethodInfo<Params, Result> methodInfo = new MethodInfo<>(this.description, this.paramInfo, this.resultInfo);
return this.method.create(methodInfo, DEFAULT_ATTRIBUTES);
}
public Holder.Reference<OutgoingRpcMethod<Params, Result>> register(String key) {
return this.register(Identifier.withDefaultNamespace("notification/" + key));
}
private Holder.Reference<OutgoingRpcMethod<Params, Result>> register(Identifier id) {
return Registry.registerForHolder(BuiltInRegistries.OUTGOING_RPC_METHOD, id, this.build());
}
}
public record ParameterlessMethod<Result>(MethodInfo<Void, Result> info, OutgoingRpcMethod.Attributes attributes)
implements OutgoingRpcMethod<Void, Result> {
@Override
public Result decodeResult(JsonElement result) {
if (this.info.result().isEmpty()) {
throw new IllegalStateException("Method defined as having no result");
} else {
return this.info.result().get().schema().codec().parse(JsonOps.INSTANCE, result).getOrThrow();
}
}
}
public record ParmeterlessNotification(MethodInfo<Void, Void> info, OutgoingRpcMethod.Attributes attributes) implements OutgoingRpcMethod<Void, Void> {
}
}引用的其他类
-
- 引用位置:
方法调用 - 关联成员:
Registry.registerForHolder()
- 引用位置:
-
- 引用位置:
参数/返回值
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Identifier.withDefaultNamespace()
- 引用位置:
-
- 引用位置:
返回值
- 引用位置: