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

Improve teleport behavior for home command #4369

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -261,6 +261,11 @@ public void getHighestBlock(final @NonNull String world, final int x, final int
});
}

@Override
public boolean isSmallBlock(Location location) {
return adapt(location).getBlock().getBoundingBox().getHeight() < 0.25;
}

@Override
@NonNegative
public int getHighestBlockSynchronous(final @NonNull String world, final int x, final int z) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,8 @@ public static final class Teleport {
public static boolean PER_WORLD_VISIT = false;
@Comment("Search merged plots for having multiple owners when using the visit command")
public static boolean VISIT_MERGED_OWNERS = true;
@Comment("Allows to teleport based on block size instead to spawn on the highest block at the home command")
public static boolean SIZED_BASED = true;

}

Expand Down
27 changes: 18 additions & 9 deletions Core/src/main/java/com/plotsquared/core/plot/Plot.java
Original file line number Diff line number Diff line change
Expand Up @@ -1420,6 +1420,9 @@ public Location getHomeSynchronous() {
);
}
Location location = toHomeLocation(bottom, home);
if (Settings.Teleport.SIZED_BASED && this.worldUtil.isSmallBlock(location) && this.worldUtil.isSmallBlock(location.add(0,1,0))) {
return location;
}
if (!this.worldUtil.getBlockSynchronous(location).getBlockType().getMaterial().isAir()) {
location = location.withY(
Math.max(1 + this.worldUtil.getHighestBlockSynchronous(
Expand Down Expand Up @@ -1453,15 +1456,21 @@ public void getHome(final Consumer<Location> result) {
}
Location bottom = this.getBottomAbs();
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())))
);
} else {
result.accept(location);
}
});
if (Settings.Teleport.SIZED_BASED && this.worldUtil.isSmallBlock(location) && this.worldUtil.isSmallBlock(location.add(0,1,0))) {
result.accept(location);
} else {
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())))
);
} else {
result.accept(location);
}
});
}

}
}

Expand Down
7 changes: 7 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 @@ -168,6 +168,13 @@ public abstract void setSign(
*/
public abstract void getBlock(@NonNull Location location, @NonNull Consumer<BlockState> result);

/**
* Checks if the block smaller as a slab
* @param location Block location
* @return true if it smaller as a slab
*/
public abstract boolean isSmallBlock(@NonNull Location location);

/**
* Get the block at a given location (synchronously)
*
Expand Down
Loading