Skip to content
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 @@ -541,7 +541,7 @@ private void registerCommands(
}, messageContainer),
new RemoveCommand(messageContainer),
new SignCommand(paperApi, executorState, messageContainer),
new TeleportCommand(getLogger(), paperApi, messageContainer, safeLocationFinder),
new TeleportCommand(getLogger(), paperApi, this.settings, messageContainer, safeLocationFinder),
new SubregionCommandGroup(paperApi, this.settings, messageContainer),
new CleanupCommandGroup(this.database,
executorState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.github.md5sha256.realty.database.entity.RealtySignEntity;
import io.github.md5sha256.realty.localisation.MessageContainer;
import io.github.md5sha256.realty.localisation.MessageKeys;
import io.github.md5sha256.realty.settings.Settings;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.bukkit.Bukkit;
import org.bukkit.Location;
Expand All @@ -23,6 +24,7 @@
import org.jetbrains.annotations.Nullable;

import java.util.UUID;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.CompletableFuture;
import java.util.logging.Logger;

Expand All @@ -37,6 +39,7 @@
public record TeleportCommand(
@NotNull Logger logger,
@NotNull RealtyPaperApi api,
@NotNull AtomicReference<Settings> settings,
@NotNull MessageContainer messages,
@NotNull SafeLocationFinder safeLocationFinder) implements CustomCommandBean.Single {

Expand Down Expand Up @@ -110,7 +113,7 @@ private void execute(@NotNull CommandContext<Source> ctx) {
return CompletableFuture.completedFuture(loc);
}
return safeLocationFinder.findSafeInRegion(
region.region(), region.world(), REGION_MAX_TRIES);
region.region(), region.world(), REGION_MAX_TRIES, settings.get().teleportStartHeight());
}).whenComplete((loc, ex) -> processTeleport(player, regionId, loc, ex));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,23 @@ private static boolean defaultIsSafe(@NotNull Block feetBlock) {
public @NotNull CompletableFuture<@Nullable Location> findSafeInRegion(
@NotNull ProtectedRegion region,
@NotNull World world,
int maxTries) {
int maxTries,
int teleportStartHeight) {

BlockVector3 min = region.getMinimumPoint();
BlockVector3 max = region.getMaximumPoint();

int startX = (min.x() + max.x()) / 2;
int startY = (min.y() + max.y()) / 2;
int startY;
int startZ = (min.z() + max.z()) / 2;

// Start searching around the configued level (ground level) for tall plots
if (max.y() - min.y() >= 100 && teleportStartHeight <= max.y() && teleportStartHeight >= min.y()) {
startY = teleportStartHeight;
} else {
startY = (min.y() + max.y()) / 2;
}

// Load center chunk and check center first
return world.getChunkAtAsync(Math.floorDiv(startX, 16), Math.floorDiv(startZ, 16))
.thenCompose(chunk -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public record Settings(
@Setting("profile-reapply-per-tick") int profileReapplyPerTick,
@Setting("subregion-min-volume") int subregionMinVolume,
@Setting("offer-payment-duration-seconds") long offerPaymentDurationSeconds,
@Setting("subregion-tag-blacklist") @NotNull List<String> subregionTagBlacklist
@Setting("subregion-tag-blacklist") @NotNull List<String> subregionTagBlacklist,
@Setting("teleportation-starting-height") int teleportStartHeight
) {

public Settings {
Expand Down
5 changes: 4 additions & 1 deletion realty-paper/src/main/resources/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ subregion-min-volume: 20
offer-payment-duration-seconds: 86400
# Tag IDs that prevent a parent region from being subregioned.
# If a region has any of these tags, it cannot be used as a parent for subregion creation.
subregion-tag-blacklist: []
subregion-tag-blacklist: []
# Y-level at which the safe location finder will start looking in the case of very tall plots.
# It's advisable to set this just above the average ground level of your map.
teleportation-starting-height: 80