2017-01-30 21:22:36 +01:00
|
|
|
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 {
|
2017-01-30 21:22:36 +01:00
|
|
|
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) {
|
2017-01-30 21:22:36 +01:00
|
|
|
this.plugin = plugin;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the Plugin that created this task
|
|
|
|
*
|
|
|
|
* @return Plugin Info
|
|
|
|
*/
|
2017-02-05 23:03:17 +01:00
|
|
|
public SubPluginInfo plugin() {
|
2017-01-30 21:22:36 +01:00
|
|
|
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) {
|
2017-01-30 21:22:36 +01:00
|
|
|
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() {
|
2017-01-30 21:22:36 +01:00
|
|
|
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) {
|
2017-01-30 21:22:36 +01:00
|
|
|
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() {
|
2017-01-30 21:22:36 +01:00
|
|
|
return this.delay;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Schedule this task
|
|
|
|
*
|
|
|
|
* @return Task ID
|
|
|
|
*/
|
|
|
|
public UUID schedule() {
|
|
|
|
return SubAPI.getInstance().schedule(this);
|
|
|
|
}
|
|
|
|
}
|