diff --git a/common/src/main/java/net/william278/huskhomes/database/MySqlDatabase.java b/common/src/main/java/net/william278/huskhomes/database/MySqlDatabase.java index 9d5f7490..3ab61e44 100644 --- a/common/src/main/java/net/william278/huskhomes/database/MySqlDatabase.java +++ b/common/src/main/java/net/william278/huskhomes/database/MySqlDatabase.java @@ -634,6 +634,7 @@ public class MySqlDatabase extends Database { new Server(resultSet.getString("server_name")))) .setType(TeleportType.getTeleportType(resultSet.getInt("type")) .orElse(TeleportType.TELEPORT)) + .doUpdateLastPosition(false) .toTeleport() .join()); } diff --git a/common/src/main/java/net/william278/huskhomes/database/SqLiteDatabase.java b/common/src/main/java/net/william278/huskhomes/database/SqLiteDatabase.java index 49cc5d0d..bafda450 100644 --- a/common/src/main/java/net/william278/huskhomes/database/SqLiteDatabase.java +++ b/common/src/main/java/net/william278/huskhomes/database/SqLiteDatabase.java @@ -630,6 +630,7 @@ public class SqLiteDatabase extends Database { new Server(resultSet.getString("server_name")))) .setType(TeleportType.getTeleportType(resultSet.getInt("type")) .orElse(TeleportType.TELEPORT)) + .doUpdateLastPosition(false) .toTeleport() .join()); } diff --git a/common/src/main/java/net/william278/huskhomes/teleport/Teleport.java b/common/src/main/java/net/william278/huskhomes/teleport/Teleport.java index 8555e557..d36b37f2 100644 --- a/common/src/main/java/net/william278/huskhomes/teleport/Teleport.java +++ b/common/src/main/java/net/william278/huskhomes/teleport/Teleport.java @@ -60,18 +60,24 @@ public class Teleport { @NotNull public final Set economyActions; + /** + * Whether to update the {@link #teleporter teleporter}'s last position (i.e. their {@code /back} position) + */ + public final boolean updateLastPosition; + /** * Internal - use TeleportBuilder to instantiate a teleport */ protected Teleport(@Nullable User teleporter, @NotNull OnlineUser executor, @Nullable Position target, @NotNull TeleportType type, @NotNull Set economyActions, - @NotNull HuskHomes plugin) { + final boolean updateLastPosition, @NotNull HuskHomes plugin) { this.teleporter = teleporter; this.executor = executor; this.target = target; this.type = type; this.economyActions = economyActions; this.plugin = plugin; + this.updateLastPosition = updateLastPosition; } /** @@ -167,7 +173,7 @@ public class Teleport { // Dispatch the teleport event and update the player's last position plugin.getEventDispatcher().dispatchTeleportEvent(this); - if (!plugin.getSettings().backCommandSaveOnTeleportEvent && type == TeleportType.TELEPORT) { + if (updateLastPosition && !plugin.getSettings().backCommandSaveOnTeleportEvent && type == TeleportType.TELEPORT) { plugin.getDatabase().setLastPosition(teleporter, teleporter.getPosition()); } diff --git a/common/src/main/java/net/william278/huskhomes/teleport/TeleportBuilder.java b/common/src/main/java/net/william278/huskhomes/teleport/TeleportBuilder.java index 49e9ab6f..e7283916 100644 --- a/common/src/main/java/net/william278/huskhomes/teleport/TeleportBuilder.java +++ b/common/src/main/java/net/william278/huskhomes/teleport/TeleportBuilder.java @@ -57,6 +57,11 @@ public class TeleportBuilder { */ private TeleportType type = TeleportType.TELEPORT; + /** + * Whether this teleport should update the user's last position (i.e. their {@code /back} position) + */ + private boolean updateLastPosition = true; + protected TeleportBuilder(@NotNull HuskHomes plugin, @NotNull OnlineUser executor) { this.plugin = plugin; this.executor = executor; @@ -168,6 +173,17 @@ public class TeleportBuilder { return this; } + /** + * Set whether this teleport should update the user's last position (i.e. their {@code /back} position) + * + * @param updateLastPosition Whether this teleport should update the user's last position + * @return The {@link TeleportBuilder} instance + */ + public TeleportBuilder doUpdateLastPosition(boolean updateLastPosition) { + this.updateLastPosition = updateLastPosition; + return this; + } + /** * Resolve the teleporter and target, and construct as an instantly-completing {@link Teleport} * @@ -178,7 +194,7 @@ public class TeleportBuilder { final User teleporter = this.teleporter.join(); final Position target = this.target.join(); - return new Teleport(teleporter, executor, target, type, economyActions, plugin); + return new Teleport(teleporter, executor, target, type, economyActions, updateLastPosition, plugin); }).exceptionally(e -> { plugin.getLoggingAdapter().log(Level.SEVERE, "Failed to create teleport", e); return null; @@ -200,7 +216,7 @@ public class TeleportBuilder { throw new IllegalStateException("Timed teleports can only be executed for local users"); } - return new TimedTeleport(onlineUser, executor, target, type, warmupTime, economyActions, plugin); + return new TimedTeleport(onlineUser, executor, target, type, warmupTime, economyActions, updateLastPosition, plugin); }).exceptionally(e -> { plugin.getLoggingAdapter().log(Level.SEVERE, "Failed to create timed teleport", e); return null; diff --git a/common/src/main/java/net/william278/huskhomes/teleport/TimedTeleport.java b/common/src/main/java/net/william278/huskhomes/teleport/TimedTeleport.java index 881b464f..c4c7ee4f 100644 --- a/common/src/main/java/net/william278/huskhomes/teleport/TimedTeleport.java +++ b/common/src/main/java/net/william278/huskhomes/teleport/TimedTeleport.java @@ -25,8 +25,8 @@ public class TimedTeleport extends Teleport { protected TimedTeleport(@NotNull OnlineUser teleporter, @NotNull OnlineUser executor, @NotNull Position target, @NotNull TeleportType type, int warmupTime, @NotNull Set economyActions, - @NotNull HuskHomes plugin) { - super(teleporter, executor, target, type, economyActions, plugin); + final boolean updateLastPosition, @NotNull HuskHomes plugin) { + super(teleporter, executor, target, type, economyActions, updateLastPosition, plugin); this.plugin = plugin; this.startLocation = teleporter.getPosition(); this.startHealth = teleporter.getHealth();