From bca3a1b04d7d412ac66e5db1e9c124d3abd09cf8 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Wed, 29 Dec 2021 14:46:30 +0000 Subject: [PATCH] More precise method names in MinecraftVersion - Also ensure correct comparisons are made in FaweBukkit and BukkitServerInterface - Fixes #1504 --- .../fastasyncworldedit/bukkit/FaweBukkit.java | 2 +- .../bukkit/util/MinecraftVersion.java | 13 +++++++++---- .../bukkit/BukkitServerInterface.java | 4 ++-- .../util/MinecraftVersionTest.java | 18 +++++++++--------- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/FaweBukkit.java b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/FaweBukkit.java index 77f5f275c..8419955d4 100644 --- a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/FaweBukkit.java +++ b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/FaweBukkit.java @@ -83,7 +83,7 @@ public class FaweBukkit implements IFawe, Listener { Bukkit.getServer().shutdown(); } - chunksStretched = new MinecraftVersion().isEqualOrLower(MinecraftVersion.NETHER); + chunksStretched = new MinecraftVersion().isEqualOrHigherThan(MinecraftVersion.NETHER); platformAdapter = new NMSAdapter(); diff --git a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/util/MinecraftVersion.java b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/util/MinecraftVersion.java index 7715c65e2..43fa6b0b6 100644 --- a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/util/MinecraftVersion.java +++ b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/util/MinecraftVersion.java @@ -69,7 +69,7 @@ public class MinecraftVersion implements Comparable { * @param other The other version to compare against. * @return {@code true} if this version is higher or equal compared to the other version. */ - public boolean isEqualOrHigher(MinecraftVersion other) { + public boolean isEqualOrHigherThan(MinecraftVersion other) { return compareTo(other) >= 0; } @@ -77,7 +77,7 @@ public class MinecraftVersion implements Comparable { * @param other The other version to compare against. * @return {@code true} if this version is lower or equal compared to the other version. */ - public boolean isEqualOrLower(MinecraftVersion other) { + public boolean isEqualOrLowerThan(MinecraftVersion other) { return compareTo(other) <= 0; } @@ -85,7 +85,7 @@ public class MinecraftVersion implements Comparable { * @param other The other version to compare against. * @return {@code true} if this version is higher than the other version. */ - public boolean isHigher(MinecraftVersion other) { + public boolean isHigherThan(MinecraftVersion other) { return compareTo(other) > 0; } @@ -93,7 +93,7 @@ public class MinecraftVersion implements Comparable { * @param other The other version to compare against. * @return {@code true} if this version is lower than to the other version. */ - public boolean isLower(MinecraftVersion other) { + public boolean isLowerThan(MinecraftVersion other) { return compareTo(other) < 0; } @@ -140,6 +140,11 @@ public class MinecraftVersion implements Comparable { return getRelease() == that.getRelease(); } + @Override + public String toString() { + return major + "." + minor + "." + release; + } + /** * Determines the server version based on the CraftBukkit package path, e.g. {@code org.bukkit.craftbukkit.v1_16_R3}, * where v1_16_R3 is the resolved version. diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java index 033790560..10df72cef 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java @@ -282,12 +282,12 @@ public class BukkitServerInterface extends AbstractPlatform implements MultiUser @Override public int getVersionMinY() { - return new MinecraftVersion().isEqualOrLower(MinecraftVersion.CAVES_18) ? -64 : 0; + return new MinecraftVersion().isEqualOrHigherThan(MinecraftVersion.CAVES_18) ? -64 : 0; } @Override public int getVersionMaxY() { - return new MinecraftVersion().isEqualOrLower(MinecraftVersion.CAVES_18) ? 319 : 255; + return new MinecraftVersion().isEqualOrHigherThan(MinecraftVersion.CAVES_18) ? 319 : 255; } //FAWE end } diff --git a/worldedit-bukkit/src/test/java/com/fastasyncworldedit/util/MinecraftVersionTest.java b/worldedit-bukkit/src/test/java/com/fastasyncworldedit/util/MinecraftVersionTest.java index 561d2be37..9d54616d4 100644 --- a/worldedit-bukkit/src/test/java/com/fastasyncworldedit/util/MinecraftVersionTest.java +++ b/worldedit-bukkit/src/test/java/com/fastasyncworldedit/util/MinecraftVersionTest.java @@ -20,14 +20,14 @@ public class MinecraftVersionTest { @Test public void testEqualOrHigher() { - assertTrue(latestVersion.isEqualOrHigher(new MinecraftVersion(1, 16, 3))); - assertTrue(latestVersion.isEqualOrHigher(new MinecraftVersion(1, 16, 2))); - assertFalse(latestVersion.isEqualOrHigher(new MinecraftVersion(1, 16, 4))); + assertTrue(latestVersion.isEqualOrHigherThan(new MinecraftVersion(1, 16, 3))); + assertTrue(latestVersion.isEqualOrHigherThan(new MinecraftVersion(1, 16, 2))); + assertFalse(latestVersion.isEqualOrHigherThan(new MinecraftVersion(1, 16, 4))); } @Test public void testEqualOrHigherWithoutRelease() { - assertTrue(latestVersion.isEqualOrHigher(new MinecraftVersion(1, 16))); + assertTrue(latestVersion.isEqualOrHigherThan(new MinecraftVersion(1, 16))); } @Test @@ -39,15 +39,15 @@ public class MinecraftVersionTest { @Test public void testEqualOrLower() { - assertTrue(latestVersion.isEqualOrLower(new MinecraftVersion(1, 16, 3))); - assertTrue(latestVersion.isEqualOrLower(new MinecraftVersion(1, 16, 4))); - assertFalse(latestVersion.isEqualOrLower(new MinecraftVersion(1, 16, 2))); + assertTrue(latestVersion.isEqualOrLowerThan(new MinecraftVersion(1, 16, 3))); + assertTrue(latestVersion.isEqualOrLowerThan(new MinecraftVersion(1, 16, 4))); + assertFalse(latestVersion.isEqualOrLowerThan(new MinecraftVersion(1, 16, 2))); } @Test public void testForChunkStretched() { - assertTrue(latestVersion.isEqualOrHigher(MinecraftVersion.NETHER)); - assertFalse(latestVersion.isLower(new MinecraftVersion(1, 14, 2))); + assertTrue(latestVersion.isEqualOrHigherThan(MinecraftVersion.NETHER)); + assertFalse(latestVersion.isLowerThan(new MinecraftVersion(1, 14, 2))); } }