From e4082b3831088a8bd5d6cf115f6aaaec2ebe4423 Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Sat, 10 Aug 2024 20:39:37 -0500 Subject: [PATCH 1/2] Refactor assault task --- .../movecraft/warfare/commands/AssaultCommand.java | 2 +- .../warfare/features/assault/tasks/AssaultBeginTask.java | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/countercraft/movecraft/warfare/commands/AssaultCommand.java b/src/main/java/net/countercraft/movecraft/warfare/commands/AssaultCommand.java index 2eb0653..8416d47 100644 --- a/src/main/java/net/countercraft/movecraft/warfare/commands/AssaultCommand.java +++ b/src/main/java/net/countercraft/movecraft/warfare/commands/AssaultCommand.java @@ -119,7 +119,7 @@ public boolean onCommand(@NotNull CommandSender commandSender, Command command, } AssaultBeginTask beginTask = new AssaultBeginTask(player, assault); - beginTask.runTaskLater(Movecraft.getInstance(), (20L * Config.AssaultDelay)); + beginTask.runTaskTimer(Movecraft.getInstance(), 20, 20); AssaultBroadcastEvent event = new AssaultBroadcastEvent(assault, broadcast, AssaultBroadcastEvent.Type.PRESTART); diff --git a/src/main/java/net/countercraft/movecraft/warfare/features/assault/tasks/AssaultBeginTask.java b/src/main/java/net/countercraft/movecraft/warfare/features/assault/tasks/AssaultBeginTask.java index 325147d..0de5211 100644 --- a/src/main/java/net/countercraft/movecraft/warfare/features/assault/tasks/AssaultBeginTask.java +++ b/src/main/java/net/countercraft/movecraft/warfare/features/assault/tasks/AssaultBeginTask.java @@ -1,5 +1,6 @@ package net.countercraft.movecraft.warfare.features.assault.tasks; +import net.countercraft.movecraft.warfare.config.Config; import net.countercraft.movecraft.warfare.features.assault.Assault; import net.countercraft.movecraft.warfare.features.assault.events.AssaultBroadcastEvent; import net.countercraft.movecraft.warfare.features.assault.events.AssaultStartEvent; @@ -15,14 +16,19 @@ public class AssaultBeginTask extends BukkitRunnable { private final Player player; private final Assault assault; + private final long start; public AssaultBeginTask(Player player, Assault assault) { this.player = player; this.assault = assault; + start = System.currentTimeMillis(); } @Override public void run() { + if (System.currentTimeMillis() - start < Config.AssaultDelay * 1000L) + return; + if (assault.getSavedCorrectly().get() != Assault.SavedState.SAVED) { player.sendMessage( MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Repair - Could not save file")); From 35ff12e91290197e7db40c05ff3d6a7156ec975e Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Sat, 10 Aug 2024 20:41:37 -0500 Subject: [PATCH 2/2] Update AssaultBeginTask.java --- .../warfare/features/assault/tasks/AssaultBeginTask.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/net/countercraft/movecraft/warfare/features/assault/tasks/AssaultBeginTask.java b/src/main/java/net/countercraft/movecraft/warfare/features/assault/tasks/AssaultBeginTask.java index 0de5211..a2f6a9b 100644 --- a/src/main/java/net/countercraft/movecraft/warfare/features/assault/tasks/AssaultBeginTask.java +++ b/src/main/java/net/countercraft/movecraft/warfare/features/assault/tasks/AssaultBeginTask.java @@ -29,6 +29,7 @@ public void run() { if (System.currentTimeMillis() - start < Config.AssaultDelay * 1000L) return; + cancel(); if (assault.getSavedCorrectly().get() != Assault.SavedState.SAVED) { player.sendMessage( MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Repair - Could not save file"));