Start command refactor

This commit is contained in:
William278 committed 2023-03-05 19:10:19 +00:00
1 parent 39e0b25d46
commit 3e27f7c5b1
57 files changed
+728 -384

No files matched your search

@@ -44,6 +44,9 @@ public class Teleport {
public void execute() throws TeleportationException {
final Optional<OnlineUser> localTeleporter = resolveLocalTeleporter();
// Validate economy actions
validateEconomyActions();
// Teleport a user on another server
if (localTeleporter.isEmpty()) {
final Username teleporter = (Username) this.teleporter;
@@ -73,11 +76,13 @@ public class Teleport {
if (target instanceof Username username) {
final Optional<OnlineUser> localTarget = username.findLocally(plugin);
if (localTarget.isPresent()) {
economyActions.forEach(action -> plugin.performEconomyTransaction(executor, action));
teleporter.teleportLocally(localTarget.get().getPosition(), async);
return;
}
if (plugin.getSettings().isCrossServer()) {
economyActions.forEach(action -> plugin.performEconomyTransaction(executor, action));
Message.builder()
.type(Message.Type.TELEPORT_TO_NETWORKED_POSITION)
.target(username.name())
@@ -87,6 +92,7 @@ public class Teleport {
throw new TeleportationException(TeleportationException.Type.TARGET_NOT_FOUND);
}
economyActions.forEach(action -> plugin.performEconomyTransaction(executor, action));
teleporter.teleportLocally((Position) target, async);
}
@@ -98,6 +104,16 @@ public class Teleport {
return Optional.of((OnlineUser) this.teleporter);
}
// Check economy actions
protected void validateEconomyActions() throws TeleportationException {
economyActions.stream()
.map(action -> plugin.validateEconomyCheck(executor, action))
.filter(result -> !result).findFirst()
.ifPresent(result -> {
throw new TeleportationException(TeleportationException.Type.ECONOMY_ACTION_FAILED);
});
}
@NotNull
public Type getType() {
return type;
@@ -117,7 +133,6 @@ public class Teleport {
* Represents the type of teleport being used
*/
public enum Type {
TELEPORT(0),
RESPAWN(1);
@@ -32,12 +32,7 @@ public class TimedTeleport extends Teleport {
this.teleporter = teleporter;
}
/**
* Execute the timed teleport, ticking the countdown and teleporting the player when the countdown is complete
*
* @return a {@link CompletableFuture} that completes when the teleport is complete or has been cancelled
*/
@Override
@Override
public void execute() throws TeleportationException {
// Check if the teleporter can bypass warmup
if (timeLeft == 0 || teleporter.hasPermission(Permission.BYPASS_TELEPORT_WARMUP.node)) {
@@ -50,12 +45,8 @@ public class TimedTeleport extends Teleport {
throw new TeleportationException(TeleportationException.Type.ALREADY_WARMING_UP);
}
// Check economy actions
for (EconomyHook.Action action : economyActions) {
if (!plugin.validateEconomyCheck(executor, action)) {
throw new TeleportationException(TeleportationException.Type.ECONOMY_ACTION_FAILED);
}
}
// Validate economy actions
validateEconomyActions();
// Check if they are moving at the start of the teleport
if (teleporter.isMoving()) {