mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-01 22:16:08 +00:00
Use UUIDs for task tracking
This commit is contained in:
8 files changed
+47
-45
No files matched your search
@@ -28,7 +28,8 @@ import net.william278.huskhomes.user.OnlineUser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
/**
|
||||
* Represents a {@link Teleport} that has an associated warmup time; the teleport will not be performed until the
|
||||
@@ -87,7 +88,7 @@ public class TimedTeleport extends Teleport {
|
||||
.ifPresent(teleporter::sendMessage);
|
||||
|
||||
// Run the warmup
|
||||
final AtomicInteger warmupTaskId = new AtomicInteger();
|
||||
final AtomicReference<UUID> warmupTaskId = new AtomicReference<>();
|
||||
final Runnable countdownRunnable = (() -> {
|
||||
// Display a countdown action bar message
|
||||
if (timeLeft > 0) {
|
||||
|
||||
@@ -22,6 +22,7 @@ package net.william278.huskhomes.util;
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Supplier;
|
||||
@@ -34,25 +35,17 @@ public interface TaskRunner {
|
||||
|
||||
void runSync(@NotNull Runnable runnable);
|
||||
|
||||
int runAsyncRepeating(@NotNull Runnable runnable, long delay);
|
||||
@NotNull
|
||||
UUID runAsyncRepeating(@NotNull Runnable runnable, long delay);
|
||||
|
||||
void runLater(@NotNull Runnable runnable, long delay);
|
||||
|
||||
void cancelTask(int taskId);
|
||||
void cancelTask(@NotNull UUID taskId);
|
||||
|
||||
void cancelAllTasks();
|
||||
|
||||
@NotNull
|
||||
ConcurrentHashMap<Integer, ?> getTasks();
|
||||
|
||||
default int getNextTaskId() {
|
||||
int taskId = 0;
|
||||
while (getTasks().containsKey(taskId)) {
|
||||
taskId++;
|
||||
}
|
||||
return taskId;
|
||||
}
|
||||
|
||||
ConcurrentHashMap<UUID, ?> getTasks();
|
||||
@NotNull
|
||||
HuskHomes getPlugin();
|
||||
|
||||
|
||||
Reference in new issue
Block a user