Run IntelliJ IDEA code formatter

This commit is contained in:
KingRainbow44
2023-03-31 17:19:26 -04:00
parent 5bf5fb07a2
commit 15e2f3ca34
917 changed files with 30030 additions and 22446 deletions

View File

@@ -11,19 +11,23 @@ public final class AsyncServerTask implements Runnable {
/* The runnable to run. */
private final Runnable task;
/* This ID is assigned by the scheduler. */
@Getter private final int taskId;
@Getter
private final int taskId;
/* The result callback to run. */
@Nullable private final Runnable callback;
@Nullable
private final Runnable callback;
/* Has the task already been started? */
private boolean started = false;
/* Has the task finished execution? */
private boolean finished = false;
/* The result produced in the async task. */
@Nullable private Object result = null;
@Nullable
private Object result = null;
/**
* For tasks without a callback.
*
* @param task The task to run.
*/
public AsyncServerTask(Runnable task, int taskId) {
@@ -32,7 +36,8 @@ public final class AsyncServerTask implements Runnable {
/**
* For tasks with a callback.
* @param task The task to run.
*
* @param task The task to run.
* @param callback The task to run after the task is complete.
*/
public AsyncServerTask(Runnable task, @Nullable Runnable callback, int taskId) {
@@ -43,6 +48,7 @@ public final class AsyncServerTask implements Runnable {
/**
* Returns the state of the task.
*
* @return True if the task has been started, false otherwise.
*/
public boolean hasStarted() {
@@ -51,6 +57,7 @@ public final class AsyncServerTask implements Runnable {
/**
* Returns the state of the task.
*
* @return True if the task has finished execution, false otherwise.
*/
public boolean isFinished() {
@@ -60,7 +67,8 @@ public final class AsyncServerTask implements Runnable {
/**
* Runs the task.
*/
@Override public void run() {
@Override
public void run() {
// Declare the task as started.
this.started = true;
@@ -76,23 +84,26 @@ public final class AsyncServerTask implements Runnable {
*/
public void complete() {
// Run the callback.
if(this.callback != null)
if (this.callback != null)
this.callback.run();
}
/**
* Returns the set result of the async task.
*
* @return The result, or null if it has not been set.
*/
@Nullable
public Object getResult() {
return this.result;
}
/**
* Sets the result of the async task.
*
* @param result The result of the async task.
*/
public void setResult(@Nullable Object result) {
this.result = result;
}
/**
* Returns the set result of the async task.
* @return The result, or null if it has not been set.
*/
@Nullable public Object getResult() {
return this.result;
}
}

View File

@@ -1,7 +1,7 @@
package emu.grasscutter.server.scheduler;
import emu.grasscutter.Grasscutter;
import lombok.*;
import lombok.Getter;
/**
* This class works the same as a runnable, except with more information.
@@ -10,11 +10,16 @@ public final class ServerTask implements Runnable {
/* The runnable to run. */
private final Runnable runnable;
/* This ID is assigned by the scheduler. */
@Getter private final int taskId;
@Getter
private final int taskId;
/* The period at which the task should be run. */
/* The delay between the first execute. */
private final int period, delay;
/* The amount of times the task has been run. */
@Getter
private int ticks = 0;
/* Should the check consider delay? */
private boolean considerDelay = true;
public ServerTask(Runnable runnable, int taskId, int period, int delay) {
this.runnable = runnable;
this.taskId = taskId;
@@ -22,11 +27,6 @@ public final class ServerTask implements Runnable {
this.delay = delay;
}
/* The amount of times the task has been run. */
@Getter private int ticks = 0;
/* Should the check consider delay? */
private boolean considerDelay = true;
/**
* Cancels the task from running the next time.
*/
@@ -36,19 +36,21 @@ public final class ServerTask implements Runnable {
/**
* Checks if the task should run at the current tick.
*
* @return True if the task should run, false otherwise.
*/
public boolean shouldRun() {
if(this.delay != -1 && this.considerDelay) {
if (this.delay != -1 && this.considerDelay) {
this.considerDelay = false;
return this.ticks == this.delay;
} else if(this.period != -1)
} else if (this.period != -1)
return this.ticks % this.period == 0;
else return true;
}
/**
* Checks if the task should be canceled.
*
* @return True if the task should be canceled, false otherwise.
*/
public boolean shouldCancel() {
@@ -58,10 +60,11 @@ public final class ServerTask implements Runnable {
/**
* Runs the task.
*/
@Override public void run() {
@Override
public void run() {
// Run the runnable.
this.runnable.run();
// Increase tick count.
this.ticks++;
}
}
}

View File

@@ -5,7 +5,7 @@ import java.util.concurrent.ConcurrentHashMap;
/**
* A class to manage all time-based tasks scheduled on the server.
* This handles both synchronous and asynchronous tasks.
*
* <p>
* Developers note: A server tick is ONE REAL-TIME SECOND.
*/
public final class ServerTaskScheduler {
@@ -26,11 +26,11 @@ public final class ServerTaskScheduler {
*/
public void runTasks() {
// Skip if there are no tasks.
if(this.tasks.size() == 0)
if (this.tasks.size() == 0)
return;
// Run all tasks.
for(ServerTask task : this.tasks.values()) {
for (ServerTask task : this.tasks.values()) {
// Check if the task should run.
if (task.shouldRun()) {
// Run the task.
@@ -45,13 +45,13 @@ public final class ServerTaskScheduler {
}
// Run all async tasks.
for(AsyncServerTask task : this.asyncTasks.values()) {
if(!task.hasStarted()) {
for (AsyncServerTask task : this.asyncTasks.values()) {
if (!task.hasStarted()) {
// Create a thread for the task.
Thread thread = new Thread(task);
// Start the thread.
thread.start();
} else if(task.isFinished()) {
} else if (task.isFinished()) {
// Cancel the task.
this.asyncTasks.remove(task.getTaskId());
// Run the task's callback.
@@ -62,6 +62,7 @@ public final class ServerTaskScheduler {
/**
* Gets a task from the scheduler.
*
* @param taskId The ID of the task to get.
* @return The task, or null if it does not exist.
*/
@@ -71,6 +72,7 @@ public final class ServerTaskScheduler {
/**
* Gets an async task from the scheduler.
*
* @param taskId The ID of the task to get.
* @return The task, or null if it does not exist.
*/
@@ -80,6 +82,7 @@ public final class ServerTaskScheduler {
/**
* Removes a task from the scheduler.
*
* @param taskId The ID of the task to remove.
*/
public void cancelTask(int taskId) {
@@ -89,6 +92,7 @@ public final class ServerTaskScheduler {
/**
* Schedules a task to be run on a separate thread.
* The task runs on the next server tick.
*
* @param runnable The runnable to run.
* @return The ID of the task.
*/
@@ -103,6 +107,7 @@ public final class ServerTaskScheduler {
/**
* Schedules a task to be run on the next server tick.
*
* @param runnable The runnable to run.
* @return The ID of the task.
*/
@@ -112,8 +117,9 @@ public final class ServerTaskScheduler {
/**
* Schedules a task to be run after the amount of ticks has passed.
*
* @param runnable The runnable to run.
* @param delay The amount of ticks to wait before running.
* @param delay The amount of ticks to wait before running.
* @return The ID of the task.
*/
public int scheduleDelayedTask(Runnable runnable, int delay) {
@@ -122,8 +128,9 @@ public final class ServerTaskScheduler {
/**
* Schedules a task to be run every amount of ticks.
*
* @param runnable The runnable to run.
* @param period The amount of ticks to wait before running again.
* @param period The amount of ticks to wait before running again.
* @return The ID of the task.
*/
public int scheduleRepeatingTask(Runnable runnable, int period) {
@@ -132,9 +139,10 @@ public final class ServerTaskScheduler {
/**
* Schedules a task to be run after the amount of ticks has passed.
*
* @param runnable The runnable to run.
* @param period The amount of ticks to wait before running again.
* @param delay The amount of ticks to wait before running the first time.
* @param period The amount of ticks to wait before running again.
* @param delay The amount of ticks to wait before running the first time.
* @return The ID of the task.
*/
public int scheduleDelayedRepeatingTask(Runnable runnable, int period, int delay) {
@@ -145,4 +153,4 @@ public final class ServerTaskScheduler {
// Return the task ID.
return taskId;
}
}
}