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

XFEServerManager

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

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

import com.xfestudio.xfeservermanager.api.util.ApiChecks;
import java.util.List;
import java.util.Objects;

public record PolicyDecision(
        DecisionEffect effect,
        long policyVersion,
        List<String> matchedRuleIds,
        List<PolicyViolation> violations,
        String explanation
) {
    public PolicyDecision {
        Objects.requireNonNull(effect, "effect");
        if (policyVersion < 0) {
            throw new IllegalArgumentException("policyVersion must be non-negative");
        }
        matchedRuleIds = ApiChecks.immutableList(matchedRuleIds, "matchedRuleIds");
        violations = ApiChecks.immutableList(violations, "violations");
        explanation = ApiChecks.notBlank(explanation, "explanation");
        if (effect != DecisionEffect.DENY && !violations.isEmpty()) {
            throw new IllegalArgumentException("only denied decisions may contain violations");
        }
    }

    public boolean isDenied() {
        return effect == DecisionEffect.DENY;
    }

    public boolean grantsPermission() {
        return effect == DecisionEffect.GRANT;
    }

    public boolean requiresVanillaPermissionCheck() {
        return effect == DecisionEffect.PASS_THROUGH || effect == DecisionEffect.CONSTRAIN;
    }

    /** Elevated commands require admission to the bounded audit writer before execution. */
    public boolean requiresAuditAdmission() {
        return effect == DecisionEffect.GRANT;
    }
}