All Downloads are FREE. Search and download functionalities are using the official Maven repository.

me.huanmeng.opensource.bukkit.scheduler.SchedulerSync Maven / Gradle / Ivy

There is a newer version: 2.2.2
Show newest version
package me.huanmeng.opensource.bukkit.scheduler;

import me.huanmeng.opensource.bukkit.gui.GuiManager;
import me.huanmeng.opensource.scheduler.Scheduler;
import org.bukkit.scheduler.BukkitRunnable;
import org.checkerframework.checker.nullness.qual.NonNull;

import java.util.Objects;
import java.util.function.Consumer;

/**
 * 2023/3/17
* Gui
* * @author huanmeng_qwq */ public class SchedulerSync implements Scheduler { @NonNull @Override public Task run(@NonNull Runnable runnable) { BukkitTaskImpl task = new BukkitTaskImpl(new BukkitRunnable() { @Override public void run() { runnable.run(); } }); Objects.requireNonNull(task.runnable()).runTask(GuiManager.instance().plugin()); return task; } @NonNull @Override public Task runRepeating(@NonNull Runnable runnable, long perTick, long timeTick) { BukkitTaskImpl task = new BukkitTaskImpl(new BukkitRunnable() { @Override public void run() { runnable.run(); } }); Objects.requireNonNull(task.runnable()).runTaskTimer(GuiManager.instance().plugin(), perTick, timeTick); return task; } @NonNull @Override public Task runRepeating(@NonNull Consumer consumer, long perTick, long timeTick) { BukkitTaskImpl task = new BukkitTaskImpl(null) { // 没法直接调用self 所以选择了这种 { setRunnable(new BukkitRunnable() { @Override public void run() { consumer.accept(self); } }); } }; Objects.requireNonNull(task.runnable()).runTaskTimer(GuiManager.instance().plugin(), perTick, timeTick); return task; } @NonNull @Override public Task runLater(@NonNull Runnable runnable, long laterTick) { BukkitTaskImpl task = new BukkitTaskImpl(new BukkitRunnable() { @Override public void run() { runnable.run(); } }); Objects.requireNonNull(task.runnable()).runTaskLater(GuiManager.instance().plugin(), laterTick); return task; } @Override public boolean willStop() { return !GuiManager.instance().plugin().isEnabled(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy