From e11a023b50e584039235bfa30bf18c579b39a5ea Mon Sep 17 00:00:00 2001 From: ThisKarolGajda Date: Tue, 15 Aug 2023 18:12:41 +0200 Subject: [PATCH] 1.8.1.1 --- .../opc/api/tools/runnable/OpRunnable.java | 33 ++++++++----------- .../opc/api/tools/teleport/OpTeleport.java | 9 +++-- 2 files changed, 17 insertions(+), 25 deletions(-) diff --git a/src/main/java/me/opkarol/opc/api/tools/runnable/OpRunnable.java b/src/main/java/me/opkarol/opc/api/tools/runnable/OpRunnable.java index a0e55f4..a9673ac 100644 --- a/src/main/java/me/opkarol/opc/api/tools/runnable/OpRunnable.java +++ b/src/main/java/me/opkarol/opc/api/tools/runnable/OpRunnable.java @@ -1,8 +1,8 @@ package me.opkarol.opc.api.tools.runnable; import me.opkarol.opc.OpAPI; +import org.bukkit.Bukkit; import org.bukkit.scheduler.BukkitRunnable; -import org.bukkit.scheduler.BukkitTask; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -10,9 +10,10 @@ import java.util.function.Consumer; public class OpRunnable implements Serializable { - private BukkitTask task; + private int taskId; private final BukkitRunnable bukkitRunnable; + public OpRunnable(Consumer consumer) { OpRunnable runnable = this; @@ -33,63 +34,55 @@ public OpRunnable(Runnable runnable) { return new OpRunnable(consumer); } - public OpRunnable set(Consumer consumer) { - return this; - } - - public boolean cancelTask() { - if (this.task != null && !this.task.isCancelled()) { - this.task.cancel(); - return true; - } - return false; + public void cancelTask() { + Bukkit.getScheduler().cancelTask(taskId); } @NotNull public synchronized OpRunnable runTaskLaterAsynchronously(long delay) throws IllegalArgumentException, IllegalStateException { - this.task = bukkitRunnable.runTaskLaterAsynchronously(OpAPI.getPlugin(), delay); + this.taskId = bukkitRunnable.runTaskLaterAsynchronously(OpAPI.getPlugin(), delay).getTaskId(); return this; } @NotNull public synchronized OpRunnable runTask() throws IllegalArgumentException, IllegalStateException { - this.task = bukkitRunnable.runTask(OpAPI.getPlugin()); + this.taskId = bukkitRunnable.runTask(OpAPI.getPlugin()).getTaskId(); return this; } @NotNull public synchronized OpRunnable runTaskLater(long delay) throws IllegalArgumentException, IllegalStateException { - this.task = bukkitRunnable.runTaskLater(OpAPI.getPlugin(), delay); + this.taskId = bukkitRunnable.runTaskLater(OpAPI.getPlugin(), delay).getTaskId(); return this; } @NotNull public synchronized OpRunnable runTaskTimerAsynchronously(long delay, long period) throws IllegalArgumentException, IllegalStateException { - this.task = bukkitRunnable.runTaskTimerAsynchronously(OpAPI.getPlugin(), delay, period); + this.taskId = bukkitRunnable.runTaskTimerAsynchronously(OpAPI.getPlugin(), delay, period).getTaskId(); return this; } @NotNull public synchronized OpRunnable runTaskTimerAsynchronously(long delay) throws IllegalArgumentException, IllegalStateException { - this.task = bukkitRunnable.runTaskTimerAsynchronously(OpAPI.getPlugin(), delay, delay); + this.taskId = bukkitRunnable.runTaskTimerAsynchronously(OpAPI.getPlugin(), delay, delay).getTaskId(); return this; } @NotNull public synchronized OpRunnable runTaskTimer(long delay, long period) throws IllegalArgumentException, IllegalStateException { - this.task = bukkitRunnable.runTaskTimer(OpAPI.getPlugin(), delay, period); + this.taskId = bukkitRunnable.runTaskTimer(OpAPI.getPlugin(), delay, period).getTaskId(); return this; } @NotNull public synchronized OpRunnable runTaskTimer(long delay) throws IllegalArgumentException, IllegalStateException { - this.task = bukkitRunnable.runTaskTimer(OpAPI.getPlugin(), delay, delay); + this.taskId = bukkitRunnable.runTaskTimer(OpAPI.getPlugin(), delay, delay).getTaskId(); return this; } @NotNull public synchronized OpRunnable runTaskAsynchronously() throws IllegalArgumentException, IllegalStateException { - this.task = bukkitRunnable.runTaskAsynchronously(OpAPI.getPlugin()); + this.taskId = bukkitRunnable.runTaskAsynchronously(OpAPI.getPlugin()).getTaskId(); return this; } } diff --git a/src/main/java/me/opkarol/opc/api/tools/teleport/OpTeleport.java b/src/main/java/me/opkarol/opc/api/tools/teleport/OpTeleport.java index 44b58c6..b543c98 100644 --- a/src/main/java/me/opkarol/opc/api/tools/teleport/OpTeleport.java +++ b/src/main/java/me/opkarol/opc/api/tools/teleport/OpTeleport.java @@ -273,11 +273,10 @@ public void cancel(String message, Player player) { public void cancel(String message, OpList players) { if (getTask() != null) { - if (task.cancelTask()) { - if (players != null) { - final String finalMessage = FormatUtils.formatMessage(message); - players.forEach(player -> player.sendMessage(finalMessage)); - } + task.cancelTask(); + if (players != null) { + final String finalMessage = FormatUtils.formatMessage(message); + players.forEach(player -> player.sendMessage(finalMessage)); } } }