XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEServerManager

【Java】我的世界XFE服务器管理器

公开
关注 0 Fork 0 Star 0
UTF-8
package com.xfestudio.xfeservermanager.api.command;

import com.xfestudio.xfeservermanager.api.util.ApiChecks;
import java.util.List;
import java.util.Locale;
import java.util.Map;

/** Platform-neutral semantic representation of one parsed command invocation. */
public record InvocationAst(
        String rawInput,
        String commandId,
        List<String> commandPath,
        Map<String, String> scalarArguments,
        List<SelectorFact> selectors,
        List<ItemFact> items,
        List<InvocationAst> nestedInvocations,
        boolean semanticsKnown
) {
    public InvocationAst {
        rawInput = ApiChecks.notBlank(rawInput, "rawInput");
        commandId = CommandNames.canonicalize(commandId);
        List<String> normalizedPath = ApiChecks.immutableList(commandPath, "commandPath").stream()
                .map(value -> ApiChecks.notBlank(value, "commandPath element").toLowerCase(Locale.ROOT))
                .toList();
        if (!normalizedPath.isEmpty()
                && CommandNames.canonicalize(normalizedPath.get(0)).equals(commandId)) {
            java.util.ArrayList<String> canonicalPath = new java.util.ArrayList<>(normalizedPath);
            canonicalPath.set(0, commandId.substring(commandId.indexOf(':') + 1));
            normalizedPath = List.copyOf(canonicalPath);
        }
        commandPath = normalizedPath;
        scalarArguments = ApiChecks.immutableMap(scalarArguments, "scalarArguments");
        selectors = ApiChecks.immutableList(selectors, "selectors");
        items = ApiChecks.immutableList(items, "items");
        nestedInvocations = ApiChecks.immutableList(nestedInvocations, "nestedInvocations");
    }

    public boolean hasNestedInvocations() {
        return !nestedInvocations.isEmpty();
    }
}