Move more complex initializations from main class to Initializer helper (tentative)
This commit is contained in:
@@ -14,7 +14,6 @@ import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
@@ -37,8 +36,7 @@ public class BukkitService {
|
||||
private final boolean getOnlinePlayersIsCollection;
|
||||
private Method getOnlinePlayers;
|
||||
|
||||
@Inject
|
||||
BukkitService(AuthMe authMe) {
|
||||
public BukkitService(AuthMe authMe) {
|
||||
this.authMe = authMe;
|
||||
getOnlinePlayersIsCollection = initializeOnlinePlayersIsCollectionField();
|
||||
}
|
||||
@@ -113,17 +111,18 @@ public class BukkitService {
|
||||
* <b>Asynchronous tasks should never access any API in Bukkit. Great care
|
||||
* should be taken to assure the thread-safety of asynchronous tasks.</b>
|
||||
* <p>
|
||||
* Returns a task that will run asynchronously after the specified number
|
||||
* of server ticks.
|
||||
* Returns a task that will repeatedly run asynchronously until cancelled,
|
||||
* starting after the specified number of server ticks.
|
||||
*
|
||||
* @param task the task to be run
|
||||
* @param delay the ticks to wait before running the task
|
||||
* @param delay the ticks to wait before running the task for the first
|
||||
* time
|
||||
* @param period the ticks to wait between runs
|
||||
* @return a BukkitTask that contains the id number
|
||||
* @throws IllegalArgumentException if plugin is null
|
||||
* @throws IllegalArgumentException if task is null
|
||||
*/
|
||||
public BukkitTask runTaskLaterAsynchronously(Runnable task, long delay) {
|
||||
return Bukkit.getScheduler().runTaskLaterAsynchronously(authMe, task, delay);
|
||||
public BukkitTask runTaskTimerAsynchronously(Runnable task, long delay, long period) {
|
||||
return Bukkit.getScheduler().runTaskTimerAsynchronously(authMe, task, delay, period);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -57,4 +57,20 @@ public final class Utils {
|
||||
public static String getPlayerIp(Player p) {
|
||||
return p.getAddress().getAddress().getHostAddress();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the class exists in the current class loader.
|
||||
*
|
||||
* @param className the class name to check
|
||||
*
|
||||
* @return true if the class is loaded, false otherwise
|
||||
*/
|
||||
public static boolean isClassLoaded(String className) {
|
||||
try {
|
||||
Class.forName(className);
|
||||
return true;
|
||||
} catch (ClassNotFoundException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user