Skip to content

Commit

Permalink
1.8.1
Browse files Browse the repository at this point in the history
- hopefully fixed runnable bug
  • Loading branch information
ThisKarolGajda committed Aug 15, 2023
1 parent 837eafd commit c9b3bfc
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 31 deletions.
41 changes: 21 additions & 20 deletions src/main/java/me/opkarol/opc/api/tools/runnable/OpRunnable.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,86 +9,87 @@
import java.io.Serializable;
import java.util.function.Consumer;

public class OpRunnable extends BukkitRunnable implements Serializable {
private Consumer<OpRunnable> consumer;
public class OpRunnable implements Serializable {
private BukkitTask task;
private final BukkitRunnable bukkitRunnable;

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

bukkitRunnable = new BukkitRunnable() {
@Override
public void run() {
consumer.accept(runnable);
}
};
}

public OpRunnable(Runnable runnable) {
this.consumer = (r) -> runnable.run();
this(runnable1 -> runnable.run());
}

@Contract("_ -> new")
public static @NotNull OpRunnable get(Consumer<OpRunnable> consumer) {
return new OpRunnable(consumer);
}

@Override
public void run() {
this.consumer.accept(this);
}

public OpRunnable set(Consumer<OpRunnable> consumer) {
this.consumer = consumer;
return this;
}

public boolean cancelTask() {
if (task != null && !task.isCancelled()) {
task.cancel();
if (this.task != null && !this.task.isCancelled()) {
this.task.cancel();
return true;
}
return false;
}

@NotNull
public synchronized OpRunnable runTaskLaterAsynchronously(long delay) throws IllegalArgumentException, IllegalStateException {
this.task = super.runTaskLaterAsynchronously(OpAPI.getPlugin(), delay);
this.task = bukkitRunnable.runTaskLaterAsynchronously(OpAPI.getPlugin(), delay);
return this;
}

@NotNull
public synchronized OpRunnable runTask() throws IllegalArgumentException, IllegalStateException {
this.task = super.runTask(OpAPI.getPlugin());
this.task = bukkitRunnable.runTask(OpAPI.getPlugin());
return this;
}

@NotNull
public synchronized OpRunnable runTaskLater(long delay) throws IllegalArgumentException, IllegalStateException {
this.task = super.runTaskLater(OpAPI.getPlugin(), delay);
this.task = bukkitRunnable.runTaskLater(OpAPI.getPlugin(), delay);
return this;
}

@NotNull
public synchronized OpRunnable runTaskTimerAsynchronously(long delay, long period) throws IllegalArgumentException, IllegalStateException {
this.task = super.runTaskTimerAsynchronously(OpAPI.getPlugin(), delay, period);
this.task = bukkitRunnable.runTaskTimerAsynchronously(OpAPI.getPlugin(), delay, period);
return this;
}

@NotNull
public synchronized OpRunnable runTaskTimerAsynchronously(long delay) throws IllegalArgumentException, IllegalStateException {
this.task = super.runTaskTimerAsynchronously(OpAPI.getPlugin(), delay, delay);
this.task = bukkitRunnable.runTaskTimerAsynchronously(OpAPI.getPlugin(), delay, delay);
return this;
}

@NotNull
public synchronized OpRunnable runTaskTimer(long delay, long period) throws IllegalArgumentException, IllegalStateException {
this.task = super.runTaskTimer(OpAPI.getPlugin(), delay, period);
this.task = bukkitRunnable.runTaskTimer(OpAPI.getPlugin(), delay, period);
return this;
}

@NotNull
public synchronized OpRunnable runTaskTimer(long delay) throws IllegalArgumentException, IllegalStateException {
this.task = super.runTaskTimer(OpAPI.getPlugin(), delay, delay);
this.task = bukkitRunnable.runTaskTimer(OpAPI.getPlugin(), delay, delay);
return this;
}

@NotNull
public synchronized OpRunnable runTaskAsynchronously() throws IllegalArgumentException, IllegalStateException {
this.task = super.runTaskAsynchronously(OpAPI.getPlugin());
this.task = bukkitRunnable.runTaskAsynchronously(OpAPI.getPlugin());
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public synchronized void runTaskTimesDown(BiConsumer<OpRunnable, Integer> onEach
new OpRunnable(r -> {
if (i[0] < 1) {
onEndConsumer.accept(r);
r.cancel();
r.cancelTask();
}
onEachConsumer.accept(r, i[0]);
i[0]--;
Expand All @@ -22,7 +22,7 @@ public synchronized void runTaskTimesUp(BiConsumer<OpRunnable, Integer> onEachCo
new OpRunnable(r -> {
if (i[0] >= times) {
onEndConsumer.accept(r);
r.cancel();
r.cancelTask();
}
onEachConsumer.accept(r, i[0]);
i[0]++;
Expand All @@ -34,7 +34,7 @@ public OpRunnable runTaskTimesDownAsynchronously(BiConsumer<OpRunnable, Integer>
return new OpRunnable(r -> {
if (i[0] < 1) {
onEndConsumer.accept(r);
r.cancel();
r.cancelTask();
}
onEachConsumer.accept(r, i[0]);
i[0]--;
Expand All @@ -45,7 +45,7 @@ public OpRunnable runTaskTimesDownAsynchronously(BiConsumer<OpRunnable, Integer>
final int[] i = {times};
return new OpRunnable(r -> {
if (i[0] < 1) {
r.cancel();
r.cancelTask();
}
onEachConsumer.accept(r, i[0]);
i[0]--;
Expand All @@ -57,7 +57,7 @@ public synchronized void runTaskTimesUpAsynchronously(BiConsumer<OpRunnable, Int
new OpRunnable(r -> {
if (i[0] > times) {
onEndConsumer.accept(r);
r.cancel();
r.cancelTask();
}
onEachConsumer.accept(r, i[0]);
i[0]++;
Expand All @@ -68,7 +68,7 @@ public synchronized void runTaskTimesUpAsynchronously(BiConsumer<OpRunnable, Int
final int[] i = {1};
new OpRunnable(r -> {
if (i[0] > times) {
r.cancel();
r.cancelTask();
}
onEachConsumer.accept(r, i[0]);
i[0]++;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/me/opkarol/opc/api/utils/StringUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ public static boolean isBoolean(Object obj) {
return false;
}


public static double getDouble(Object object) {
if (object == null) {
return getDoubleFromString(null);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/me/opkarol/opc/api/wrappers/OpActionBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public OpActionBar sendLooped(int times) {
runnable = new OpRunnable(r -> {
if (i[0] < 1) {
sendEmpty();
r.cancel();
r.cancelTask();
} else {
build(text.replace("%time%", String.valueOf(i[0]))).send();
}
Expand All @@ -96,7 +96,7 @@ public OpActionBar sendEmpty() {
}

public void cancel() {
runnable.cancel();
runnable.cancelTask();
}

public String getText() {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/me/opkarol/opc/api/wrappers/OpParticle.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public OpParticle animateDisplay(int amount, int delay) {
final int[] i = {0};
animatedTask = new OpRunnable(r -> {
if (i[0] >= amount) {
r.cancel();
r.cancelTask();
}

display();
Expand All @@ -214,7 +214,7 @@ public OpParticle displayByNearPlayers(Player byPlayer, int reach) {
}

public void cancelAnimatedTask() {
animatedTask.cancel();
animatedTask.cancelTask();
}

@Override
Expand Down

0 comments on commit c9b3bfc

Please sign in to comment.