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);
}
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;
}
Aggregations