mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-03 06:28:49 +00:00
Teleport types, cross-server respawn handling
This commit is contained in:
1 parent
8dff4a123a
commit
f74f77c62d
17 files changed
+192
-33
No files matched your search
@@ -21,8 +21,15 @@ public class Teleport {
|
||||
@NotNull
|
||||
public Position target;
|
||||
|
||||
public Teleport(@NotNull User player, @NotNull Position target) {
|
||||
/**
|
||||
* The type of the teleport
|
||||
*/
|
||||
@NotNull
|
||||
public TeleportType type;
|
||||
|
||||
public Teleport(@NotNull User player, @NotNull Position target, @NotNull TeleportType type) {
|
||||
this.player = player;
|
||||
this.target = target;
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
@@ -301,15 +301,29 @@ public class TeleportManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Carries out a teleport, teleporting a {@link OnlineUser} to a specified {@link Position} and returning
|
||||
* a future that will return a {@link TeleportResult}
|
||||
* Carries out a teleport, teleporting a {@link OnlineUser} to a specified {@link Position} with a TeleportType of
|
||||
* {@link TeleportType#TELEPORT} and returning a future that will return a {@link TeleportResult}
|
||||
*
|
||||
* @param onlineUser the {@link OnlineUser} to teleport
|
||||
* @param position the target {@link Position} to teleport to#
|
||||
* @param position the target {@link Position} to teleport to
|
||||
* @return a {@link CompletableFuture} that completes when the teleport is complete with the {@link TeleportResult}
|
||||
*/
|
||||
public CompletableFuture<TeleportResult> teleport(@NotNull OnlineUser onlineUser, @NotNull Position position) {
|
||||
final Teleport teleport = new Teleport(onlineUser, position);
|
||||
return teleport(onlineUser, position, TeleportType.TELEPORT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Carries out a teleport, teleporting a {@link OnlineUser} to a specified {@link Position} and returning
|
||||
* a future that will return a {@link TeleportResult}
|
||||
*
|
||||
* @param onlineUser the {@link OnlineUser} to teleport
|
||||
* @param position the target {@link Position} to teleport to
|
||||
* @param teleportType the {@link TeleportType} of the teleport
|
||||
* @return a {@link CompletableFuture} that completes when the teleport is complete with the {@link TeleportResult}
|
||||
*/
|
||||
public CompletableFuture<TeleportResult> teleport(@NotNull OnlineUser onlineUser, @NotNull Position position,
|
||||
@NotNull TeleportType teleportType) {
|
||||
final Teleport teleport = new Teleport(onlineUser, position, teleportType);
|
||||
return onlineUser.getPosition().thenApply(preTeleportPosition -> plugin.getDatabase()
|
||||
.setLastPosition(onlineUser, preTeleportPosition) // Update the player's last position
|
||||
.thenApply(ignored -> plugin.getServer(onlineUser).thenApply(server -> {
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package net.william278.huskhomes.teleport;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Represents the type of teleport being used
|
||||
*/
|
||||
public enum TeleportType {
|
||||
|
||||
TELEPORT(0),
|
||||
RESPAWN(1);
|
||||
|
||||
public final int typeId;
|
||||
|
||||
TeleportType(final int typeId) {
|
||||
this.typeId = typeId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link TeleportType} by its type id.
|
||||
*
|
||||
* @param typeId The type id of the {@link TeleportType} to return.
|
||||
* @return The {@link TeleportType} of the given type id.
|
||||
*/
|
||||
public static Optional<TeleportType> getTeleportType(int typeId) {
|
||||
return Arrays.stream(values())
|
||||
.filter(type -> type.typeId == typeId)
|
||||
.findFirst();
|
||||
}
|
||||
}
|
||||
@@ -6,19 +6,15 @@ import net.william278.huskhomes.position.Position;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Represents a {@link Teleport} due to occur
|
||||
* Represents a {@link Teleport} due to occur after a warmup period
|
||||
*/
|
||||
public class TimedTeleport {
|
||||
|
||||
private final OnlineUser onlineUser;
|
||||
private final Position targetPosition;
|
||||
|
||||
private final Location startLocation;
|
||||
private final double startHealth;
|
||||
|
||||
private final int duration;
|
||||
protected int timeLeft;
|
||||
|
||||
public boolean cancelled = false;
|
||||
|
||||
protected TimedTeleport(@NotNull OnlineUser onlineUser, @NotNull Position targetPosition, int duration) {
|
||||
@@ -26,7 +22,6 @@ public class TimedTeleport {
|
||||
this.targetPosition = targetPosition;
|
||||
this.startLocation = onlineUser.getLocation();
|
||||
this.startHealth = onlineUser.getHealth();
|
||||
this.duration = duration;
|
||||
this.timeLeft = duration;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user