Schema.java

net.minecraft.server.jsonrpc.api.Schema

信息

  • 全限定名:net.minecraft.server.jsonrpc.api.Schema
  • 类型:public record
  • 包:net.minecraft.server.jsonrpc.api
  • 源码路径:src/main/java/net/minecraft/server/jsonrpc/api/Schema.java
  • 起始行号:L36
  • 职责:

    TODO

字段/常量

  • CODEC

    • 类型: Codec<?extends Schema<?>>
    • 修饰符: public static final
    • 源码定位: L39
    • 说明:

      TODO

  • SCHEMA_REGISTRY

    • 类型: List<SchemaComponent<?>>
    • 修饰符: private static final
    • 源码定位: L57
    • 说明:

      TODO

  • BOOL_SCHEMA

    • 类型: Schema<Boolean>
    • 修饰符: public static final
    • 源码定位: L58
    • 说明:

      TODO

  • INT_SCHEMA

    • 类型: Schema<Integer>
    • 修饰符: public static final
    • 源码定位: L59
    • 说明:

      TODO

  • BOOL_OR_INT_SCHEMA

    • 类型: Schema<Either<Boolean,Integer>>
    • 修饰符: public static final
    • 源码定位: L60
    • 说明:

      TODO

  • NUMBER_SCHEMA

    • 类型: Schema<Float>
    • 修饰符: public static final
    • 源码定位: L61
    • 说明:

      TODO

  • STRING_SCHEMA

    • 类型: Schema<String>
    • 修饰符: public static final
    • 源码定位: L62
    • 说明:

      TODO

  • UUID_SCHEMA

    • 类型: Schema<UUID>
    • 修饰符: public static final
    • 源码定位: L63
    • 说明:

      TODO

  • DISCOVERY_SCHEMA

    • 类型: Schema<DiscoveryService.DiscoverResponse>
    • 修饰符: public static final
    • 源码定位: L64
    • 说明:

      TODO

  • DIFFICULTY_SCHEMA

    • 类型: SchemaComponent<Difficulty>
    • 修饰符: public static final
    • 源码定位: L65
    • 说明:

      TODO

  • GAME_TYPE_SCHEMA

    • 类型: SchemaComponent<GameType>
    • 修饰符: public static final
    • 源码定位: L66
    • 说明:

      TODO

  • PERMISSION_LEVEL_SCHEMA

    • 类型: Schema<PermissionLevel>
    • 修饰符: public static final
    • 源码定位: L67
    • 说明:

      TODO

  • PLAYER_SCHEMA

    • 类型: SchemaComponent<PlayerDto>
    • 修饰符: public static final
    • 源码定位: L68
    • 说明:

      TODO

  • VERSION_SCHEMA

    • 类型: SchemaComponent<DiscoveryService.DiscoverInfo>
    • 修饰符: public static final
    • 源码定位: L71
    • 说明:

      TODO

  • SERVER_STATE_SCHEMA

    • 类型: SchemaComponent<ServerStateService.ServerState>
    • 修饰符: public static final
    • 源码定位: L74
    • 说明:

      TODO

  • RULE_TYPE_SCHEMA

    • 类型: Schema<GameRuleType>
    • 修饰符: public static final
    • 源码定位: L81
    • 说明:

      TODO

  • TYPED_GAME_RULE_SCHEMA

    • 类型: SchemaComponent<GameRulesService.GameRuleUpdate<?>>
    • 修饰符: public static final
    • 源码定位: L82
    • 说明:

      TODO

  • UNTYPED_GAME_RULE_SCHEMA

    • 类型: SchemaComponent<GameRulesService.GameRuleUpdate<?>>
    • 修饰符: public static final
    • 源码定位: L89
    • 说明:

      TODO

  • MESSAGE_SCHEMA

    • 类型: SchemaComponent<Message>
    • 修饰符: public static final
    • 源码定位: L92
    • 说明:

      TODO

  • SYSTEM_MESSAGE_SCHEMA

    • 类型: SchemaComponent<ServerStateService.SystemMessage>
    • 修饰符: public static final
    • 源码定位: L99
    • 说明:

      TODO

  • KICK_PLAYER_SCHEMA

    • 类型: SchemaComponent<PlayerService.KickDto>
    • 修饰符: public static final
    • 源码定位: L106
    • 说明:

      TODO

  • OPERATOR_SCHEMA

    • 类型: SchemaComponent<OperatorService.OperatorDto>
    • 修饰符: public static final
    • 源码定位: L109
    • 说明:

      TODO

  • INCOMING_IP_BAN_SCHEMA

    • 类型: SchemaComponent<IpBanlistService.IncomingIpBanDto>
    • 修饰符: public static final
    • 源码定位: L116
    • 说明:

      TODO

  • IP_BAN_SCHEMA

    • 类型: SchemaComponent<IpBanlistService.IpBanDto>
    • 修饰符: public static final
    • 源码定位: L125
    • 说明:

      TODO

  • PLAYER_BAN_SCHEMA

    • 类型: SchemaComponent<BanlistService.UserBanDto>
    • 修饰符: public static final
    • 源码定位: L133
    • 说明:

      TODO

