Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-27 08:30:09 +01:00
Rename platform task implementations
Dieser Commit ist enthalten in:
Ursprung
96b5051c75
Commit
ab93e0877c
@ -31,9 +31,9 @@ public interface PlatformTask<T> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the actual object represented by this task/task id.
|
* 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();
|
@Nullable T getObject();
|
||||||
|
|
||||||
|
@ -115,17 +115,6 @@ public interface ViaPlatform<T> {
|
|||||||
*/
|
*/
|
||||||
PlatformTask runRepeatingSync(Runnable runnable, long ticks);
|
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
|
* Get the online players
|
||||||
*
|
*
|
||||||
|
@ -30,7 +30,7 @@ import com.viaversion.viaversion.bukkit.classgenerator.ClassGenerator;
|
|||||||
import com.viaversion.viaversion.bukkit.commands.BukkitCommandHandler;
|
import com.viaversion.viaversion.bukkit.commands.BukkitCommandHandler;
|
||||||
import com.viaversion.viaversion.bukkit.commands.BukkitCommandSender;
|
import com.viaversion.viaversion.bukkit.commands.BukkitCommandSender;
|
||||||
import com.viaversion.viaversion.bukkit.listeners.ProtocolLibEnableListener;
|
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.BukkitViaAPI;
|
||||||
import com.viaversion.viaversion.bukkit.platform.BukkitViaConfig;
|
import com.viaversion.viaversion.bukkit.platform.BukkitViaConfig;
|
||||||
import com.viaversion.viaversion.bukkit.platform.BukkitViaInjector;
|
import com.viaversion.viaversion.bukkit.platform.BukkitViaInjector;
|
||||||
@ -180,31 +180,31 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform<Player>
|
|||||||
@Override
|
@Override
|
||||||
public PlatformTask runAsync(Runnable runnable) {
|
public PlatformTask runAsync(Runnable runnable) {
|
||||||
if (isPluginEnabled()) {
|
if (isPluginEnabled()) {
|
||||||
return new BukkitTaskId(getServer().getScheduler().runTaskAsynchronously(this, runnable));
|
return new BukkitViaTask(getServer().getScheduler().runTaskAsynchronously(this, runnable));
|
||||||
} else {
|
} else {
|
||||||
asyncQueuedTasks.add(runnable);
|
asyncQueuedTasks.add(runnable);
|
||||||
return new BukkitTaskId(null);
|
return new BukkitViaTask(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlatformTask runSync(Runnable runnable) {
|
public PlatformTask runSync(Runnable runnable) {
|
||||||
if (isPluginEnabled()) {
|
if (isPluginEnabled()) {
|
||||||
return new BukkitTaskId(getServer().getScheduler().runTask(this, runnable));
|
return new BukkitViaTask(getServer().getScheduler().runTask(this, runnable));
|
||||||
} else {
|
} else {
|
||||||
queuedTasks.add(runnable);
|
queuedTasks.add(runnable);
|
||||||
return new BukkitTaskId(null);
|
return new BukkitViaTask(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlatformTask runSync(Runnable runnable, long ticks) {
|
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
|
@Override
|
||||||
public PlatformTask runRepeatingSync(Runnable runnable, long ticks) {
|
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
|
@Override
|
||||||
|
@ -22,10 +22,10 @@ import com.viaversion.viaversion.api.platform.PlatformTask;
|
|||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
public class BukkitTaskId implements PlatformTask<BukkitTask> {
|
public class BukkitViaTask implements PlatformTask<BukkitTask> {
|
||||||
private final BukkitTask task;
|
private final BukkitTask task;
|
||||||
|
|
||||||
public BukkitTaskId(@Nullable BukkitTask task) {
|
public BukkitViaTask(@Nullable BukkitTask task) {
|
||||||
this.task = task;
|
this.task = task;
|
||||||
}
|
}
|
||||||
|
|
@ -28,7 +28,7 @@ import com.viaversion.viaversion.api.platform.ViaPlatform;
|
|||||||
import com.viaversion.viaversion.bungee.commands.BungeeCommand;
|
import com.viaversion.viaversion.bungee.commands.BungeeCommand;
|
||||||
import com.viaversion.viaversion.bungee.commands.BungeeCommandHandler;
|
import com.viaversion.viaversion.bungee.commands.BungeeCommandHandler;
|
||||||
import com.viaversion.viaversion.bungee.commands.BungeeCommandSender;
|
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.BungeeViaAPI;
|
||||||
import com.viaversion.viaversion.bungee.platform.BungeeViaConfig;
|
import com.viaversion.viaversion.bungee.platform.BungeeViaConfig;
|
||||||
import com.viaversion.viaversion.bungee.platform.BungeeViaInjector;
|
import com.viaversion.viaversion.bungee.platform.BungeeViaInjector;
|
||||||
@ -113,7 +113,7 @@ public class BungeePlugin extends Plugin implements ViaPlatform<ProxiedPlayer>,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlatformTask runAsync(Runnable runnable) {
|
public PlatformTask runAsync(Runnable runnable) {
|
||||||
return new BungeeTaskId(getProxy().getScheduler().runAsync(this, runnable));
|
return new BungeeViaTask(getProxy().getScheduler().runAsync(this, runnable));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -123,12 +123,12 @@ public class BungeePlugin extends Plugin implements ViaPlatform<ProxiedPlayer>,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlatformTask runSync(Runnable runnable, long ticks) {
|
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
|
@Override
|
||||||
public PlatformTask runRepeatingSync(Runnable runnable, long ticks) {
|
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
|
@Override
|
||||||
|
@ -20,10 +20,10 @@ package com.viaversion.viaversion.bungee.platform;
|
|||||||
import com.viaversion.viaversion.api.platform.PlatformTask;
|
import com.viaversion.viaversion.api.platform.PlatformTask;
|
||||||
import net.md_5.bungee.api.scheduler.ScheduledTask;
|
import net.md_5.bungee.api.scheduler.ScheduledTask;
|
||||||
|
|
||||||
public class BungeeTaskId implements PlatformTask<ScheduledTask> {
|
public class BungeeViaTask implements PlatformTask<ScheduledTask> {
|
||||||
private final ScheduledTask task;
|
private final ScheduledTask task;
|
||||||
|
|
||||||
public BungeeTaskId(ScheduledTask task) {
|
public BungeeViaTask(ScheduledTask task) {
|
||||||
this.task = task;
|
this.task = task;
|
||||||
}
|
}
|
||||||
|
|
@ -151,7 +151,7 @@ public class ViaManagerImpl implements ViaManager {
|
|||||||
// Common tasks
|
// Common tasks
|
||||||
mappingLoadingTask = Via.getPlatform().runRepeatingSync(() -> {
|
mappingLoadingTask = Via.getPlatform().runRepeatingSync(() -> {
|
||||||
if (protocolManager.checkForMappingCompletion()) {
|
if (protocolManager.checkForMappingCompletion()) {
|
||||||
platform.cancelTask(mappingLoadingTask);
|
mappingLoadingTask.cancel();
|
||||||
mappingLoadingTask = null;
|
mappingLoadingTask = null;
|
||||||
}
|
}
|
||||||
}, 10L);
|
}, 10L);
|
||||||
|
@ -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.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
import com.viaversion.viaversion.sponge.commands.SpongeCommandHandler;
|
import com.viaversion.viaversion.sponge.commands.SpongeCommandHandler;
|
||||||
import com.viaversion.viaversion.sponge.commands.SpongeCommandSender;
|
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.SpongeViaAPI;
|
||||||
import com.viaversion.viaversion.sponge.platform.SpongeViaConfig;
|
import com.viaversion.viaversion.sponge.platform.SpongeViaConfig;
|
||||||
import com.viaversion.viaversion.sponge.platform.SpongeViaInjector;
|
import com.viaversion.viaversion.sponge.platform.SpongeViaInjector;
|
||||||
@ -128,7 +128,7 @@ public class SpongePlugin implements ViaPlatform<Player> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlatformTask runAsync(Runnable runnable) {
|
public PlatformTask runAsync(Runnable runnable) {
|
||||||
return new SpongeTaskId(
|
return new SpongeViaTask(
|
||||||
Task.builder()
|
Task.builder()
|
||||||
.execute(runnable)
|
.execute(runnable)
|
||||||
.async()
|
.async()
|
||||||
@ -138,7 +138,7 @@ public class SpongePlugin implements ViaPlatform<Player> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlatformTask runSync(Runnable runnable) {
|
public PlatformTask runSync(Runnable runnable) {
|
||||||
return new SpongeTaskId(
|
return new SpongeViaTask(
|
||||||
Task.builder()
|
Task.builder()
|
||||||
.execute(runnable)
|
.execute(runnable)
|
||||||
.submit(this)
|
.submit(this)
|
||||||
@ -147,7 +147,7 @@ public class SpongePlugin implements ViaPlatform<Player> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlatformTask runSync(Runnable runnable, long ticks) {
|
public PlatformTask runSync(Runnable runnable, long ticks) {
|
||||||
return new SpongeTaskId(
|
return new SpongeViaTask(
|
||||||
Task.builder()
|
Task.builder()
|
||||||
.execute(runnable)
|
.execute(runnable)
|
||||||
.delayTicks(ticks)
|
.delayTicks(ticks)
|
||||||
@ -157,7 +157,7 @@ public class SpongePlugin implements ViaPlatform<Player> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlatformTask runRepeatingSync(Runnable runnable, long ticks) {
|
public PlatformTask runRepeatingSync(Runnable runnable, long ticks) {
|
||||||
return new SpongeTaskId(
|
return new SpongeViaTask(
|
||||||
Task.builder()
|
Task.builder()
|
||||||
.execute(runnable)
|
.execute(runnable)
|
||||||
.intervalTicks(ticks)
|
.intervalTicks(ticks)
|
||||||
|
@ -103,7 +103,7 @@ public class SpongeViaLoader implements ViaPlatformLoader {
|
|||||||
public void unload() {
|
public void unload() {
|
||||||
listeners.forEach(Sponge.getEventManager()::unregisterListeners);
|
listeners.forEach(Sponge.getEventManager()::unregisterListeners);
|
||||||
listeners.clear();
|
listeners.clear();
|
||||||
tasks.forEach(Via.getPlatform()::cancelTask);
|
tasks.forEach(PlatformTask::cancel);
|
||||||
tasks.clear();
|
tasks.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -20,10 +20,10 @@ package com.viaversion.viaversion.sponge.platform;
|
|||||||
import com.viaversion.viaversion.api.platform.PlatformTask;
|
import com.viaversion.viaversion.api.platform.PlatformTask;
|
||||||
import org.spongepowered.api.scheduler.Task;
|
import org.spongepowered.api.scheduler.Task;
|
||||||
|
|
||||||
public class SpongeTaskId implements PlatformTask<Task> {
|
public class SpongeViaTask implements PlatformTask<Task> {
|
||||||
private final Task task;
|
private final Task task;
|
||||||
|
|
||||||
public SpongeTaskId(Task task) {
|
public SpongeViaTask(Task task) {
|
||||||
this.task = task;
|
this.task = task;
|
||||||
}
|
}
|
||||||
|
|
@ -39,7 +39,7 @@ import com.viaversion.viaversion.util.GsonUtil;
|
|||||||
import com.viaversion.viaversion.util.VersionInfo;
|
import com.viaversion.viaversion.util.VersionInfo;
|
||||||
import com.viaversion.viaversion.velocity.command.VelocityCommandHandler;
|
import com.viaversion.viaversion.velocity.command.VelocityCommandHandler;
|
||||||
import com.viaversion.viaversion.velocity.command.VelocityCommandSender;
|
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.VelocityViaAPI;
|
||||||
import com.viaversion.viaversion.velocity.platform.VelocityViaConfig;
|
import com.viaversion.viaversion.velocity.platform.VelocityViaConfig;
|
||||||
import com.viaversion.viaversion.velocity.platform.VelocityViaInjector;
|
import com.viaversion.viaversion.velocity.platform.VelocityViaInjector;
|
||||||
@ -138,7 +138,7 @@ public class VelocityPlugin implements ViaPlatform<Player> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlatformTask runSync(Runnable runnable, long ticks) {
|
public PlatformTask runSync(Runnable runnable, long ticks) {
|
||||||
return new VelocityTaskId(
|
return new VelocityViaTask(
|
||||||
PROXY.getScheduler()
|
PROXY.getScheduler()
|
||||||
.buildTask(this, runnable)
|
.buildTask(this, runnable)
|
||||||
.delay(ticks * 50, TimeUnit.MILLISECONDS).schedule()
|
.delay(ticks * 50, TimeUnit.MILLISECONDS).schedule()
|
||||||
@ -147,7 +147,7 @@ public class VelocityPlugin implements ViaPlatform<Player> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlatformTask runRepeatingSync(Runnable runnable, long ticks) {
|
public PlatformTask runRepeatingSync(Runnable runnable, long ticks) {
|
||||||
return new VelocityTaskId(
|
return new VelocityViaTask(
|
||||||
PROXY.getScheduler()
|
PROXY.getScheduler()
|
||||||
.buildTask(this, runnable)
|
.buildTask(this, runnable)
|
||||||
.repeat(ticks * 50, TimeUnit.MILLISECONDS).schedule()
|
.repeat(ticks * 50, TimeUnit.MILLISECONDS).schedule()
|
||||||
|
@ -20,10 +20,10 @@ package com.viaversion.viaversion.velocity.platform;
|
|||||||
import com.velocitypowered.api.scheduler.ScheduledTask;
|
import com.velocitypowered.api.scheduler.ScheduledTask;
|
||||||
import com.viaversion.viaversion.api.platform.PlatformTask;
|
import com.viaversion.viaversion.api.platform.PlatformTask;
|
||||||
|
|
||||||
public class VelocityTaskId implements PlatformTask<ScheduledTask> {
|
public class VelocityViaTask implements PlatformTask<ScheduledTask> {
|
||||||
private final ScheduledTask task;
|
private final ScheduledTask task;
|
||||||
|
|
||||||
public VelocityTaskId(ScheduledTask task) {
|
public VelocityViaTask(ScheduledTask task) {
|
||||||
this.task = task;
|
this.task = task;
|
||||||
}
|
}
|
||||||
|
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren