mirror of
https://github.com/Phoenix616/RandomTeleport.git
synced 2024-11-25 12:06:15 +01:00
Added min and max y settings (Resolves #2)
Max y will be 127 in the nether by default. Use the -maxY parameter to change it. Also once a maxY is set it will try to find a random y between the values if the highest block is above the max y value.
This commit is contained in:
parent
8eb93d138e
commit
081d217053
@ -149,6 +149,20 @@ public class RandomTeleport extends JavaPlugin implements RandomTeleportAPI {
|
||||
}
|
||||
return false;
|
||||
}));
|
||||
addOptionParser(new SimpleOptionParser(array("miny"), (searcher, args) -> {
|
||||
if (args.length > 0) {
|
||||
searcher.setMinY(Integer.parseInt(args[0]));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}));
|
||||
addOptionParser(new SimpleOptionParser(array("maxy"), (searcher, args) -> {
|
||||
if (args.length > 0) {
|
||||
searcher.setMaxY(Integer.parseInt(args[0]));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}));
|
||||
addOptionParser(new SimpleOptionParser(array("w", "world"), (searcher, args) -> {
|
||||
if (args.length > 0) {
|
||||
World world = getServer().getWorld(args[0]);
|
||||
|
@ -28,6 +28,7 @@ import io.papermc.lib.PaperLib;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
@ -68,6 +69,8 @@ public class RandomSearcher {
|
||||
private Location center;
|
||||
private int minRadius = 0;
|
||||
private int maxRadius = Integer.MAX_VALUE;
|
||||
private int minY = 0;
|
||||
private int maxY;
|
||||
private boolean loadedOnly = false;
|
||||
private boolean generatedOnly = false;
|
||||
private int maxTries = 100;
|
||||
@ -85,6 +88,11 @@ public class RandomSearcher {
|
||||
setCenter(center);
|
||||
setMinRadius(minRadius);
|
||||
setMaxRadius(maxRadius);
|
||||
if (center.getWorld().getEnvironment() == World.Environment.NETHER) {
|
||||
maxY = 127;
|
||||
} else {
|
||||
maxY = center.getWorld().getMaxHeight();
|
||||
}
|
||||
this.validators.getRaw().putAll(plugin.getLocationValidators().getRaw());
|
||||
Arrays.asList(validators).forEach(this.validators::add);
|
||||
}
|
||||
@ -216,6 +224,40 @@ public class RandomSearcher {
|
||||
this.maxRadius = maxRadius;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the minimum Y
|
||||
* @return The minimum Y, always positive and less than the max Y!
|
||||
*/
|
||||
public int getMinY() {
|
||||
return minY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the minimum search Y
|
||||
* @param minY The min Y; has to be positive and less than the max Y!
|
||||
*/
|
||||
public void setMinY(int minY) {
|
||||
Validate.isTrue(minY >= 0 && minY < maxY, "Min Y has to be positive and less than the max Y!");
|
||||
this.minY = minY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the maximum Y
|
||||
* @return The maximum Y, always greater than the minimum Y
|
||||
*/
|
||||
public int getMaxY() {
|
||||
return maxY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the maximum search Y
|
||||
* @param maxY The max Y; has to be greater than the min Y!
|
||||
*/
|
||||
public void setMaxY(int maxY) {
|
||||
Validate.isTrue(maxY > minY, "Max Y has to be greater than the min Y!");
|
||||
this.maxY = maxY;
|
||||
}
|
||||
|
||||
/**
|
||||
* By default it will search for coordinates in any chunk, even unloaded ones prompting the server to load new
|
||||
* chunks which might result in some performance impact if the server doesn't support async loading. This disables
|
||||
|
@ -32,9 +32,16 @@ public class HeightValidator extends LocationValidator {
|
||||
@Override
|
||||
public boolean validate(RandomSearcher searcher, Location location) {
|
||||
Block block = location.getWorld().getHighestBlockAt(location);
|
||||
if (block.getY() > searcher.getMaxY()) {
|
||||
block = location.getWorld().getBlockAt(
|
||||
block.getX(),
|
||||
searcher.getMinY() + searcher.getRandom().nextInt(searcher.getMaxY() - searcher.getMinY()),
|
||||
block.getZ()
|
||||
);
|
||||
}
|
||||
while (block.isEmpty()) {
|
||||
block = block.getRelative(BlockFace.DOWN);
|
||||
if (block == null || block.getY() == 0) {
|
||||
if (block == null || block.getY() < searcher.getMinY()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,8 @@ commands:
|
||||
> -b,-biome <biomename> [<biome 2> ...] - only teleport to this biome (multiple allowed, Bukkit biome names!)
|
||||
> -x,-xPos <x value> - x axis of the center point, if not set the player's x axis is used
|
||||
> -z,-zPos <z value> - z axis of the center point, if not set the player's z axis is used
|
||||
> -minY <y value> - minimum y value that the random location should have (default: 0)
|
||||
> -maxY <y value> - maximum y value that the random location should have (default: world height, half in nether)
|
||||
> -l,-loaded - only search loaded chunks for possible locations (might fail more often)
|
||||
> -g,-generated - only search generated chunks for possible locations
|
||||
> -c, -cooldown <seconds> - cooldown in seconds after which the player can use this teleporter again
|
||||
|
Loading…
Reference in New Issue
Block a user