Database design, start callback-based implementation planning

This commit is contained in:
William committed 2022-05-21 02:53:58 +01:00
1 parent 0446db39c5
commit 8e7d5e74a0
17 files changed
+672 -92

No files matched your search

@@ -5,14 +5,12 @@ import net.william278.huskhomes.player.Player;
import net.william278.huskhomes.position.Position;
import org.jetbrains.annotations.NotNull;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
/**
* Cross-platform teleportation manager
*/
public abstract class TeleportManager {
public class TeleportManager {
/**
* Instance of the implementing plugin
@@ -20,35 +18,29 @@ public abstract class TeleportManager {
@NotNull
private final HuskHomes plugin;
/**
* {@link Set} of currently processing teleports
*/
@NotNull
private final Set<CompletableFuture<Teleport>> processingTeleports;
public TeleportManager(@NotNull HuskHomes plugin) {
this.plugin = plugin;
this.processingTeleports = new HashSet<>();
}
/**
* Teleport the player to a specified {@link Position}
*
* @param position the target {@link Position} to teleport to
* @return A {@link CompletableFuture} callback returning the {@link TeleportResult} of completing the teleport
*/
public CompletableFuture<TeleportResult> teleport(Player player, Position position) {
final Teleport teleport = new Teleport(player, position);
if (position.server.equals(plugin.getServerData())) {
return teleportLocally(new Teleport(player, position));
return player.teleport(teleport.target);
} else {
return teleportCrossServer(new Teleport(player, position));
return teleportCrossServer(teleport);
}
}
public abstract CompletableFuture<TeleportResult> teleportLocally(Teleport teleport);
private CompletableFuture<TeleportResult> teleportCrossServer(Teleport teleport) {
return null; //todo dispatch cross-server message here!
return CompletableFuture.supplyAsync(() -> {
return TeleportResult.COMPLETED_CROSS_SERVER;
});
}
}
@@ -9,9 +9,14 @@ import net.william278.huskhomes.position.World;
public enum TeleportResult {
/**
* Returns if the {@link Teleport} completed successfully
* Returns if the {@link Teleport} was completed locally, successfully
*/
SUCCESS(true),
COMPLETED_LOCALLY(true),
/**
* Returns if the {@link Teleport} was completed cross-server
*/
COMPLETED_CROSS_SERVER(true),
/**
* Returns if the {@link Teleport} failed because the {@link World} of the
@@ -32,7 +37,14 @@ public enum TeleportResult {
* target {@link Position} were outside the world border limits
* <p>
*/
FAILED_INVALID_COORDINATES(false);
FAILED_ILLEGAL_COORDINATES(false),
/**
* Returns if the {@link Teleport} failed because the coordinates of the
* target {@link Position} were in an unsafe spot
* <p>
*/
FAILED_UNSAFE(false);
/**
* Is {@code true} if the teleport was a success