mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-30 14:43:49 +01:00
this should be better
This commit is contained in:
parent
6f01310f92
commit
f91ed4705a
@ -1,15 +1,6 @@
|
|||||||
package world.bentobox.bentobox.util.teleport;
|
package world.bentobox.bentobox.util.teleport;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import org.bukkit.*;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChunkSnapshot;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.World.Environment;
|
import org.bukkit.World.Environment;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
@ -17,13 +8,17 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.database.objects.Island;
|
import world.bentobox.bentobox.database.objects.Island;
|
||||||
import world.bentobox.bentobox.util.Pair;
|
import world.bentobox.bentobox.util.Pair;
|
||||||
import world.bentobox.bentobox.util.Util;
|
import world.bentobox.bentobox.util.Util;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class that calculates finds a safe spot asynchronously and then teleports the player there.
|
* A class that calculates finds a safe spot asynchronously and then teleports the player there.
|
||||||
* @author tastybento
|
* @author tastybento
|
||||||
@ -231,17 +226,19 @@ public class SafeSpotTeleport {
|
|||||||
*/
|
*/
|
||||||
private boolean scanChunk(ChunkSnapshot chunk) {
|
private boolean scanChunk(ChunkSnapshot chunk) {
|
||||||
int startY = location.getBlockY();
|
int startY = location.getBlockY();
|
||||||
int minY = location.getWorld().getMinHeight() + 1;
|
int minY = location.getWorld().getMinHeight();
|
||||||
int maxY = maxHeight;
|
int maxY = 60; // Just a dummy value
|
||||||
|
|
||||||
// Check the safe spot at the current height
|
// Check the safe spot at the current height
|
||||||
for (int x = 0; x < 16; x++) {
|
for (int x = 0; x < 16; x++) {
|
||||||
for (int z = 0; z < 16; z++) {
|
for (int z = 0; z < 16; z++) {
|
||||||
if (minY >= startY && startY <= maxY && checkBlock(chunk, x, startY ,z)) {
|
if (minY >= startY && checkBlock(chunk, x, startY, z)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
maxY = Math.max(chunk.getHighestBlockYAt(x, z), maxY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
maxY = Math.min(maxY, maxHeight);
|
||||||
|
|
||||||
// Expand the height up and down until a safe spot is found
|
// Expand the height up and down until a safe spot is found
|
||||||
int upperY = startY + 1;
|
int upperY = startY + 1;
|
||||||
@ -251,23 +248,25 @@ public class SafeSpotTeleport {
|
|||||||
while (checkUpper || checkLower) {
|
while (checkUpper || checkLower) {
|
||||||
for (int x = 0; x < 16; x++) {
|
for (int x = 0; x < 16; x++) {
|
||||||
for (int z = 0; z < 16; z++) {
|
for (int z = 0; z < 16; z++) {
|
||||||
if (checkUpper && upperY <= maxY && checkBlock(chunk, x, upperY, z)) {
|
if (checkUpper && checkBlock(chunk, x, upperY, z)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (checkLower && lowerY >= minY && checkBlock(chunk, x, lowerY, z)) {
|
if (checkLower && checkBlock(chunk, x, lowerY, z)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (checkUpper) {
|
||||||
|
upperY++;
|
||||||
if (upperY > maxY) {
|
if (upperY > maxY) {
|
||||||
checkUpper = false;
|
checkUpper = false;
|
||||||
} else {
|
|
||||||
upperY++;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (checkLower) {
|
||||||
|
lowerY--;
|
||||||
if (lowerY < minY) {
|
if (lowerY < minY) {
|
||||||
checkLower = false;
|
checkLower = false;
|
||||||
} else {
|
}
|
||||||
lowerY--;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user