Skip to content

Commit

Permalink
chore: various changes to 1.20.5 branch (#4240)
Browse files Browse the repository at this point in the history
* fix: fix isBefore, also added unit tests

* chore: comments

* chore: simplify

* chore: use == for enum comparison

* chore: retrigger ci

* chore(ci): e2e on more versions
  • Loading branch information
ybw0014 authored Sep 11, 2024
1 parent cf98cd8 commit 283a896
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/e2e-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ jobs:
javaVersion: '18'
- mcVersion: '1.19.4'
javaVersion: '19'
- mcVersion: 'latest'
- mcVersion: '1.20.4'
javaVersion: '20'
- mcVersion: '1.20.6'
javaVersion: '21'
#- mcVersion: 'latest'
# javaVersion: '21'

steps:
- name: Checkout repository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public boolean isMinecraftVersion(int minecraftVersion) {
* It is equivalent to the "minor" version
* <p>
* Example: {@literal "1.13"} returns {@literal 13}<br />
* Exampe: {@literal "1.13.2"} returns {@literal 13_2}
* Example: {@literal "1.13.2"} returns {@literal 13_2}
*
* @param minecraftVersion
* The {@link Integer} version to match
Expand Down Expand Up @@ -278,7 +278,17 @@ public boolean isBefore(@Nonnull MinecraftVersion version) {
* @return True if this version is before, False if this version is virtual or otherwise.
*/
public boolean isBefore(int minecraftVersion, int patchVersion) {
return !isVirtual() && (this.majorVersion < minecraftVersion && this.minorVersion < patchVersion);
// unit tests or whatever
if (isVirtual()) {
return false;
}

// major version mismatch
if (this.majorVersion != minecraftVersion) {
return this.majorVersion < minecraftVersion;
}

return this.minorVersion == -1 ? patchVersion > 0 : this.minorVersion < patchVersion;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -495,14 +495,14 @@ private static boolean equalsItemMeta(@Nonnull ItemMeta itemMeta, @Nonnull ItemM
return potionMeta.getBasePotionData().equals(sfPotionMeta.getBasePotionData());
} else if (current.isBefore(20, 5)) {
// getBasePotionType without null check for 1.20.3 and 1.20.4
return potionMeta.getBasePotionType().equals(sfPotionMeta.getBasePotionType());
return potionMeta.getBasePotionType() == sfPotionMeta.getBasePotionType();
}
// check if potionMetha has a basePotionType (acting a null check for getBasePotionType
// on 1.20.5+
if (potionMeta.hasBasePotionType() != sfPotionMeta.hasBasePotionType()) {
return false;
}
return potionMeta.getBasePotionType().equals(sfPotionMeta.getBasePotionType());
return potionMeta.getBasePotionType() == sfPotionMeta.getBasePotionType();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,24 @@ void testIsBefore() {
Assertions.assertFalse(MinecraftVersion.MINECRAFT_1_17.isBefore(MinecraftVersion.MINECRAFT_1_16));
}

@Test
@DisplayName("Test if Minecraft versions #isBefore behaves correctly for minor versions")
void testIsBeforeMinor() {
Assertions.assertFalse(MinecraftVersion.MINECRAFT_1_18.isBefore(16, 5));
Assertions.assertFalse(MinecraftVersion.MINECRAFT_1_18.isBefore(17, 1));
Assertions.assertFalse(MinecraftVersion.MINECRAFT_1_18.isBefore(18, 0));
Assertions.assertTrue(MinecraftVersion.MINECRAFT_1_18.isBefore(18, 1));

Assertions.assertFalse(MinecraftVersion.MINECRAFT_1_20.isBefore(20, 0));
Assertions.assertTrue(MinecraftVersion.MINECRAFT_1_20.isBefore(20, 2));
Assertions.assertTrue(MinecraftVersion.MINECRAFT_1_20.isBefore(20, 4));
Assertions.assertTrue(MinecraftVersion.MINECRAFT_1_20.isBefore(20, 5));

Assertions.assertFalse(MinecraftVersion.MINECRAFT_1_20_5.isBefore(20, 4));
Assertions.assertFalse(MinecraftVersion.MINECRAFT_1_20_5.isBefore(20, 5));
Assertions.assertTrue(MinecraftVersion.MINECRAFT_1_20_5.isBefore(20, 6));
}

@Test
@DisplayName("Test correct behaviour for MinecraftVersion.UNKNOWN.isBefore(...)")
void testIsBeforeUnknown() {
Expand Down

0 comments on commit 283a896

Please sign in to comment.