From 283a896481aaa5a35b168813e5a875295a6ca19c Mon Sep 17 00:00:00 2001 From: ybw0014 Date: Wed, 11 Sep 2024 16:37:39 -0700 Subject: [PATCH] chore: various changes to 1.20.5 branch (#4240) * 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 --- .github/workflows/e2e-testing.yml | 6 +++++- .../slimefun4/api/MinecraftVersion.java | 14 ++++++++++++-- .../slimefun4/utils/SlimefunUtils.java | 4 ++-- .../slimefun4/utils/TestMinecraftVersion.java | 18 ++++++++++++++++++ 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/.github/workflows/e2e-testing.yml b/.github/workflows/e2e-testing.yml index 351249cbcb..1c77c2c25d 100644 --- a/.github/workflows/e2e-testing.yml +++ b/.github/workflows/e2e-testing.yml @@ -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 diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/MinecraftVersion.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/MinecraftVersion.java index 3a7cecb4eb..8611860411 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/MinecraftVersion.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/MinecraftVersion.java @@ -201,7 +201,7 @@ public boolean isMinecraftVersion(int minecraftVersion) { * It is equivalent to the "minor" version *
* Example: {@literal "1.13"} returns {@literal 13}
- * 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
@@ -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;
}
}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java
index b2fd0ac052..a509b207f3 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java
@@ -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();
}
/**
diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/utils/TestMinecraftVersion.java b/src/test/java/io/github/thebusybiscuit/slimefun4/utils/TestMinecraftVersion.java
index f16a2052b2..74a2622cce 100644
--- a/src/test/java/io/github/thebusybiscuit/slimefun4/utils/TestMinecraftVersion.java
+++ b/src/test/java/io/github/thebusybiscuit/slimefun4/utils/TestMinecraftVersion.java
@@ -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() {