Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add a getNextHighesBlock method to the plotspawn teleportation #4352

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,43 @@ public int getHighestBlockSynchronous(final @NonNull String world, final int x,
return bukkitWorld.getMaxHeight() - 1;
}

@Override
public int getNextHighestBlockSynchronous(
@NonNull final String world,
final int x,
final int y,
final int z
) {
final World bukkitWorld = Objects.requireNonNull(getWorld(world));
int maxY = com.plotsquared.bukkit.util.BukkitWorld.getMaxWorldHeight(bukkitWorld);
for (int current = y; current <= maxY; current++) {
Block block = bukkitWorld.getBlockAt(x, current, z);
Material type = block.getType();
if (!type.isSolid() || block.isLiquid()) {
return current;
}
}
return bukkitWorld.getMaxHeight() - 1;
}

@Override
public void getNextHighestBlock(final @NonNull String world, final int x, final int y, final int z,
@NonNull IntConsumer result) {
ensureLoaded(world, x, z, chunk -> {
final World bukkitWorld = Objects.requireNonNull(getWorld(world));
int maxY = com.plotsquared.bukkit.util.BukkitWorld.getMaxWorldHeight(bukkitWorld);
for (int current = y; current <= maxY; current++) {
Block block = bukkitWorld.getBlockAt(x, current, z);
Material type = block.getType();
if (!type.isSolid() || block.isLiquid()) {
result.accept(current);
return;
}
}
result.accept(bukkitWorld.getMaxHeight() - 1);
});
}

@Override
public @NonNull String[] getSignSynchronous(final @NonNull Location location) {
Block block = Objects.requireNonNull(getWorld(location.getWorldName())).getBlockAt(
Expand Down
7 changes: 4 additions & 3 deletions Core/src/main/java/com/plotsquared/core/plot/Plot.java
Original file line number Diff line number Diff line change
Expand Up @@ -1422,9 +1422,10 @@ public Location getHomeSynchronous() {
Location location = toHomeLocation(bottom, home);
if (!this.worldUtil.getBlockSynchronous(location).getBlockType().getMaterial().isAir()) {
location = location.withY(
Math.max(1 + this.worldUtil.getHighestBlockSynchronous(
Math.max(1 + this.worldUtil.getNextHighestBlockSynchronous(
this.getWorldName(),
location.getX(),
location.getY(),
location.getZ()
), bottom.getY()));
}
Expand Down Expand Up @@ -1455,8 +1456,8 @@ public void getHome(final Consumer<Location> result) {
Location location = toHomeLocation(bottom, home);
this.worldUtil.getBlock(location, block -> {
if (!block.getBlockType().getMaterial().isAir()) {
this.worldUtil.getHighestBlock(this.getWorldName(), location.getX(), location.getZ(),
y -> result.accept(location.withY(Math.max(1 + y, bottom.getY())))
this.worldUtil.getNextHighestBlock(this.getWorldName(), location.getX(), location.getY(), location.getZ(),
y -> result.accept(location.withY(Math.max(y, bottom.getY())))
);
} else {
result.accept(location);
Expand Down
22 changes: 22 additions & 0 deletions Core/src/main/java/com/plotsquared/core/util/WorldUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,28 @@ public abstract void setSign(
@NonNegative
public abstract int getHighestBlockSynchronous(@NonNull String world, int x, int z);

/**
* Get the Y coordinate of the next highest non-air block in the world, asynchronously
*
* @param world World name
* @param x X coordinate
* @param y Y coordinate
* @param z Z coordinate
* @param result Result consumer
*/
public abstract void getNextHighestBlock(@NonNull String world, int x, int y, int z, @NonNull IntConsumer result);

/**
* Get the Y coordinate of the next highest non-air block in the world, synchronously
*
* @param world World name
* @param x X coordinate
* @param y Y coordinate
* @param z Z coordinate
* @return Result
*/
public abstract int getNextHighestBlockSynchronous(@NonNull String world, int x, int y, int z);

/**
* Set the biome in a region
*
Expand Down
Loading