diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/CommandProtocol.java b/ProtocolLib/src/main/java/com/comphenix/protocol/CommandProtocol.java index c35f7632..c722eb53 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/CommandProtocol.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/CommandProtocol.java @@ -25,6 +25,7 @@ import com.comphenix.protocol.error.ErrorReporter; import com.comphenix.protocol.metrics.Updater; import com.comphenix.protocol.metrics.Updater.UpdateResult; import com.comphenix.protocol.metrics.Updater.UpdateType; +import com.comphenix.protocol.utility.WrappedScheduler; /** * Handles the "protocol" administration command. @@ -64,10 +65,9 @@ class CommandProtocol extends CommandBase { return true; } - @SuppressWarnings("deprecation") public void checkVersion(final CommandSender sender) { // Perform on an async thread - plugin.getServer().getScheduler().scheduleAsyncDelayedTask(plugin, new Runnable() { + WrappedScheduler.runAsynchronouslyOnce(plugin, new Runnable() { @Override public void run() { try { @@ -77,15 +77,14 @@ class CommandProtocol extends CommandBase { getReporter().reportDetailed(this, "Cannot check updates for ProtocolLib.", e, sender); } } - }); + }, 0L); updateFinished(); } - @SuppressWarnings("deprecation") public void updateVersion(final CommandSender sender) { // Perform on an async thread - plugin.getServer().getScheduler().scheduleAsyncDelayedTask(plugin, new Runnable() { + WrappedScheduler.runAsynchronouslyOnce(plugin, new Runnable() { @Override public void run() { try { @@ -95,7 +94,7 @@ class CommandProtocol extends CommandBase { getReporter().reportDetailed(this, "Cannot update ProtocolLib.", e, sender); } } - }); + }, 0L); updateFinished(); } diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/async/AsyncListenerHandler.java b/ProtocolLib/src/main/java/com/comphenix/protocol/async/AsyncListenerHandler.java index cefd8a0a..47eb84a6 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/async/AsyncListenerHandler.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/async/AsyncListenerHandler.java @@ -30,6 +30,7 @@ import com.comphenix.protocol.events.ListeningWhitelist; import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.events.PacketListener; +import com.comphenix.protocol.utility.WrappedScheduler; import com.google.common.base.Function; import com.google.common.base.Joiner; @@ -298,9 +299,9 @@ public class AsyncListenerHandler { }); } - @SuppressWarnings("deprecation") private void scheduleAsync(Runnable runnable) { - filterManager.getScheduler().scheduleAsyncDelayedTask(listener.getPlugin(), runnable); + // Handle deprecation + WrappedScheduler.runAsynchronouslyRepeat(listener.getPlugin(), filterManager.getScheduler(), runnable, 0L, -1L); } /** diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/metrics/Metrics.java b/ProtocolLib/src/main/java/com/comphenix/protocol/metrics/Metrics.java index e2a6f3bd..d7640502 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/metrics/Metrics.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/metrics/Metrics.java @@ -239,7 +239,7 @@ public class Metrics { } // Begin hitting the server with glorious data - task = WrappedScheduler.runAsynchronously(plugin, new Runnable() { + task = WrappedScheduler.runAsynchronouslyRepeat(plugin, new Runnable() { private boolean firstPost = true; diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/utility/WrappedScheduler.java b/ProtocolLib/src/main/java/com/comphenix/protocol/utility/WrappedScheduler.java index 8eda7c7e..a7a54395 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/utility/WrappedScheduler.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/utility/WrappedScheduler.java @@ -21,15 +21,26 @@ public class WrappedScheduler { } /** - * Schedule a given task for asynchronous execution. + * Schedule a given task for a single asynchronous execution. + * @param plugin - the owner plugin. + * @param runnable - the task to run. + * @param firstDelay - the amount of time to wait until executing the task. + * @return A cancel token. + */ + public static TaskWrapper runAsynchronouslyOnce(final Plugin plugin, Runnable runnable, long firstDelay) { + return runAsynchronouslyRepeat(plugin, plugin.getServer().getScheduler(), runnable, firstDelay, -1L); + } + + /** + * Schedule a given task for multiple asynchronous executions. * @param plugin - the owner plugin. * @param runnable - the task to run. * @param firstDelay - the amount of time to wait until executing the task for the first time. * @param repeatDelay - the amount of time inbetween each execution. If less than zero, the task is only executed once. * @return A cancel token. */ - public static TaskWrapper runAsynchronously(final Plugin plugin, Runnable runnable, long firstDelay, long repeatDelay) { - return runAsynchronously(plugin, plugin.getServer().getScheduler(), runnable, firstDelay, repeatDelay); + public static TaskWrapper runAsynchronouslyRepeat(final Plugin plugin, Runnable runnable, long firstDelay, long repeatDelay) { + return runAsynchronouslyRepeat(plugin, plugin.getServer().getScheduler(), runnable, firstDelay, repeatDelay); } /** @@ -41,7 +52,7 @@ public class WrappedScheduler { * @param repeatDelay - the amount of time inbetween each execution. If less than zero, the task is only executed once. * @return A cancel token. */ - public static TaskWrapper runAsynchronously(final Plugin plugin, final BukkitScheduler scheduler, Runnable runnable, long firstDelay, long repeatDelay) { + public static TaskWrapper runAsynchronouslyRepeat(final Plugin plugin, final BukkitScheduler scheduler, Runnable runnable, long firstDelay, long repeatDelay) { try { @SuppressWarnings("deprecation") final int taskID = scheduler.scheduleAsyncRepeatingTask(plugin, runnable, firstDelay, repeatDelay);