Skip to content

Commit

Permalink
1.8.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ThisKarolGajda committed Aug 15, 2023
1 parent c9b3bfc commit e11a023
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 25 deletions.
33 changes: 13 additions & 20 deletions src/main/java/me/opkarol/opc/api/tools/runnable/OpRunnable.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
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;

import java.io.Serializable;
import java.util.function.Consumer;

public class OpRunnable implements Serializable {
private BukkitTask task;
private int taskId;
private final BukkitRunnable bukkitRunnable;


public OpRunnable(Consumer<OpRunnable> consumer) {
OpRunnable runnable = this;

Expand All @@ -33,63 +34,55 @@ public OpRunnable(Runnable runnable) {
return new OpRunnable(consumer);
}

public OpRunnable set(Consumer<OpRunnable> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,10 @@ public void cancel(String message, Player player) {

public void cancel(String message, OpList<Player> 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));
}
}
}
Expand Down

0 comments on commit e11a023

Please sign in to comment.