From e449599ae74c1191b1c7029fdea658cb6aaebfa2 Mon Sep 17 00:00:00 2001 From: EnZaXD <60033407+FlorianMichael@users.noreply.github.com> Date: Tue, 13 Feb 2024 21:50:19 +0100 Subject: [PATCH] Add ProtocolVersion#betweenInclusive and ProtocolVersion#betweenExclusive (#3690) --- .../api/protocol/version/ProtocolVersion.java | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/com/viaversion/viaversion/api/protocol/version/ProtocolVersion.java b/api/src/main/java/com/viaversion/viaversion/api/protocol/version/ProtocolVersion.java index 8d7539a86..982099287 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/protocol/version/ProtocolVersion.java +++ b/api/src/main/java/com/viaversion/viaversion/api/protocol/version/ProtocolVersion.java @@ -210,7 +210,7 @@ public class ProtocolVersion implements Comparable { this.versionType = versionType; this.version = version; this.snapshotVersion = snapshotVersion; - this.name = name;; + this.name = name; Preconditions.checkArgument(!(isVersionWildcard() && versionRange == null), "A wildcard name must have a version range"); if (versionRange != null) { @@ -377,6 +377,29 @@ public class ProtocolVersion implements Comparable { return this.compareTo(other) <= 0; } + + /** + * Returns whether this protocol version is between the given protocol versions, inclusive. + * + * @param min minimum version + * @param max maximum version + * @return true if this protocol version is between the given protocol versions, inclusive + */ + public boolean betweenInclusive(final ProtocolVersion min, final ProtocolVersion max) { + return this.higherThanOrEquals(min) && this.lowerThanOrEquals(max); + } + + /** + * Returns whether this protocol version is between the given protocol versions, exclusive. + * + * @param min minimum version + * @param max maximum version + * @return true if this protocol version is between the given protocol versions, exclusive + */ + public boolean betweenExclusive(final ProtocolVersion min, final ProtocolVersion max) { + return this.higherThan(min) && this.lowerThan(max); + } + /** * Returns a custom comparator used to compare protocol versions. * Must be overridden if the version type is {@link VersionType#SPECIAL}