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

cn.nukkit.scheduler.Task Maven / Gradle / Ivy

Go to download

A Minecraft Bedrock Edition server software implementation made in Java from scratch which supports all new features.

There is a newer version: 1.6.0.1-PN
Show newest version
package cn.nukkit.scheduler;

import lombok.extern.log4j.Log4j2;

/**
 * 表达一个任务的类。
A class that describes a task. * *

一个任务可以被Nukkit服务器立即,延时,循环或延时循环执行。参见:{@link ServerScheduler}
* A task can be executed by Nukkit server with a/an express, delay, repeat or delay&repeat. * See:{@link ServerScheduler}

* *

对于插件开发者,为确保自己任务能够在安全的情况下执行(比如:在插件被禁用时不执行), * 建议让任务继承{@link PluginTask}类而不是这个类。
* For plugin developers: To make sure your task will only be executed in the case of safety * (such as: prevent this task from running if its owner plugin is disabled), * it's suggested to use {@link PluginTask} instead of extend this class.

* * @author MagicDroidX(code) @ Nukkit Project * @author 粉鞋大妈(javadoc) @ Nukkit Project * @since Nukkit 1.0 | Nukkit API 1.0.0 */ @Log4j2 public abstract class Task implements Runnable { private TaskHandler taskHandler = null; public final TaskHandler getHandler() { return this.taskHandler; } public final int getTaskId() { return this.taskHandler != null ? this.taskHandler.getTaskId() : -1; } public final void setHandler(TaskHandler taskHandler) { if (this.taskHandler == null || taskHandler == null) { this.taskHandler = taskHandler; } } /** * 这个任务被执行时,会调用的过程。
* What will be called when the task is executed. * * @param currentTick 服务器从开始运行到现在所经过的tick数,20ticks = 1秒,1tick = 0.05秒。
* The elapsed tick count from the server is started. 20ticks = 1second, 1tick = 0.05second. * @since Nukkit 1.0 | Nukkit API 1.0.0 */ public abstract void onRun(int currentTick); @Override public final void run() { this.onRun(taskHandler.getLastRunTick()); } public void onCancel() { } public void cancel() { try { this.getHandler().cancel(); } catch (RuntimeException ex) { log.fatal("Exception while invoking onCancel", ex); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy