UuidArgument.java

net.minecraft.commands.arguments.UuidArgument

信息

  • 全限定名:net.minecraft.commands.arguments.UuidArgument
  • 类型:public class
  • 包:net.minecraft.commands.arguments
  • 源码路径:src/main/java/net/minecraft/commands/arguments/UuidArgument.java
  • 起始行号:L16
  • 实现:ArgumentType
  • 职责:

    TODO

字段/常量

  • ERROR_INVALID_UUID

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

      TODO

  • EXAMPLES

    • 类型: Collection<String>
    • 修饰符: private static final
    • 源码定位: L18
    • 说明:

      TODO

  • ALLOWED_CHARACTERS

    • 类型: Pattern
    • 修饰符: private static final
    • 源码定位: L19
    • 说明:

      TODO

内部类/嵌套类型

构造器

方法

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

public static UUID getUuid(CommandContext<CommandSourceStack> source, String name) @ L21

  • 方法名:getUuid
  • 源码定位:L21
  • 返回类型:UUID
  • 修饰符:public static

参数:

  • source: CommandContext
  • name: String

说明:

TODO

public static UuidArgument uuid() @ L25

  • 方法名:uuid
  • 源码定位:L25
  • 返回类型:UuidArgument
  • 修饰符:public static

参数:

说明:

TODO

public UUID parse(StringReader reader) @ L29

  • 方法名:parse
  • 源码定位:L29
  • 返回类型:UUID
  • 修饰符:public

参数:

  • reader: StringReader

说明:

TODO

public Collection<String> getExamples() @ L46

  • 方法名:getExamples
  • 源码定位:L46
  • 返回类型:Collection
  • 修饰符:public

参数:

说明:

TODO

代码

public class UuidArgument implements ArgumentType<UUID> {
    public static final SimpleCommandExceptionType ERROR_INVALID_UUID = new SimpleCommandExceptionType(Component.translatable("argument.uuid.invalid"));
    private static final Collection<String> EXAMPLES = Arrays.asList("dd12be42-52a9-4a91-a8a1-11c01849e498");
    private static final Pattern ALLOWED_CHARACTERS = Pattern.compile("^([-A-Fa-f0-9]+)");
 
    public static UUID getUuid(CommandContext<CommandSourceStack> source, String name) {
        return source.getArgument(name, UUID.class);
    }
 
    public static UuidArgument uuid() {
        return new UuidArgument();
    }
 
    public UUID parse(StringReader reader) throws CommandSyntaxException {
        String remaining = reader.getRemaining();
        Matcher matcher = ALLOWED_CHARACTERS.matcher(remaining);
        if (matcher.find()) {
            String maybeUUID = matcher.group(1);
 
            try {
                UUID result = UUID.fromString(maybeUUID);
                reader.setCursor(reader.getCursor() + maybeUUID.length());
                return result;
            } catch (IllegalArgumentException var6) {
            }
        }
 
        throw ERROR_INVALID_UUID.createWithContext(reader);
    }
 
    @Override
    public Collection<String> getExamples() {
        return EXAMPLES;
    }
}

引用的其他类

  • CommandSourceStack

    • 引用位置: 参数
  • Component

    • 引用位置: 方法调用
    • 关联成员: Component.translatable()
  • TropicalFish

    • 引用位置: 字段/方法调用
    • 关联成员: Pattern.compile()