内部类/嵌套类型

  • net.minecraft.server.jsonrpc.api.Schema.(

    • 类型: record
    • 修饰符: public static final
    • 源码定位: L69
    • 说明:

      TODO

  • net.minecraft.server.jsonrpc.api.Schema.(

    • 类型: record
    • 修饰符: public static final
    • 源码定位: L72
    • 说明:

      TODO

  • net.minecraft.server.jsonrpc.api.Schema.(

    • 类型: record
    • 修饰符: public static final
    • 源码定位: L76
    • 说明:

      TODO

  • net.minecraft.server.jsonrpc.api.Schema.(

    • 类型: record
    • 修饰符: public static final
    • 源码定位: L84
    • 说明:

      TODO

  • net.minecraft.server.jsonrpc.api.Schema.(

    • 类型: record
    • 修饰符: public static final
    • 源码定位: L90
    • 说明:

      TODO

  • net.minecraft.server.jsonrpc.api.Schema.(

    • 类型: record
    • 修饰符: public static final
    • 源码定位: L94
    • 说明:

      TODO

  • net.minecraft.server.jsonrpc.api.Schema.(

    • 类型: record
    • 修饰符: public static final
    • 源码定位: L101
    • 说明:

      TODO

  • net.minecraft.server.jsonrpc.api.Schema.(

    • 类型: record
    • 修饰符: public static final
    • 源码定位: L107
    • 说明:

      TODO

  • net.minecraft.server.jsonrpc.api.Schema.(

    • 类型: record
    • 修饰符: public static final
    • 源码定位: L111
    • 说明:

      TODO

  • net.minecraft.server.jsonrpc.api.Schema.(

    • 类型: record
    • 修饰符: public static final
    • 源码定位: L118
    • 说明:

      TODO

  • net.minecraft.server.jsonrpc.api.Schema.(

    • 类型: record
    • 修饰符: public static final
    • 源码定位: L127
    • 说明:

      TODO

  • net.minecraft.server.jsonrpc.api.Schema.(

    • 类型: record
    • 修饰符: public static final
    • 源码定位: L135
    • 说明:

      TODO

  • net.minecraft.server.jsonrpc.api.Schema.(

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

      TODO

  • net.minecraft.server.jsonrpc.api.Schema.(

    • 类型: record
    • 修饰符: private static
    • 源码定位: L200
    • 说明:

      TODO

  • net.minecraft.server.jsonrpc.api.Schema.(

    • 类型: record
    • 修饰符: package-private
    • 源码定位: L207
    • 说明:

      TODO

构造器

方法

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

public static <T> Codec<Schema<T>> typedCodec() @ L142

  • 方法名:typedCodec
  • 源码定位:L142
  • 返回类型: Codec<Schema>
  • 修饰符:public static

参数:

说明:

TODO

public Schema<T> info() @ L146

  • 方法名:info
  • 源码定位:L146
  • 返回类型:Schema
  • 修饰符:public

参数:

说明:

TODO

private static <T> SchemaComponent<T> registerSchema(String name, Schema<T> schema) @ L157

  • 方法名:registerSchema
  • 源码定位:L157
  • 返回类型: SchemaComponent
  • 修饰符:private static

参数:

  • name: String
  • schema: Schema

说明:

TODO

public static List<SchemaComponent<?>> getSchemaRegistry() @ L163

  • 方法名:getSchemaRegistry
  • 源码定位:L163
  • 返回类型:List<SchemaComponent<?>>
  • 修饰符:public static

参数:

说明:

TODO

public static <T> Schema<T> ofRef(URI ref, Codec<T> codec) @ L167

  • 方法名:ofRef
  • 源码定位:L167
  • 返回类型: Schema
  • 修饰符:public static

参数:

  • ref: URI
  • codec: Codec

说明:

TODO

public static <T> Schema<T> ofType(String type, Codec<T> codec) @ L171

  • 方法名:ofType
  • 源码定位:L171
  • 返回类型: Schema
  • 修饰符:public static

参数:

  • type: String
  • codec: Codec

说明:

TODO

public static <T> Schema<T> ofTypes(List<String> types, Codec<T> codec) @ L175

  • 方法名:ofTypes
  • 源码定位:L175
  • 返回类型: Schema
  • 修饰符:public static

参数:

  • types: List
  • codec: Codec

说明:

TODO

public static <E extends Enum<E> &StringRepresentable> Schema<E> ofEnum(Supplier<E[]> values) @ L179

  • 方法名:ofEnum
  • 源码定位:L179
  • 返回类型:<E extends Enum &StringRepresentable> Schema
  • 修饰符:public static

参数:

  • values: Supplier<E[]>

说明:

TODO

public static <E extends Enum<E> &StringRepresentable> Schema<E> ofEnum(Supplier<E[]> values, Codec<E> codec) @ L183

  • 方法名:ofEnum
  • 源码定位:L183
  • 返回类型:<E extends Enum &StringRepresentable> Schema
  • 修饰符:public static

参数:

  • values: Supplier<E[]>
  • codec: Codec

说明:

TODO

public static <T> Schema<T> ofEnum(List<String> enumValues, Codec<T> codec) @ L188

  • 方法名:ofEnum
  • 源码定位:L188
  • 返回类型: Schema
  • 修饰符:public static

参数:

  • enumValues: List
  • codec: Codec

说明:

TODO

public static <T> Schema<List<T>> arrayOf(Schema<?> item, Codec<T> codec) @ L192

  • 方法名:arrayOf
  • 源码定位:L192
  • 返回类型: Schema<List>
  • 修饰符:public static

参数:

  • item: Schema<?>
  • codec: Codec

说明:

TODO

public Schema<T> withField(String name, Schema<?> field) @ L204

  • 方法名:withField
  • 源码定位:L204
  • 返回类型:Schema
  • 修饰符:public

参数:

  • name: String
  • field: Schema<?>

说明:

TODO

public Schema<List<T>> asArray() @ L210

  • 方法名:asArray
  • 源码定位:L210
  • 返回类型:Schema<List>
  • 修饰符:public

参数:

说明:

TODO

代码

public record Schema<T>(
    Optional<URI> reference, List<String> type, Optional<Schema<?>> items, Map<String, Schema<?>> properties, List<String> enumValues, Codec<T> codec
) {
    public static final Codec<? extends Schema<?>> CODEC = Codec.<Schema<?>>recursive(
            "Schema",
            subCodec -> RecordCodecBuilder.create(
                i -> i.group(
                        ReferenceUtil.REFERENCE_CODEC.optionalFieldOf("$ref").forGetter(Schema::reference),
                        ExtraCodecs.compactListCodec(Codec.STRING)
                            .optionalFieldOf("type", List.of())
                            .forGetter(Schema::type),
                        subCodec.optionalFieldOf("items").forGetter(Schema::items),
                        Codec.unboundedMap(Codec.STRING, subCodec)
                            .optionalFieldOf("properties", Map.of())
                            .forGetter(Schema::properties),
                        Codec.STRING.listOf().optionalFieldOf("enum", List.of()).forGetter(Schema::enumValues)
                    )
                    .apply(i, (ref, type, items, properties, enumValues) -> null)
            )
        )
        .validate(schema -> schema == null ? DataResult.error(() -> "Should not deserialize schema") : DataResult.success(schema));
    private static final List<SchemaComponent<?>> SCHEMA_REGISTRY = new ArrayList<>();
    public static final Schema<Boolean> BOOL_SCHEMA = ofType("boolean", Codec.BOOL);
    public static final Schema<Integer> INT_SCHEMA = ofType("integer", Codec.INT);
    public static final Schema<Either<Boolean, Integer>> BOOL_OR_INT_SCHEMA = ofTypes(List.of("boolean", "integer"), Codec.either(Codec.BOOL, Codec.INT));
    public static final Schema<Float> NUMBER_SCHEMA = ofType("number", Codec.FLOAT);
    public static final Schema<String> STRING_SCHEMA = ofType("string", Codec.STRING);
    public static final Schema<UUID> UUID_SCHEMA = ofType("string", UUIDUtil.CODEC);
    public static final Schema<DiscoveryService.DiscoverResponse> DISCOVERY_SCHEMA = ofType("string", DiscoveryService.DiscoverResponse.CODEC.codec());
    public static final SchemaComponent<Difficulty> DIFFICULTY_SCHEMA = registerSchema("difficulty", ofEnum(Difficulty::values, Difficulty.CODEC));
    public static final SchemaComponent<GameType> GAME_TYPE_SCHEMA = registerSchema("game_type", ofEnum(GameType::values, GameType.CODEC));
    public static final Schema<PermissionLevel> PERMISSION_LEVEL_SCHEMA = ofType("integer", PermissionLevel.INT_CODEC);
    public static final SchemaComponent<PlayerDto> PLAYER_SCHEMA = registerSchema(
        "player", record(PlayerDto.CODEC.codec()).withField("id", UUID_SCHEMA).withField("name", STRING_SCHEMA)
    );
    public static final SchemaComponent<DiscoveryService.DiscoverInfo> VERSION_SCHEMA = registerSchema(
        "version", record(DiscoveryService.DiscoverInfo.CODEC.codec()).withField("name", STRING_SCHEMA).withField("protocol", INT_SCHEMA)
    );
    public static final SchemaComponent<ServerStateService.ServerState> SERVER_STATE_SCHEMA = registerSchema(
        "server_state",
        record(ServerStateService.ServerState.CODEC)
            .withField("started", BOOL_SCHEMA)
            .withField("players", PLAYER_SCHEMA.asRef().asArray())
            .withField("version", VERSION_SCHEMA.asRef())
    );
    public static final Schema<GameRuleType> RULE_TYPE_SCHEMA = ofEnum(GameRuleType::values);
    public static final SchemaComponent<GameRulesService.GameRuleUpdate<?>> TYPED_GAME_RULE_SCHEMA = registerSchema(
        "typed_game_rule",
        record(GameRulesService.GameRuleUpdate.TYPED_CODEC)
            .withField("key", STRING_SCHEMA)
            .withField("value", BOOL_OR_INT_SCHEMA)
            .withField("type", RULE_TYPE_SCHEMA)
    );
    public static final SchemaComponent<GameRulesService.GameRuleUpdate<?>> UNTYPED_GAME_RULE_SCHEMA = registerSchema(
        "untyped_game_rule", record(GameRulesService.GameRuleUpdate.CODEC).withField("key", STRING_SCHEMA).withField("value", BOOL_OR_INT_SCHEMA)
    );
    public static final SchemaComponent<Message> MESSAGE_SCHEMA = registerSchema(
        "message",
        record(Message.CODEC)
            .withField("literal", STRING_SCHEMA)
            .withField("translatable", STRING_SCHEMA)
            .withField("translatableParams", STRING_SCHEMA.asArray())
    );
    public static final SchemaComponent<ServerStateService.SystemMessage> SYSTEM_MESSAGE_SCHEMA = registerSchema(
        "system_message",
        record(ServerStateService.SystemMessage.CODEC)
            .withField("message", MESSAGE_SCHEMA.asRef())
            .withField("overlay", BOOL_SCHEMA)
            .withField("receivingPlayers", PLAYER_SCHEMA.asRef().asArray())
    );
    public static final SchemaComponent<PlayerService.KickDto> KICK_PLAYER_SCHEMA = registerSchema(
        "kick_player", record(PlayerService.KickDto.CODEC.codec()).withField("message", MESSAGE_SCHEMA.asRef()).withField("player", PLAYER_SCHEMA.asRef())
    );
    public static final SchemaComponent<OperatorService.OperatorDto> OPERATOR_SCHEMA = registerSchema(
        "operator",
        record(OperatorService.OperatorDto.CODEC.codec())
            .withField("player", PLAYER_SCHEMA.asRef())
            .withField("bypassesPlayerLimit", BOOL_SCHEMA)
            .withField("permissionLevel", INT_SCHEMA)
    );
    public static final SchemaComponent<IpBanlistService.IncomingIpBanDto> INCOMING_IP_BAN_SCHEMA = registerSchema(
        "incoming_ip_ban",
        record(IpBanlistService.IncomingIpBanDto.CODEC.codec())
            .withField("player", PLAYER_SCHEMA.asRef())
            .withField("ip", STRING_SCHEMA)
            .withField("reason", STRING_SCHEMA)
            .withField("source", STRING_SCHEMA)
            .withField("expires", STRING_SCHEMA)
    );
    public static final SchemaComponent<IpBanlistService.IpBanDto> IP_BAN_SCHEMA = registerSchema(
        "ip_ban",
        record(IpBanlistService.IpBanDto.CODEC.codec())
            .withField("ip", STRING_SCHEMA)
            .withField("reason", STRING_SCHEMA)
            .withField("source", STRING_SCHEMA)
            .withField("expires", STRING_SCHEMA)
    );
    public static final SchemaComponent<BanlistService.UserBanDto> PLAYER_BAN_SCHEMA = registerSchema(
        "user_ban",
        record(BanlistService.UserBanDto.CODEC.codec())
            .withField("player", PLAYER_SCHEMA.asRef())
            .withField("reason", STRING_SCHEMA)
            .withField("source", STRING_SCHEMA)
            .withField("expires", STRING_SCHEMA)
    );
 
    public static <T> Codec<Schema<T>> typedCodec() {
        return (Codec<Schema<T>>)CODEC;
    }
 
    public Schema<T> info() {
        return new Schema<>(
            this.reference,
            this.type,
            this.items.map(Schema::info),
            this.properties.entrySet().stream().collect(Collectors.toMap(Entry::getKey, b -> b.getValue().info())),
            this.enumValues,
            this.codec
        );
    }
 
    private static <T> SchemaComponent<T> registerSchema(String name, Schema<T> schema) {
        SchemaComponent<T> entry = new SchemaComponent<>(name, ReferenceUtil.createLocalReference(name), schema);
        SCHEMA_REGISTRY.add(entry);
        return entry;
    }
 
    public static List<SchemaComponent<?>> getSchemaRegistry() {
        return SCHEMA_REGISTRY;
    }
 
    public static <T> Schema<T> ofRef(URI ref, Codec<T> codec) {
        return new Schema<>(Optional.of(ref), List.of(), Optional.empty(), Map.of(), List.of(), codec);
    }
 
    public static <T> Schema<T> ofType(String type, Codec<T> codec) {
        return ofTypes(List.of(type), codec);
    }
 
    public static <T> Schema<T> ofTypes(List<String> types, Codec<T> codec) {
        return new Schema<>(Optional.empty(), types, Optional.empty(), Map.of(), List.of(), codec);
    }
 
    public static <E extends Enum<E> & StringRepresentable> Schema<E> ofEnum(Supplier<E[]> values) {
        return ofEnum(values, StringRepresentable.fromEnum(values));
    }
 
    public static <E extends Enum<E> & StringRepresentable> Schema<E> ofEnum(Supplier<E[]> values, Codec<E> codec) {
        List<String> enumValues = Stream.<Enum>of((Enum[])values.get()).map(rec$ -> ((StringRepresentable)rec$).getSerializedName()).toList();
        return ofEnum(enumValues, codec);
    }
 
    public static <T> Schema<T> ofEnum(List<String> enumValues, Codec<T> codec) {
        return new Schema<>(Optional.empty(), List.of("string"), Optional.empty(), Map.of(), enumValues, codec);
    }
 
    public static <T> Schema<List<T>> arrayOf(Schema<?> item, Codec<T> codec) {
        return new Schema<>(Optional.empty(), List.of("array"), Optional.of(item), Map.of(), List.of(), codec.listOf());
    }
 
    public static <T> Schema<T> record(Codec<T> codec) {
        return new Schema<>(Optional.empty(), List.of("object"), Optional.empty(), Map.of(), List.of(), codec);
    }
 
    private static <T> Schema<T> record(Map<String, Schema<?>> properties, Codec<T> codec) {
        return new Schema<>(Optional.empty(), List.of("object"), Optional.empty(), properties, List.of(), codec);
    }
 
    public Schema<T> withField(String name, Schema<?> field) {
        HashMap<String, Schema<?>> properties = new HashMap<>(this.properties);
        properties.put(name, field);
        return record(properties, this.codec);
    }
 
    public Schema<List<T>> asArray() {
        return arrayOf(this, this.codec);
    }
}

引用的其他类