DiscoveryService.java

net.minecraft.server.jsonrpc.methods.DiscoveryService

信息

  • 全限定名:net.minecraft.server.jsonrpc.methods.DiscoveryService
  • 类型:public class
  • 包:net.minecraft.server.jsonrpc.methods
  • 源码路径:src/main/java/net/minecraft/server/jsonrpc/methods/DiscoveryService.java
  • 起始行号:L15
  • 职责:

    TODO

字段/常量

内部类/嵌套类型

  • net.minecraft.server.jsonrpc.methods.DiscoveryService.DiscoverComponents

    • 类型: record
    • 修饰符: public
    • 源码定位: L38
    • 说明:

      TODO

  • net.minecraft.server.jsonrpc.methods.DiscoveryService.DiscoverInfo

    • 类型: record
    • 修饰符: public
    • 源码定位: L49
    • 说明:

      TODO

  • net.minecraft.server.jsonrpc.methods.DiscoveryService.DiscoverResponse

    • 类型: record
    • 修饰符: public
    • 源码定位: L59
    • 说明:

      TODO

构造器

方法

下面的方法块按源码顺序生成。

public static DiscoveryService.DiscoverResponse discover(List<SchemaComponent<?>> schemaRegistry) @ L16

  • 方法名:discover
  • 源码定位:L16
  • 返回类型:DiscoveryService.DiscoverResponse
  • 修饰符:public static

参数:

  • schemaRegistry: List<SchemaComponent<?>>

说明:

TODO

代码

public class DiscoveryService {
    public static DiscoveryService.DiscoverResponse discover(List<SchemaComponent<?>> schemaRegistry) {
        List<MethodInfo.Named<?, ?>> methods = new ArrayList<>(BuiltInRegistries.INCOMING_RPC_METHOD.size() + BuiltInRegistries.OUTGOING_RPC_METHOD.size());
        BuiltInRegistries.INCOMING_RPC_METHOD.listElements().forEach(e -> {
            if (e.value().attributes().discoverable()) {
                methods.add(e.value().info().named(e.key().identifier()));
            }
        });
        BuiltInRegistries.OUTGOING_RPC_METHOD.listElements().forEach(e -> {
            if (e.value().attributes().discoverable()) {
                methods.add(e.value().info().named(e.key().identifier()));
            }
        });
        Map<String, Schema<?>> schemas = new HashMap<>();
 
        for (SchemaComponent<?> component : schemaRegistry) {
            schemas.put(component.name(), component.schema().info());
        }
 
        DiscoveryService.DiscoverInfo discoverInfo = new DiscoveryService.DiscoverInfo("Minecraft Server JSON-RPC", "2.0.0");
        return new DiscoveryService.DiscoverResponse("1.3.2", discoverInfo, methods, new DiscoveryService.DiscoverComponents(schemas));
    }
 
    public record DiscoverComponents(Map<String, Schema<?>> schemas) {
        public static final MapCodec<DiscoveryService.DiscoverComponents> CODEC = typedSchema();
 
        private static MapCodec<DiscoveryService.DiscoverComponents> typedSchema() {
            return RecordCodecBuilder.mapCodec(
                i -> i.group(Codec.unboundedMap(Codec.STRING, (Codec<Schema<?>>) Schema.CODEC).fieldOf("schemas").forGetter(DiscoveryService.DiscoverComponents::schemas))
                    .apply(i, DiscoveryService.DiscoverComponents::new)
            );
        }
    }
 
    public record DiscoverInfo(String title, String version) {
        public static final MapCodec<DiscoveryService.DiscoverInfo> CODEC = RecordCodecBuilder.mapCodec(
            i -> i.group(
                    Codec.STRING.fieldOf("title").forGetter(DiscoveryService.DiscoverInfo::title),
                    Codec.STRING.fieldOf("version").forGetter(DiscoveryService.DiscoverInfo::version)
                )
                .apply(i, DiscoveryService.DiscoverInfo::new)
        );
    }
 
    public record DiscoverResponse(
        String jsonRpcProtocolVersion,
        DiscoveryService.DiscoverInfo discoverInfo,
        List<MethodInfo.Named<?, ?>> methods,
        DiscoveryService.DiscoverComponents components
    ) {
        public static final MapCodec<DiscoveryService.DiscoverResponse> CODEC = RecordCodecBuilder.mapCodec(
            i -> i.group(
                    Codec.STRING.fieldOf("openrpc").forGetter(DiscoveryService.DiscoverResponse::jsonRpcProtocolVersion),
                    DiscoveryService.DiscoverInfo.CODEC.codec().fieldOf("info").forGetter(DiscoveryService.DiscoverResponse::discoverInfo),
                    Codec.list(MethodInfo.Named.CODEC).fieldOf("methods").forGetter(DiscoveryService.DiscoverResponse::methods),
                    DiscoveryService.DiscoverComponents.CODEC.codec().fieldOf("components").forGetter(DiscoveryService.DiscoverResponse::components)
                )
                .apply(i, DiscoveryService.DiscoverResponse::new)
        );
    }
}

引用的其他类