mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-03 22:16:34 +00:00
More refactor work, encapsulate classes
This commit is contained in:
1 parent
3e1ec09487
commit
1cebdac9b8
51 files changed
+756
-621
No files matched your search
@@ -178,27 +178,24 @@ public class Teleport {
|
||||
}
|
||||
|
||||
// If the target position is local, finalize economy transactions and teleport the player
|
||||
if (!plugin.getSettings().isCrossServer() || target.server.equals(plugin.getServerName())) {
|
||||
if (!plugin.getSettings().isCrossServer() || target.getServer().equals(plugin.getServerName())) {
|
||||
return teleporter.teleportLocally(target, plugin.getSettings().isAsynchronousTeleports());
|
||||
}
|
||||
|
||||
// If the target position is on another server, execute a cross-server teleport
|
||||
final CompletableFuture<TeleportResult> teleportFuture = new CompletableFuture<>();
|
||||
plugin.getDatabase()
|
||||
.setCurrentTeleport(teleporter, this)
|
||||
.thenApply(ignored -> plugin
|
||||
.getMessenger()
|
||||
.sendPlayer(teleporter, target.server)
|
||||
.thenApply(completed -> completed
|
||||
? TeleportResult.COMPLETED_CROSS_SERVER
|
||||
: TeleportResult.FAILED_INVALID_SERVER))
|
||||
plugin.getDatabase().setCurrentTeleport(teleporter, this);
|
||||
plugin.getMessenger()
|
||||
.sendPlayer(teleporter, target.getServer())
|
||||
.thenApply(completed -> completed
|
||||
? TeleportResult.COMPLETED_CROSS_SERVER
|
||||
: TeleportResult.FAILED_INVALID_SERVER)
|
||||
.orTimeout(10, TimeUnit.SECONDS)
|
||||
.exceptionally(throwable -> {
|
||||
plugin.getLoggingAdapter().log(Level.WARNING, "Cross-server teleport timed out for " + teleporter.username);
|
||||
plugin.getDatabase().setCurrentTeleport(teleporter, null);
|
||||
return CompletableFuture.completedFuture(TeleportResult.FAILED_INVALID_SERVER);
|
||||
})
|
||||
.thenAccept(result -> result.thenAcceptAsync(teleportFuture::complete));
|
||||
return TeleportResult.FAILED_INVALID_SERVER;
|
||||
});
|
||||
return teleportFuture;
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ public class TimedTeleport extends Teleport {
|
||||
}
|
||||
|
||||
// Check if the teleporter is already warming up to teleport
|
||||
if (plugin.getCache().currentlyOnWarmup.contains(teleporter.uuid)) {
|
||||
if (plugin.getCache().getCurrentlyOnWarmup().contains(teleporter.uuid)) {
|
||||
return CompletableFuture.completedFuture(TeleportResult.FAILED_ALREADY_TELEPORTING)
|
||||
.thenApply(resultState -> CompletedTeleport.from(resultState, this));
|
||||
}
|
||||
@@ -98,7 +98,7 @@ public class TimedTeleport extends Teleport {
|
||||
}
|
||||
|
||||
// Mark the player as warming up and display the message
|
||||
plugin.getCache().currentlyOnWarmup.add(teleporter.uuid);
|
||||
plugin.getCache().getCurrentlyOnWarmup().add(teleporter.uuid);
|
||||
plugin.getLocales().getLocale("teleporting_warmup_start", Integer.toString(timeLeft))
|
||||
.ifPresent(teleporter::sendMessage);
|
||||
|
||||
@@ -118,7 +118,7 @@ public class TimedTeleport extends Teleport {
|
||||
|
||||
// Tick (decrement) the timed teleport timer and end it if done
|
||||
if (tickWarmup()) {
|
||||
plugin.getCache().currentlyOnWarmup.remove(teleporter.uuid);
|
||||
plugin.getCache().getCurrentlyOnWarmup().remove(teleporter.uuid);
|
||||
timedTeleportFuture.complete(null);
|
||||
executor.shutdown();
|
||||
}
|
||||
@@ -195,9 +195,9 @@ public class TimedTeleport extends Teleport {
|
||||
*/
|
||||
private boolean hasTeleporterMoved() {
|
||||
final double maxMovementDistance = 0.1d;
|
||||
double movementDistance = Math.abs(startLocation.x - teleporter.getPosition().x) +
|
||||
Math.abs(startLocation.y - teleporter.getPosition().y) +
|
||||
Math.abs(startLocation.z - teleporter.getPosition().z);
|
||||
double movementDistance = Math.abs(startLocation.getX() - teleporter.getPosition().getX()) +
|
||||
Math.abs(startLocation.getY() - teleporter.getPosition().getY()) +
|
||||
Math.abs(startLocation.getZ() - teleporter.getPosition().getZ());
|
||||
return movementDistance > maxMovementDistance;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user