mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-04 14:38:53 +00:00
Add updateLastPosition setting to Teleport, fix back position setting cross-server
This commit is contained in:
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"))))
|
new Server(resultSet.getString("server_name"))))
|
||||||
.setType(TeleportType.getTeleportType(resultSet.getInt("type"))
|
.setType(TeleportType.getTeleportType(resultSet.getInt("type"))
|
||||||
.orElse(TeleportType.TELEPORT))
|
.orElse(TeleportType.TELEPORT))
|
||||||
|
.doUpdateLastPosition(false)
|
||||||
.toTeleport()
|
.toTeleport()
|
||||||
.join());
|
.join());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -630,6 +630,7 @@ public class SqLiteDatabase extends Database {
|
|||||||
new Server(resultSet.getString("server_name"))))
|
new Server(resultSet.getString("server_name"))))
|
||||||
.setType(TeleportType.getTeleportType(resultSet.getInt("type"))
|
.setType(TeleportType.getTeleportType(resultSet.getInt("type"))
|
||||||
.orElse(TeleportType.TELEPORT))
|
.orElse(TeleportType.TELEPORT))
|
||||||
|
.doUpdateLastPosition(false)
|
||||||
.toTeleport()
|
.toTeleport()
|
||||||
.join());
|
.join());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,18 +60,24 @@ public class Teleport {
|
|||||||
@NotNull
|
@NotNull
|
||||||
public final Set<Settings.EconomyAction> economyActions;
|
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
|
* <b>Internal</b> - use TeleportBuilder to instantiate a teleport
|
||||||
*/
|
*/
|
||||||
protected Teleport(@Nullable User teleporter, @NotNull OnlineUser executor, @Nullable Position target,
|
protected Teleport(@Nullable User teleporter, @NotNull OnlineUser executor, @Nullable Position target,
|
||||||
@NotNull TeleportType type, @NotNull Set<Settings.EconomyAction> economyActions,
|
@NotNull TeleportType type, @NotNull Set<Settings.EconomyAction> economyActions,
|
||||||
@NotNull HuskHomes plugin) {
|
final boolean updateLastPosition, @NotNull HuskHomes plugin) {
|
||||||
this.teleporter = teleporter;
|
this.teleporter = teleporter;
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
this.target = target;
|
this.target = target;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.economyActions = economyActions;
|
this.economyActions = economyActions;
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
this.updateLastPosition = updateLastPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -167,7 +173,7 @@ public class Teleport {
|
|||||||
|
|
||||||
// Dispatch the teleport event and update the player's last position
|
// Dispatch the teleport event and update the player's last position
|
||||||
plugin.getEventDispatcher().dispatchTeleportEvent(this);
|
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());
|
plugin.getDatabase().setLastPosition(teleporter, teleporter.getPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,6 +57,11 @@ public class TeleportBuilder {
|
|||||||
*/
|
*/
|
||||||
private TeleportType type = TeleportType.TELEPORT;
|
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) {
|
protected TeleportBuilder(@NotNull HuskHomes plugin, @NotNull OnlineUser executor) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
@@ -168,6 +173,17 @@ public class TeleportBuilder {
|
|||||||
return this;
|
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}
|
* 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 User teleporter = this.teleporter.join();
|
||||||
final Position target = this.target.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 -> {
|
}).exceptionally(e -> {
|
||||||
plugin.getLoggingAdapter().log(Level.SEVERE, "Failed to create teleport", e);
|
plugin.getLoggingAdapter().log(Level.SEVERE, "Failed to create teleport", e);
|
||||||
return null;
|
return null;
|
||||||
@@ -200,7 +216,7 @@ public class TeleportBuilder {
|
|||||||
throw new IllegalStateException("Timed teleports can only be executed for local users");
|
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 -> {
|
}).exceptionally(e -> {
|
||||||
plugin.getLoggingAdapter().log(Level.SEVERE, "Failed to create timed teleport", e);
|
plugin.getLoggingAdapter().log(Level.SEVERE, "Failed to create timed teleport", e);
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ public class TimedTeleport extends Teleport {
|
|||||||
|
|
||||||
protected TimedTeleport(@NotNull OnlineUser teleporter, @NotNull OnlineUser executor, @NotNull Position target,
|
protected TimedTeleport(@NotNull OnlineUser teleporter, @NotNull OnlineUser executor, @NotNull Position target,
|
||||||
@NotNull TeleportType type, int warmupTime, @NotNull Set<Settings.EconomyAction> economyActions,
|
@NotNull TeleportType type, int warmupTime, @NotNull Set<Settings.EconomyAction> economyActions,
|
||||||
@NotNull HuskHomes plugin) {
|
final boolean updateLastPosition, @NotNull HuskHomes plugin) {
|
||||||
super(teleporter, executor, target, type, economyActions, plugin);
|
super(teleporter, executor, target, type, economyActions, updateLastPosition, plugin);
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.startLocation = teleporter.getPosition();
|
this.startLocation = teleporter.getPosition();
|
||||||
this.startHealth = teleporter.getHealth();
|
this.startHealth = teleporter.getHealth();
|
||||||
|
|||||||
Reference in new issue
Block a user