Search in sources :

Example 1 with BlockedProtocolVersions

use of com.viaversion.viaversion.api.protocol.version.BlockedProtocolVersions in project ViaVersion by ViaVersion.

the class AbstractViaConfig method loadBlockedProtocolVersions.

private BlockedProtocolVersions loadBlockedProtocolVersions() {
    IntSet blockedProtocols = new IntOpenHashSet(getIntegerList("block-protocols"));
    int lowerBound = -1;
    int upperBound = -1;
    for (String s : getStringList("block-versions")) {
        if (s.isEmpty()) {
            continue;
        }
        char c = s.charAt(0);
        if (c == '<' || c == '>') {
            // Set lower/upper bound
            ProtocolVersion protocolVersion = protocolVersion(s.substring(1));
            if (protocolVersion == null) {
                continue;
            }
            if (c == '<') {
                if (lowerBound != -1) {
                    Via.getPlatform().getLogger().warning("Already set lower bound " + lowerBound + " overridden by " + protocolVersion.getName());
                }
                lowerBound = protocolVersion.getVersion();
            } else {
                if (upperBound != -1) {
                    Via.getPlatform().getLogger().warning("Already set upper bound " + upperBound + " overridden by " + protocolVersion.getName());
                }
                upperBound = protocolVersion.getVersion();
            }
            continue;
        }
        ProtocolVersion protocolVersion = protocolVersion(s);
        if (protocolVersion == null) {
            continue;
        }
        // Add single protocol version and check for duplication
        if (!blockedProtocols.add(protocolVersion.getVersion())) {
            Via.getPlatform().getLogger().warning("Duplicated blocked protocol version " + protocolVersion.getName() + "/" + protocolVersion.getVersion());
        }
    }
    // Check for duplicated entries
    if (lowerBound != -1 || upperBound != -1) {
        final int finalLowerBound = lowerBound;
        final int finalUpperBound = upperBound;
        blockedProtocols.removeIf((IntPredicate) version -> {
            if (finalLowerBound != -1 && version < finalLowerBound || finalUpperBound != -1 && version > finalUpperBound) {
                ProtocolVersion protocolVersion = ProtocolVersion.getProtocol(version);
                Via.getPlatform().getLogger().warning("Blocked protocol version " + protocolVersion.getName() + "/" + protocolVersion.getVersion() + " already covered by upper or lower bound");
                return true;
            }
            return false;
        });
    }
    return new BlockedProtocolVersionsImpl(blockedProtocols, lowerBound, upperBound);
}
Also used : IntOpenHashSet(it.unimi.dsi.fastutil.ints.IntOpenHashSet) BlockedProtocolVersionsImpl(com.viaversion.viaversion.protocol.BlockedProtocolVersionsImpl) ViaVersionConfig(com.viaversion.viaversion.api.configuration.ViaVersionConfig) BlockedProtocolVersions(com.viaversion.viaversion.api.protocol.version.BlockedProtocolVersions) HashMap(java.util.HashMap) Via(com.viaversion.viaversion.api.Via) ProtocolVersion(com.viaversion.viaversion.api.protocol.version.ProtocolVersion) IntPredicate(java.util.function.IntPredicate) File(java.io.File) JsonElement(com.google.gson.JsonElement) WorldIdentifiers(com.viaversion.viaversion.api.minecraft.WorldIdentifiers) IntOpenHashSet(it.unimi.dsi.fastutil.ints.IntOpenHashSet) Map(java.util.Map) Config(com.viaversion.viaversion.util.Config) IntSet(it.unimi.dsi.fastutil.ints.IntSet) Nullable(org.checkerframework.checker.nullness.qual.Nullable) BlockedProtocolVersionsImpl(com.viaversion.viaversion.protocol.BlockedProtocolVersionsImpl) IntSet(it.unimi.dsi.fastutil.ints.IntSet) ProtocolVersion(com.viaversion.viaversion.api.protocol.version.ProtocolVersion)

Example 2 with BlockedProtocolVersions

use of com.viaversion.viaversion.api.protocol.version.BlockedProtocolVersions in project ViaVersion by ViaVersion.

the class ViaAPIBase method getSupportedVersions.

@Override
public SortedSet<Integer> getSupportedVersions() {
    SortedSet<Integer> outputSet = new TreeSet<>(Via.getManager().getProtocolManager().getSupportedVersions());
    BlockedProtocolVersions blockedVersions = Via.getPlatform().getConf().blockedProtocolVersions();
    outputSet.removeIf(blockedVersions::contains);
    return outputSet;
}
Also used : TreeSet(java.util.TreeSet) BlockedProtocolVersions(com.viaversion.viaversion.api.protocol.version.BlockedProtocolVersions)

Aggregations

BlockedProtocolVersions (com.viaversion.viaversion.api.protocol.version.BlockedProtocolVersions)2 JsonElement (com.google.gson.JsonElement)1 Via (com.viaversion.viaversion.api.Via)1 ViaVersionConfig (com.viaversion.viaversion.api.configuration.ViaVersionConfig)1 WorldIdentifiers (com.viaversion.viaversion.api.minecraft.WorldIdentifiers)1 ProtocolVersion (com.viaversion.viaversion.api.protocol.version.ProtocolVersion)1 BlockedProtocolVersionsImpl (com.viaversion.viaversion.protocol.BlockedProtocolVersionsImpl)1 Config (com.viaversion.viaversion.util.Config)1 IntOpenHashSet (it.unimi.dsi.fastutil.ints.IntOpenHashSet)1 IntSet (it.unimi.dsi.fastutil.ints.IntSet)1 File (java.io.File)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeSet (java.util.TreeSet)1 IntPredicate (java.util.function.IntPredicate)1 Nullable (org.checkerframework.checker.nullness.qual.Nullable)1