From ab93e0877c8627f410cba85c21a3d6e925eff7cc Mon Sep 17 00:00:00 2001 From: KennyTV Date: Thu, 29 Apr 2021 17:46:29 +0200 Subject: [PATCH] Rename platform task implementations --- .../viaversion/api/platform/PlatformTask.java | 4 ++-- .../viaversion/api/platform/ViaPlatform.java | 11 ----------- .../viaversion/viaversion/ViaVersionPlugin.java | 14 +++++++------- .../{BukkitTaskId.java => BukkitViaTask.java} | 4 ++-- .../com/viaversion/viaversion/BungeePlugin.java | 8 ++++---- .../{BungeeTaskId.java => BungeeViaTask.java} | 4 ++-- .../com/viaversion/viaversion/ViaManagerImpl.java | 2 +- .../com/viaversion/viaversion/SpongePlugin.java | 10 +++++----- .../sponge/platform/SpongeViaLoader.java | 2 +- .../{SpongeTaskId.java => SpongeViaTask.java} | 4 ++-- .../com/viaversion/viaversion/VelocityPlugin.java | 6 +++--- .../{VelocityTaskId.java => VelocityViaTask.java} | 4 ++-- 12 files changed, 31 insertions(+), 42 deletions(-) rename bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/{BukkitTaskId.java => BukkitViaTask.java} (91%) rename bungee/src/main/java/com/viaversion/viaversion/bungee/platform/{BungeeTaskId.java => BungeeViaTask.java} (91%) rename sponge/src/main/java/com/viaversion/viaversion/sponge/platform/{SpongeTaskId.java => SpongeViaTask.java} (92%) rename velocity/src/main/java/com/viaversion/viaversion/velocity/platform/{VelocityTaskId.java => VelocityViaTask.java} (90%) diff --git a/api/src/main/java/com/viaversion/viaversion/api/platform/PlatformTask.java b/api/src/main/java/com/viaversion/viaversion/api/platform/PlatformTask.java index 6a7c8e55f..316c7bc06 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/platform/PlatformTask.java +++ b/api/src/main/java/com/viaversion/viaversion/api/platform/PlatformTask.java @@ -31,9 +31,9 @@ public interface PlatformTask { /** * Returns the actual object represented by this task/task id. - * Null if task cannot be cancelled. + * Null if task cannot be instantly tracked. * - * @return platform based object, or null if not cancellable + * @return platform based object, or null if not tracked/cancellable */ @Nullable T getObject(); diff --git a/api/src/main/java/com/viaversion/viaversion/api/platform/ViaPlatform.java b/api/src/main/java/com/viaversion/viaversion/api/platform/ViaPlatform.java index 94b642cdf..5c1f9c734 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/platform/ViaPlatform.java +++ b/api/src/main/java/com/viaversion/viaversion/api/platform/ViaPlatform.java @@ -115,17 +115,6 @@ public interface ViaPlatform { */ PlatformTask runRepeatingSync(Runnable runnable, long ticks); - /** - * Cancels a task. - * - * @param task task to cancel - */ - default void cancelTask(PlatformTask task) { - if (task.getObject() != null) { - task.cancel(); - } - } - /** * Get the online players * diff --git a/bukkit/src/main/java/com/viaversion/viaversion/ViaVersionPlugin.java b/bukkit/src/main/java/com/viaversion/viaversion/ViaVersionPlugin.java index 7cbdd902b..d523b3f90 100644 --- a/bukkit/src/main/java/com/viaversion/viaversion/ViaVersionPlugin.java +++ b/bukkit/src/main/java/com/viaversion/viaversion/ViaVersionPlugin.java @@ -30,7 +30,7 @@ import com.viaversion.viaversion.bukkit.classgenerator.ClassGenerator; import com.viaversion.viaversion.bukkit.commands.BukkitCommandHandler; import com.viaversion.viaversion.bukkit.commands.BukkitCommandSender; import com.viaversion.viaversion.bukkit.listeners.ProtocolLibEnableListener; -import com.viaversion.viaversion.bukkit.platform.BukkitTaskId; +import com.viaversion.viaversion.bukkit.platform.BukkitViaTask; import com.viaversion.viaversion.bukkit.platform.BukkitViaAPI; import com.viaversion.viaversion.bukkit.platform.BukkitViaConfig; import com.viaversion.viaversion.bukkit.platform.BukkitViaInjector; @@ -180,31 +180,31 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform @Override public PlatformTask runAsync(Runnable runnable) { if (isPluginEnabled()) { - return new BukkitTaskId(getServer().getScheduler().runTaskAsynchronously(this, runnable)); + return new BukkitViaTask(getServer().getScheduler().runTaskAsynchronously(this, runnable)); } else { asyncQueuedTasks.add(runnable); - return new BukkitTaskId(null); + return new BukkitViaTask(null); } } @Override public PlatformTask runSync(Runnable runnable) { if (isPluginEnabled()) { - return new BukkitTaskId(getServer().getScheduler().runTask(this, runnable)); + return new BukkitViaTask(getServer().getScheduler().runTask(this, runnable)); } else { queuedTasks.add(runnable); - return new BukkitTaskId(null); + return new BukkitViaTask(null); } } @Override public PlatformTask runSync(Runnable runnable, long ticks) { - return new BukkitTaskId(getServer().getScheduler().runTaskLater(this, runnable, ticks)); + return new BukkitViaTask(getServer().getScheduler().runTaskLater(this, runnable, ticks)); } @Override public PlatformTask runRepeatingSync(Runnable runnable, long ticks) { - return new BukkitTaskId(getServer().getScheduler().runTaskTimer(this, runnable, 0, ticks)); + return new BukkitViaTask(getServer().getScheduler().runTaskTimer(this, runnable, 0, ticks)); } @Override diff --git a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitTaskId.java b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaTask.java similarity index 91% rename from bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitTaskId.java rename to bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaTask.java index abb2f7176..1a1fa28cc 100644 --- a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitTaskId.java +++ b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaTask.java @@ -22,10 +22,10 @@ import com.viaversion.viaversion.api.platform.PlatformTask; import org.bukkit.scheduler.BukkitTask; import org.checkerframework.checker.nullness.qual.Nullable; -public class BukkitTaskId implements PlatformTask { +public class BukkitViaTask implements PlatformTask { private final BukkitTask task; - public BukkitTaskId(@Nullable BukkitTask task) { + public BukkitViaTask(@Nullable BukkitTask task) { this.task = task; } diff --git a/bungee/src/main/java/com/viaversion/viaversion/BungeePlugin.java b/bungee/src/main/java/com/viaversion/viaversion/BungeePlugin.java index 53ce09ee4..1032b7468 100644 --- a/bungee/src/main/java/com/viaversion/viaversion/BungeePlugin.java +++ b/bungee/src/main/java/com/viaversion/viaversion/BungeePlugin.java @@ -28,7 +28,7 @@ import com.viaversion.viaversion.api.platform.ViaPlatform; import com.viaversion.viaversion.bungee.commands.BungeeCommand; import com.viaversion.viaversion.bungee.commands.BungeeCommandHandler; import com.viaversion.viaversion.bungee.commands.BungeeCommandSender; -import com.viaversion.viaversion.bungee.platform.BungeeTaskId; +import com.viaversion.viaversion.bungee.platform.BungeeViaTask; import com.viaversion.viaversion.bungee.platform.BungeeViaAPI; import com.viaversion.viaversion.bungee.platform.BungeeViaConfig; import com.viaversion.viaversion.bungee.platform.BungeeViaInjector; @@ -113,7 +113,7 @@ public class BungeePlugin extends Plugin implements ViaPlatform, @Override public PlatformTask runAsync(Runnable runnable) { - return new BungeeTaskId(getProxy().getScheduler().runAsync(this, runnable)); + return new BungeeViaTask(getProxy().getScheduler().runAsync(this, runnable)); } @Override @@ -123,12 +123,12 @@ public class BungeePlugin extends Plugin implements ViaPlatform, @Override public PlatformTask runSync(Runnable runnable, long ticks) { - return new BungeeTaskId(getProxy().getScheduler().schedule(this, runnable, ticks * 50, TimeUnit.MILLISECONDS)); + return new BungeeViaTask(getProxy().getScheduler().schedule(this, runnable, ticks * 50, TimeUnit.MILLISECONDS)); } @Override public PlatformTask runRepeatingSync(Runnable runnable, long ticks) { - return new BungeeTaskId(getProxy().getScheduler().schedule(this, runnable, 0, ticks * 50, TimeUnit.MILLISECONDS)); + return new BungeeViaTask(getProxy().getScheduler().schedule(this, runnable, 0, ticks * 50, TimeUnit.MILLISECONDS)); } @Override diff --git a/bungee/src/main/java/com/viaversion/viaversion/bungee/platform/BungeeTaskId.java b/bungee/src/main/java/com/viaversion/viaversion/bungee/platform/BungeeViaTask.java similarity index 91% rename from bungee/src/main/java/com/viaversion/viaversion/bungee/platform/BungeeTaskId.java rename to bungee/src/main/java/com/viaversion/viaversion/bungee/platform/BungeeViaTask.java index 733f48632..0d4c2ed02 100644 --- a/bungee/src/main/java/com/viaversion/viaversion/bungee/platform/BungeeTaskId.java +++ b/bungee/src/main/java/com/viaversion/viaversion/bungee/platform/BungeeViaTask.java @@ -20,10 +20,10 @@ package com.viaversion.viaversion.bungee.platform; import com.viaversion.viaversion.api.platform.PlatformTask; import net.md_5.bungee.api.scheduler.ScheduledTask; -public class BungeeTaskId implements PlatformTask { +public class BungeeViaTask implements PlatformTask { private final ScheduledTask task; - public BungeeTaskId(ScheduledTask task) { + public BungeeViaTask(ScheduledTask task) { this.task = task; } diff --git a/common/src/main/java/com/viaversion/viaversion/ViaManagerImpl.java b/common/src/main/java/com/viaversion/viaversion/ViaManagerImpl.java index 7faa1e848..aab5d17df 100644 --- a/common/src/main/java/com/viaversion/viaversion/ViaManagerImpl.java +++ b/common/src/main/java/com/viaversion/viaversion/ViaManagerImpl.java @@ -151,7 +151,7 @@ public class ViaManagerImpl implements ViaManager { // Common tasks mappingLoadingTask = Via.getPlatform().runRepeatingSync(() -> { if (protocolManager.checkForMappingCompletion()) { - platform.cancelTask(mappingLoadingTask); + mappingLoadingTask.cancel(); mappingLoadingTask = null; } }, 10L); diff --git a/sponge/src/main/java/com/viaversion/viaversion/SpongePlugin.java b/sponge/src/main/java/com/viaversion/viaversion/SpongePlugin.java index 2c812a557..e4bf639df 100644 --- a/sponge/src/main/java/com/viaversion/viaversion/SpongePlugin.java +++ b/sponge/src/main/java/com/viaversion/viaversion/SpongePlugin.java @@ -29,7 +29,7 @@ import com.viaversion.viaversion.dump.PluginInfo; import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import com.viaversion.viaversion.sponge.commands.SpongeCommandHandler; import com.viaversion.viaversion.sponge.commands.SpongeCommandSender; -import com.viaversion.viaversion.sponge.platform.SpongeTaskId; +import com.viaversion.viaversion.sponge.platform.SpongeViaTask; import com.viaversion.viaversion.sponge.platform.SpongeViaAPI; import com.viaversion.viaversion.sponge.platform.SpongeViaConfig; import com.viaversion.viaversion.sponge.platform.SpongeViaInjector; @@ -128,7 +128,7 @@ public class SpongePlugin implements ViaPlatform { @Override public PlatformTask runAsync(Runnable runnable) { - return new SpongeTaskId( + return new SpongeViaTask( Task.builder() .execute(runnable) .async() @@ -138,7 +138,7 @@ public class SpongePlugin implements ViaPlatform { @Override public PlatformTask runSync(Runnable runnable) { - return new SpongeTaskId( + return new SpongeViaTask( Task.builder() .execute(runnable) .submit(this) @@ -147,7 +147,7 @@ public class SpongePlugin implements ViaPlatform { @Override public PlatformTask runSync(Runnable runnable, long ticks) { - return new SpongeTaskId( + return new SpongeViaTask( Task.builder() .execute(runnable) .delayTicks(ticks) @@ -157,7 +157,7 @@ public class SpongePlugin implements ViaPlatform { @Override public PlatformTask runRepeatingSync(Runnable runnable, long ticks) { - return new SpongeTaskId( + return new SpongeViaTask( Task.builder() .execute(runnable) .intervalTicks(ticks) diff --git a/sponge/src/main/java/com/viaversion/viaversion/sponge/platform/SpongeViaLoader.java b/sponge/src/main/java/com/viaversion/viaversion/sponge/platform/SpongeViaLoader.java index 59962a143..68df49d24 100644 --- a/sponge/src/main/java/com/viaversion/viaversion/sponge/platform/SpongeViaLoader.java +++ b/sponge/src/main/java/com/viaversion/viaversion/sponge/platform/SpongeViaLoader.java @@ -103,7 +103,7 @@ public class SpongeViaLoader implements ViaPlatformLoader { public void unload() { listeners.forEach(Sponge.getEventManager()::unregisterListeners); listeners.clear(); - tasks.forEach(Via.getPlatform()::cancelTask); + tasks.forEach(PlatformTask::cancel); tasks.clear(); } } \ No newline at end of file diff --git a/sponge/src/main/java/com/viaversion/viaversion/sponge/platform/SpongeTaskId.java b/sponge/src/main/java/com/viaversion/viaversion/sponge/platform/SpongeViaTask.java similarity index 92% rename from sponge/src/main/java/com/viaversion/viaversion/sponge/platform/SpongeTaskId.java rename to sponge/src/main/java/com/viaversion/viaversion/sponge/platform/SpongeViaTask.java index 1e22ef277..a751dd616 100644 --- a/sponge/src/main/java/com/viaversion/viaversion/sponge/platform/SpongeTaskId.java +++ b/sponge/src/main/java/com/viaversion/viaversion/sponge/platform/SpongeViaTask.java @@ -20,10 +20,10 @@ package com.viaversion.viaversion.sponge.platform; import com.viaversion.viaversion.api.platform.PlatformTask; import org.spongepowered.api.scheduler.Task; -public class SpongeTaskId implements PlatformTask { +public class SpongeViaTask implements PlatformTask { private final Task task; - public SpongeTaskId(Task task) { + public SpongeViaTask(Task task) { this.task = task; } diff --git a/velocity/src/main/java/com/viaversion/viaversion/VelocityPlugin.java b/velocity/src/main/java/com/viaversion/viaversion/VelocityPlugin.java index 95972d3ae..573f2d2ca 100644 --- a/velocity/src/main/java/com/viaversion/viaversion/VelocityPlugin.java +++ b/velocity/src/main/java/com/viaversion/viaversion/VelocityPlugin.java @@ -39,7 +39,7 @@ import com.viaversion.viaversion.util.GsonUtil; import com.viaversion.viaversion.util.VersionInfo; import com.viaversion.viaversion.velocity.command.VelocityCommandHandler; import com.viaversion.viaversion.velocity.command.VelocityCommandSender; -import com.viaversion.viaversion.velocity.platform.VelocityTaskId; +import com.viaversion.viaversion.velocity.platform.VelocityViaTask; import com.viaversion.viaversion.velocity.platform.VelocityViaAPI; import com.viaversion.viaversion.velocity.platform.VelocityViaConfig; import com.viaversion.viaversion.velocity.platform.VelocityViaInjector; @@ -138,7 +138,7 @@ public class VelocityPlugin implements ViaPlatform { @Override public PlatformTask runSync(Runnable runnable, long ticks) { - return new VelocityTaskId( + return new VelocityViaTask( PROXY.getScheduler() .buildTask(this, runnable) .delay(ticks * 50, TimeUnit.MILLISECONDS).schedule() @@ -147,7 +147,7 @@ public class VelocityPlugin implements ViaPlatform { @Override public PlatformTask runRepeatingSync(Runnable runnable, long ticks) { - return new VelocityTaskId( + return new VelocityViaTask( PROXY.getScheduler() .buildTask(this, runnable) .repeat(ticks * 50, TimeUnit.MILLISECONDS).schedule() diff --git a/velocity/src/main/java/com/viaversion/viaversion/velocity/platform/VelocityTaskId.java b/velocity/src/main/java/com/viaversion/viaversion/velocity/platform/VelocityViaTask.java similarity index 90% rename from velocity/src/main/java/com/viaversion/viaversion/velocity/platform/VelocityTaskId.java rename to velocity/src/main/java/com/viaversion/viaversion/velocity/platform/VelocityViaTask.java index c7560ecf9..c6cb5a5c7 100644 --- a/velocity/src/main/java/com/viaversion/viaversion/velocity/platform/VelocityTaskId.java +++ b/velocity/src/main/java/com/viaversion/viaversion/velocity/platform/VelocityViaTask.java @@ -20,10 +20,10 @@ package com.viaversion.viaversion.velocity.platform; import com.velocitypowered.api.scheduler.ScheduledTask; import com.viaversion.viaversion.api.platform.PlatformTask; -public class VelocityTaskId implements PlatformTask { +public class VelocityViaTask implements PlatformTask { private final ScheduledTask task; - public VelocityTaskId(ScheduledTask task) { + public VelocityViaTask(ScheduledTask task) { this.task = task; }