Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: make scheduler methods return BukkitTask and add NonNull Annotation #253

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 16 additions & 34 deletions src/main/java/minevalley/core/api/Core.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.bukkit.metadata.MetadataValue;
import org.bukkit.metadata.Metadatable;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.Vector;

import javax.annotation.Nonnull;
Expand All @@ -72,7 +73,7 @@
import java.util.function.Consumer;
import java.util.stream.Collectors;

@SuppressWarnings("unused")
@SuppressWarnings({"unused", "UnusedReturnValue"})
public final class Core {

private static CoreServer server;
Expand All @@ -81,56 +82,36 @@ public static JavaPlugin getInstance() {
return server.getInstance();
}

public static int runSyncTaskNow(Runnable runnable) {
@Nonnull
public static BukkitTask runSyncTaskNow(@Nonnull Runnable runnable) {
return server.runSyncTaskLater(0, runnable);
}

public static int runAsyncTaskNow(Runnable runnable) {
@Nonnull
public static BukkitTask runAsyncTaskNow(@Nonnull Runnable runnable) {
return server.runAsyncTaskLater(0, runnable);
}

public static int runSyncTaskLater(long delay, Runnable runnable) {
@Nonnull
public static BukkitTask runSyncTaskLater(long delay, @Nonnull Runnable runnable) {
return server.runSyncTaskLater(delay, runnable);
}

public static int runAsyncTaskLater(long delay, Runnable runnable) {
@Nonnull
public static BukkitTask runAsyncTaskLater(long delay, @Nonnull Runnable runnable) {
return server.runAsyncTaskLater(delay, runnable);
}

public static int runSyncTaskPeriodically(long delay, long period, Runnable runnable) {
@Nonnull
public static BukkitTask runSyncTaskPeriodically(long delay, long period, @Nonnull Runnable runnable) {
return server.runSyncTaskPeriodically(delay, period, runnable);
}

public static int runAsyncTaskPeriodically(long delay, long period, Runnable runnable) {
@Nonnull
public static BukkitTask runAsyncTaskPeriodically(long delay, long period, @Nonnull Runnable runnable) {
return server.runAsyncTaskPeriodically(delay, period, runnable);
}

/**
* Check if the task currently running.
* <p>
* A repeating task might not be running currently, but will be running in
* the future. A task that has finished, and does not repeat, will not be
* running ever again.
* <p>
* Explicitly, a task is running if there exists a thread for it, and that
* thread is alive.
*
* @param taskId The task to check.
* @return If the task is currently running.
*/
public static boolean isCurrentlyRunning(int taskId) {
return server.isCurrentlyRunning(taskId);
}

/**
* Removes task from scheduler.
*
* @param taskId Id number of task to be removed
*/
public static void cancelTask(int taskId) {
server.cancelTask(taskId);
}

public static void registerListener(Class<? extends Event> cls, EventListener<? extends Event> listener) {
server.registerListener(cls, listener);
}
Expand Down Expand Up @@ -198,11 +179,12 @@ public static String getName(@Nonnull UUID uniqueId) {
* <br>
* <strong>Note:</strong> If no player is found, this method returns null.
* <p>
* <strong>Runtime Optimization</strong>
* <strong>Runtime Optimization</strong>
* <ul>
* <li>This method uses an internal cache</li>
* <li>If the player is online, no use of the mojang api is taken</li>
* </p>
*
* @param name name of the player
* @return unique id as UUID
*/
Expand Down
18 changes: 10 additions & 8 deletions src/main/java/minevalley/core/api/CoreServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@
import org.bukkit.metadata.MetadataValue;
import org.bukkit.metadata.Metadatable;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.Vector;

import javax.annotation.Nonnull;
import java.time.DayOfWeek;
import java.util.List;
import java.util.UUID;
Expand All @@ -69,17 +71,17 @@ public interface CoreServer {

JavaPlugin getInstance();

int runSyncTaskLater(long delay, Runnable runnable);
@Nonnull
BukkitTask runSyncTaskLater(long delay, Runnable runnable);

int runAsyncTaskLater(long delay, Runnable runnable);
@Nonnull
BukkitTask runAsyncTaskLater(long delay, Runnable runnable);

int runSyncTaskPeriodically(long delay, long period, Runnable runnable);
@Nonnull
BukkitTask runSyncTaskPeriodically(long delay, long period, Runnable runnable);

int runAsyncTaskPeriodically(long delay, long period, Runnable runnable);

boolean isCurrentlyRunning(int taskId);

void cancelTask(int taskId);
@Nonnull
BukkitTask runAsyncTaskPeriodically(long delay, long period, Runnable runnable);

void registerListener(Class<? extends Event> cls, EventListener<? extends Event> listener);

Expand Down
Loading