From b8d686d9d31452565613d341dd502b0994ffcc4e Mon Sep 17 00:00:00 2001 From: Phoenix616 Date: Sun, 22 May 2022 12:37:24 +0100 Subject: [PATCH] Re-add backwards support down to 1.13 Also update PaperLib dependency and repo --- pom.xml | 6 +++--- .../randomteleport/RandomTeleport.java | 19 +++++++++++++++++++ .../searcher/RandomSearcher.java | 7 ++++--- .../src/main/resources/plugin.yml | 2 +- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 539ddc9..4fb074b 100644 --- a/pom.xml +++ b/pom.xml @@ -40,7 +40,7 @@ paper-repo - https://papermc.io/repo/repository/maven-public/ + https://repo.papermc.io/repository/maven-public/ minebench-repo @@ -52,13 +52,13 @@ org.spigotmc spigot-api - 1.17.1-R0.1-SNAPSHOT + 1.16.5-R0.1-SNAPSHOT provided io.papermc paperlib - 1.0.6 + 1.0.7 compile diff --git a/randomteleport-plugin/src/main/java/de/themoep/randomteleport/RandomTeleport.java b/randomteleport-plugin/src/main/java/de/themoep/randomteleport/RandomTeleport.java index 672603b..47a9a2b 100644 --- a/randomteleport-plugin/src/main/java/de/themoep/randomteleport/RandomTeleport.java +++ b/randomteleport-plugin/src/main/java/de/themoep/randomteleport/RandomTeleport.java @@ -83,6 +83,8 @@ public class RandomTeleport extends JavaPlugin implements RandomTeleportAPI { private Material[] unsafeBlocks; private Set signVariables; + private boolean hasMinHeight = true; + public void onEnable() { hookManager = new HookManager(this); loadConfig(); @@ -481,4 +483,21 @@ public class RandomTeleport extends JavaPlugin implements RandomTeleportAPI { public RandomSearcher getRandomSearcher(Player player, Location origin, int minRange, int maxRange, LocationValidator... validators) { return new RandomSearcher(this, player, origin, minRange, maxRange, validators); } + + /** + * Utility method to get the min height of a world as old versions didn't have support for this. + * @param world The world + * @return The min height or 0 if querying that isn't supported + */ + public int getMinHeight(World world) { + if (hasMinHeight) { + try { + return world.getMinHeight(); + } catch (NoSuchMethodError ignored) { + // getMinHeight is only available starting in 1.16.5 + } + hasMinHeight = false; + } + return 0; + } } diff --git a/randomteleport-plugin/src/main/java/de/themoep/randomteleport/searcher/RandomSearcher.java b/randomteleport-plugin/src/main/java/de/themoep/randomteleport/searcher/RandomSearcher.java index 4724a19..b076a5f 100644 --- a/randomteleport-plugin/src/main/java/de/themoep/randomteleport/searcher/RandomSearcher.java +++ b/randomteleport-plugin/src/main/java/de/themoep/randomteleport/searcher/RandomSearcher.java @@ -90,7 +90,7 @@ public class RandomSearcher { setCenter(center); setMinRadius(minRadius); setMaxRadius(maxRadius); - minY = center.getWorld().getMinHeight(); + minY = plugin.getMinHeight(center.getWorld()); if (center.getWorld().getEnvironment() == World.Environment.NETHER) { maxY = 126; } else { @@ -257,7 +257,8 @@ public class RandomSearcher { * @param minY The min Y; has to be positive and less than the max Y! */ public void setMinY(int minY) { - Validate.isTrue(minY >= center.getWorld().getMinHeight() && minY < maxY, "Min Y has to be at least the world's minimum height and less than the max Y!"); + Validate.isTrue(minY >= plugin.getMinHeight(center.getWorld()), "Min Y has to be at least the world's minimum height!"); + Validate.isTrue(minY < maxY, "Min Y has to be less than the max Y!"); this.minY = minY; } @@ -362,7 +363,7 @@ public class RandomSearcher { } lastCheck = center.getWorld().getTime(); Location randomLoc = center.clone(); - randomLoc.setY(center.getWorld().getMinHeight()); + randomLoc.setY(plugin.getMinHeight(center.getWorld())); int minChunk = minRadius >> 4; int maxChunk = maxRadius >> 4; int randChunkX; diff --git a/randomteleport-plugin/src/main/resources/plugin.yml b/randomteleport-plugin/src/main/resources/plugin.yml index 22b1c08..dfe3132 100644 --- a/randomteleport-plugin/src/main/resources/plugin.yml +++ b/randomteleport-plugin/src/main/resources/plugin.yml @@ -2,7 +2,7 @@ name: RandomTeleport provides: [FUBSRandomTeleport] main: de.themoep.randomteleport.RandomTeleport version: '${minecraft.plugin.version}' -api-version: 1.17 +api-version: 1.13 description: ${project.description} author: Phoenix616 website: https://github.com/Phoenix616/RandomTeleport/