SubServers-2/SubServers.Host/src/net/ME1312/SubServers/Host/API/SubTask.java

85 lines
1.6 KiB
Java
Raw Normal View History

package net.ME1312.SubServers.Host.API;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.SubServers.Host.SubAPI;
import java.util.UUID;
/**
* SubServers Task Builder Class
*/
2017-02-05 23:03:17 +01:00
public abstract class SubTask implements Runnable {
private long repeat = -1L;
private long delay = -1L;
private SubPluginInfo plugin;
/**
* Create a new Task
*
* @param plugin Plugin Creating
*/
2017-02-05 23:03:17 +01:00
public SubTask(SubPluginInfo plugin) {
this.plugin = plugin;
}
/**
* Get the Plugin that created this task
*
* @return Plugin Info
*/
2017-02-05 23:03:17 +01:00
public SubPluginInfo plugin() {
return this.plugin;
}
/**
* Set the Repeat Interval for this task
*
* @param value Value
* @return Task Builder
*/
2017-02-05 23:03:17 +01:00
public SubTask repeat(long value) {
if (Util.isNull(value)) throw new NullPointerException();
this.repeat = value;
return this;
}
/**
* Get the Repeat Interval for this task
*
* @return Repeat Interval
*/
2017-02-05 23:03:17 +01:00
public long repeat() {
return this.repeat;
}
/**
* Delay this task
*
* @param value Value
* @return Task Builder
*/
2017-02-05 23:03:17 +01:00
public SubTask delay(long value) {
if (Util.isNull(value)) throw new NullPointerException();
this.delay = value;
return this;
}
/**
* Get the Delay for this task
*
* @return Task Delay
*/
2017-02-05 23:03:17 +01:00
public long delay() {
return this.delay;
}
/**
* Schedule this task
*
* @return Task ID
*/
public UUID schedule() {
return SubAPI.getInstance().schedule(this);
}
}