mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 14:38:52 +00:00
enhance(rtp): Ensure that random teleport respects the vanilla worldborder.
This commit is contained in:
1 parent
63a8f7b7d8
commit
8cb21f19a0
1 file changed
+9
-2
@@ -47,7 +47,10 @@ public class RandomPoint extends TeleportationPoint {
|
||||
double blockCenterZ = 0.5;
|
||||
|
||||
// The furthest distance at which a player can be teleported to
|
||||
int rtpRange = HuskHomes.getSettings().getRtpRange();
|
||||
int rtpRange = Math.min(
|
||||
HuskHomes.getSettings().getRtpRange(),
|
||||
(int) world.getWorldBorder().getSize() - 1
|
||||
);
|
||||
|
||||
// Calculate random X and Z coords
|
||||
x = random.nextInt(rtpRange);
|
||||
@@ -72,7 +75,7 @@ public class RandomPoint extends TeleportationPoint {
|
||||
}
|
||||
|
||||
// Checks to see if the location is safe to teleport to
|
||||
private boolean isLocationSafe(Location location){
|
||||
private boolean isLocationSafe(Location location) {
|
||||
int x = location.getBlockX();
|
||||
int y = location.getBlockY()-1;
|
||||
int z = location.getBlockZ();
|
||||
@@ -81,6 +84,10 @@ public class RandomPoint extends TeleportationPoint {
|
||||
|
||||
// Failsafe check in case the world is null
|
||||
if (world != null) {
|
||||
// Ensure we are inside of the world border.
|
||||
if (!world.getWorldBorder().isInside(location)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get instances of the blocks around where the player would teleport
|
||||
Block block = world.getBlockAt(x, y, z);
|
||||
|
||||
Reference in new issue
Block a user