Re-add backwards support down to 1.13

Also update PaperLib dependency and repo
This commit is contained in:
Phoenix616 2022-05-22 12:37:24 +01:00
parent c30af21608
commit b8d686d9d3
No known key found for this signature in database
GPG Key ID: 40E2321E71738EB0
4 changed files with 27 additions and 7 deletions

View File

@ -40,7 +40,7 @@
</repository>
<repository>
<id>paper-repo</id>
<url>https://papermc.io/repo/repository/maven-public/</url>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
<repository>
<id>minebench-repo</id>
@ -52,13 +52,13 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.17.1-R0.1-SNAPSHOT</version>
<version>1.16.5-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.papermc</groupId>
<artifactId>paperlib</artifactId>
<version>1.0.6</version>
<version>1.0.7</version>
<scope>compile</scope>
</dependency>
<dependency>

View File

@ -83,6 +83,8 @@ public class RandomTeleport extends JavaPlugin implements RandomTeleportAPI {
private Material[] unsafeBlocks;
private Set<String> 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;
}
}

View File

@ -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;

View File

@ -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/