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.command.SelectorType;
import com.xfestudio.xfeservermanager.api.command.SelectorSort;
import com.xfestudio.xfeservermanager.api.util.ApiChecks;
import java.util.Set;

public record SelectorConstraint(
        Set<SelectorType> deniedSelectorTypes,
        Set<SelectorSort> deniedSorts,
        boolean allowBroadSelectorWithExplicitType,
        Integer maximumTargets,
        Double maximumDistance,
        Set<String> allowedEntityTypes,
        Set<String> deniedEntityTypes,
        boolean allowTagFilters,
        boolean allowNbtFilters,
        boolean allowPredicateFilters
) {
    public SelectorConstraint {
        deniedSelectorTypes = ApiChecks.immutableSet(deniedSelectorTypes, "deniedSelectorTypes");
        deniedSorts = ApiChecks.immutableSet(deniedSorts, "deniedSorts");
        if (maximumTargets != null && maximumTargets < 1) {
            throw new IllegalArgumentException("maximumTargets must be positive when present");
        }
        if (maximumDistance != null && (!Double.isFinite(maximumDistance) || maximumDistance < 0.0)) {
            throw new IllegalArgumentException("maximumDistance must be finite and non-negative");
        }
        allowedEntityTypes = ApiChecks.immutableLowercaseSet(allowedEntityTypes, "allowedEntityTypes");
        deniedEntityTypes = ApiChecks.immutableLowercaseSet(deniedEntityTypes, "deniedEntityTypes");
    }

    public SelectorConstraint(
            Set<SelectorType> deniedSelectorTypes,
            boolean allowBroadSelectorWithExplicitType,
            Integer maximumTargets,
            Double maximumDistance,
            Set<String> allowedEntityTypes,
            Set<String> deniedEntityTypes,
            boolean allowTagFilters,
            boolean allowNbtFilters,
            boolean allowPredicateFilters
    ) {
        this(deniedSelectorTypes, Set.of(), allowBroadSelectorWithExplicitType, maximumTargets, maximumDistance,
                allowedEntityTypes, deniedEntityTypes, allowTagFilters, allowNbtFilters, allowPredicateFilters);
    }

    public static SelectorConstraint unrestricted() {
        return new SelectorConstraint(Set.of(), Set.of(), false, null, null, Set.of(), Set.of(), true, true, true);
    }
}