Skip to content

Commit

Permalink
fix: misjudge version code
Browse files Browse the repository at this point in the history
  • Loading branch information
StarWishsama committed Jul 4, 2024
1 parent 5753e69 commit c08a04c
Showing 1 changed file with 22 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
*
* @author TheBusyBiscuit
* @author Walshy
*
* @see Slimefun
*
*/
public enum MinecraftVersion {

Expand Down Expand Up @@ -75,10 +73,8 @@ public enum MinecraftVersion {
* This constructor forces the {@link MinecraftVersion} to be real.
* It must be a real version of Minecraft.
*
* @param majorVersion
* The major version of minecraft as an {@link Integer}
* @param name
* The display name of this {@link MinecraftVersion}
* @param majorVersion The major version of minecraft as an {@link Integer}
* @param name The display name of this {@link MinecraftVersion}
*/
MinecraftVersion(int majorVersion, @Nonnull String name) {
this.name = name;
Expand All @@ -92,12 +88,9 @@ public enum MinecraftVersion {
* This constructor forces the {@link MinecraftVersion} to be real.
* It must be a real version of Minecraft.
*
* @param majorVersion
* The major (minor in semver, major in MC land) version of minecraft as an {@link Integer}
* @param minor
* The minor (patch in semver, minor in MC land) version of minecraft as an {@link Integer}
* @param name
* The display name of this {@link MinecraftVersion}
* @param majorVersion The major (minor in semver, major in MC land) version of minecraft as an {@link Integer}
* @param minor The minor (patch in semver, minor in MC land) version of minecraft as an {@link Integer}
* @param name The display name of this {@link MinecraftVersion}
*/
MinecraftVersion(int majorVersion, int minor, @Nonnull String name) {
this.name = name;
Expand All @@ -111,10 +104,8 @@ public enum MinecraftVersion {
* A virtual {@link MinecraftVersion} (unknown or unit test) is not an actual
* version of Minecraft but rather a state of the {@link Server} software.
*
* @param name
* The display name of this {@link MinecraftVersion}
* @param virtual
* Whether this {@link MinecraftVersion} is virtual
* @param name The display name of this {@link MinecraftVersion}
* @param virtual Whether this {@link MinecraftVersion} is virtual
*/
MinecraftVersion(@Nonnull String name, boolean virtual) {
this.name = name;
Expand Down Expand Up @@ -154,9 +145,7 @@ public boolean isVirtual() {
* <p>
* Example: {@literal "1.13"} returns {@literal 13}
*
* @param minecraftVersion
* The {@link Integer} version to match
*
* @param minecraftVersion The {@link Integer} version to match
* @return Whether this {@link MinecraftVersion} matches the specified version id
*/
public boolean isMinecraftVersion(int minecraftVersion) {
Expand All @@ -175,15 +164,21 @@ public boolean isMinecraftVersion(int minecraftVersion) {
* Example: {@literal "1.13"} returns {@literal 13}<br />
* Exampe: {@literal "1.13.2"} returns {@literal 13_2}
*
* @param minecraftVersion
* The {@link Integer} version to match
*
* @param minecraftVersion The {@link Integer} version to match
* @return Whether this {@link MinecraftVersion} matches the specified version id
*/
public boolean isMinecraftVersion(int minecraftVersion, int patchVersion) {
return !isVirtual()
&& this.majorVersion == minecraftVersion
&& (this.minorVersion == -1 || this.minorVersion >= patchVersion);
if (isVirtual()) {
return false;
}

if (this.majorVersion != 20) {
return this.majorVersion == minecraftVersion && this.minorVersion >= patchVersion;
} else {
return this.majorVersion == minecraftVersion && this.minorVersion == -1
? patchVersion < 5
: patchVersion >= minorVersion;
}
}

/**
Expand All @@ -192,9 +187,7 @@ public boolean isMinecraftVersion(int minecraftVersion, int patchVersion) {
*
* An unknown version will default to {@literal false}.
*
* @param version
* The {@link MinecraftVersion} to compare
*
* @param version The {@link MinecraftVersion} to compare
* @return Whether this {@link MinecraftVersion} is newer or equal to the given {@link MinecraftVersion}
*/
public boolean isAtLeast(@Nonnull MinecraftVersion version) {
Expand Down Expand Up @@ -227,9 +220,7 @@ public boolean isAtLeast(@Nonnull MinecraftVersion version) {
*
* An unknown version will default to {@literal true}.
*
* @param version
* The {@link MinecraftVersion} to compare
*
* @param version The {@link MinecraftVersion} to compare
* @return Whether this {@link MinecraftVersion} is older than the given one
*/
public boolean isBefore(@Nonnull MinecraftVersion version) {
Expand Down

0 comments on commit c08a04c

Please sign in to comment.