Add updateLastPosition setting to Teleport, fix back position setting cross-server

This commit is contained in:
William committed 2022-11-22 23:05:58 +00:00
1 parent 8edb2073ac
commit 9a34ecdee6
5 files changed
+30 -6

No files matched your search

@@ -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());
}
@@ -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());
}
@@ -60,18 +60,24 @@ public class Teleport {
@NotNull
public final Set<Settings.EconomyAction> economyActions;
/**
* Whether to update the {@link #teleporter teleporter}'s last position (i.e. their {@code /back} position)
*/
public final boolean updateLastPosition;
/**
* <b>Internal</b> - use TeleportBuilder to instantiate a teleport
*/
protected Teleport(@Nullable User teleporter, @NotNull OnlineUser executor, @Nullable Position target,
@NotNull TeleportType type, @NotNull Set<Settings.EconomyAction> 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());
}
@@ -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;
@@ -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<Settings.EconomyAction> 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();