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 @@ -67,6 +67,7 @@ public final class MainConfig extends ATConfig {
public ConfigOption<Boolean> MONITOR_ALL_TELEPORTS;
public PerCommandOption<Integer> DISTANCE_LIMITS;
public ConfigOption<ConfigSection> CUSTOM_DISTANCE_LIMITS;
public ConfigOption<ConfigSection> WARP_DISTANCE_OVERRIDES;
public ConfigOption<Boolean> ENABLE_TELEPORT_LIMITATIONS;
public ConfigOption<Boolean> MONITOR_ALL_TELEPORTS_LIMITS;
public ConfigOption<ConfigSection> WORLD_RULES;
Expand Down Expand Up @@ -497,6 +498,18 @@ The key (vip-distance) and group name (VIP) do not have to be different, this is
To combine the two, you can use at.member.distance.<command>.<world>.vip-distance.\
""");

makeSectionLenient("warp-distance-overrides");
addComment(
"warp-distance-overrides",
"""
Set a specific distance limit for individual warps.
Use -1 to remove the distance limit entirely for that warp.
Example:
warp-distance-overrides:
caverns: -1
temple: 5000\
""");

addSection("Teleportation Limitations");

addComment(
Expand Down Expand Up @@ -1145,6 +1158,7 @@ public void postSave() {
new PerCommandOption<>(
"per-command-distance-limitations", "maximum-teleport-distance");
CUSTOM_DISTANCE_LIMITS = new ConfigOption<>("custom-distance-limitations");
WARP_DISTANCE_OVERRIDES = new ConfigOption<>("warp-distance-overrides");

ENABLE_TELEPORT_LIMITATIONS = new ConfigOption<>("enable-teleport-limitations");
MONITOR_ALL_TELEPORTS_LIMITS = new ConfigOption<>("monitor-all-teleports-limitations");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ public void onTeleport(ATTeleportEvent e) {
e.getFromLocation(),
e.getToLocation(),
e.getType().getName(),
e.getPlayer());
e.getPlayer(),
e.getLocName());
if (result != null) {
CustomMessages.sendMessage(
e.getPlayer(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ public class ConditionChecker {

public static @Nullable String canTeleport(
Location fromLoc, Location toLoc, String command, Player teleportingPlayer) {
return canTeleport(fromLoc, toLoc, command, teleportingPlayer, null);
}

public static @Nullable String canTeleport(
Location fromLoc, Location toLoc, String command, Player teleportingPlayer,
@Nullable String locName) {

// Use debug print
CoreClass.debug(
Expand All @@ -81,7 +87,7 @@ public class ConditionChecker {
&& !teleportingPlayer.hasPermission("at.admin.bypass.distance-limit")
&& fromLoc.getWorld() == toLoc.getWorld()
&& !DistanceLimiter.canTeleport(
toLoc, fromLoc, command, ATPlayer.getPlayer(teleportingPlayer))) {
toLoc, fromLoc, command, ATPlayer.getPlayer(teleportingPlayer), locName)) {
return "Error.tooFarAway";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,38 @@
import io.github.niestrat99.advancedteleport.api.ATPlayer;
import io.github.niestrat99.advancedteleport.config.MainConfig;

import io.github.thatsmusic99.configurationmaster.api.ConfigSection;
import org.bukkit.Location;
import org.jetbrains.annotations.Nullable;

public class DistanceLimiter {

public static boolean canTeleport(
Location loc1, Location loc2, String command, ATPlayer player) {
return canTeleport(loc1, loc2, command, player, null);
}

public static boolean canTeleport(
Location loc1, Location loc2, String command, ATPlayer player, @Nullable String locName) {
if (command == null && !MainConfig.get().MONITOR_ALL_TELEPORTS.get()) return true;

// Check for per-warp distance overrides when the command is "warp"
if ("warp".equalsIgnoreCase(command) && locName != null && !locName.isEmpty()) {
ConfigSection overrides = MainConfig.get().WARP_DISTANCE_OVERRIDES.get();
if (overrides != null) {
Object overrideValue = overrides.get(locName);
if (overrideValue != null) {
int overrideDistance = overrides.getInteger(locName);
if (overrideDistance == -1) return true;
if (overrideDistance > 0) {
if (!MainConfig.get().ENABLE_DISTANCE_LIMITATIONS.get()) return true;
if (loc1.getWorld() != loc2.getWorld()) return true;
return loc1.distanceSquared(loc2) < (long) overrideDistance * overrideDistance;
}
}
}
}

int allowedDistance = player.getDistanceLimitation(command, loc2.getWorld());
if (MainConfig.get().ENABLE_DISTANCE_LIMITATIONS.get() && allowedDistance > 0) {
if (loc1.getWorld() != loc2.getWorld()) return true;
Expand Down
7 changes: 7 additions & 0 deletions config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,13 @@ per-command-distance-limitations:
# Distance limit for /back
back: default

# Per-warp distance overrides.
# Set a specific distance limit for individual warps.
# Use -1 to remove the distance limit entirely for that warp.
# warp-distance-overrides:
# caverns: -1
# temple: 5000

###############################
# Teleportation Limitations #
###############################
Expand Down