Delete src/main/java/pers/xanadu/enderdragon/task directory
This commit is contained in:
@@ -1,40 +0,0 @@
|
|||||||
package pers.xanadu.enderdragon.task;
|
|
||||||
|
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
|
||||||
import pers.xanadu.enderdragon.config.Config;
|
|
||||||
import pers.xanadu.enderdragon.config.Lang;
|
|
||||||
import pers.xanadu.enderdragon.manager.TaskManager;
|
|
||||||
import pers.xanadu.enderdragon.EnderDragon;
|
|
||||||
|
|
||||||
import static pers.xanadu.enderdragon.EnderDragon.plugin;
|
|
||||||
|
|
||||||
public class DragonRespawnRunnable extends BukkitRunnable {
|
|
||||||
private static DragonRespawnRunnable runnable = null;
|
|
||||||
@Override
|
|
||||||
public void run(){
|
|
||||||
if(TaskManager.task == null) {
|
|
||||||
this.cancel();
|
|
||||||
runnable = null;
|
|
||||||
Lang.error("The config of auto-respawn errors!Task has been disabled...");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(TaskManager.task.isTimeUp()){
|
|
||||||
new BukkitRunnable(){
|
|
||||||
@Override
|
|
||||||
public void run(){
|
|
||||||
EnderDragon.getInstance().getDragonManager().initiateRespawn(Config.auto_respawn_world_the_end_name);
|
|
||||||
}
|
|
||||||
}.runTask(plugin);
|
|
||||||
TaskManager.task.updateTime();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static void reload(){
|
|
||||||
if(runnable != null){
|
|
||||||
runnable.cancel();
|
|
||||||
runnable = null;
|
|
||||||
}
|
|
||||||
runnable = new DragonRespawnRunnable();
|
|
||||||
runnable.runTaskTimerAsynchronously(plugin,0,200L);
|
|
||||||
Lang.info("The task has started to run...");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
package pers.xanadu.enderdragon.task;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
|
||||||
import pers.xanadu.enderdragon.EnderDragon;
|
|
||||||
import pers.xanadu.enderdragon.config.Lang;
|
|
||||||
import pers.xanadu.enderdragon.util.MathUtil;
|
|
||||||
|
|
||||||
import static pers.xanadu.enderdragon.EnderDragon.plugin;
|
|
||||||
|
|
||||||
public class DragonRespawnTimer {
|
|
||||||
private final String world_name;
|
|
||||||
private final int delay;
|
|
||||||
private BukkitRunnable runnable;
|
|
||||||
private int remainSecond;
|
|
||||||
private boolean isRunning;
|
|
||||||
public DragonRespawnTimer(String WorldName,int second){
|
|
||||||
this(WorldName,second,second);
|
|
||||||
}
|
|
||||||
public DragonRespawnTimer(String WorldName,int second,int rest_second){
|
|
||||||
this.world_name = WorldName;
|
|
||||||
this.delay = second;
|
|
||||||
this.remainSecond = rest_second;
|
|
||||||
this.isRunning = false;
|
|
||||||
resetRunnable();
|
|
||||||
}
|
|
||||||
public void run(){
|
|
||||||
if(!isRunning) runnable.runTaskTimerAsynchronously(plugin,0L,20L);
|
|
||||||
isRunning = true;
|
|
||||||
}
|
|
||||||
public void update(){
|
|
||||||
remainSecond = delay;
|
|
||||||
runnable.cancel();
|
|
||||||
isRunning = false;
|
|
||||||
resetRunnable();
|
|
||||||
}
|
|
||||||
public void del(){
|
|
||||||
if(isRunning) runnable.cancel();
|
|
||||||
}
|
|
||||||
public String getWorld_name(){
|
|
||||||
return this.world_name;
|
|
||||||
}
|
|
||||||
public int getSetTime(){
|
|
||||||
return this.delay;
|
|
||||||
}
|
|
||||||
public int getRestTime(){
|
|
||||||
return this.remainSecond;
|
|
||||||
}
|
|
||||||
public boolean isRunning(){
|
|
||||||
return isRunning;
|
|
||||||
}
|
|
||||||
public double getProgress(){
|
|
||||||
return 1d*remainSecond/delay;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public String toString(){
|
|
||||||
return "(" + world_name + ") " +
|
|
||||||
"remain:" + MathUtil.formatDuration(remainSecond) +
|
|
||||||
", set:" + MathUtil.formatDuration(delay);
|
|
||||||
}
|
|
||||||
private void resetRunnable(){
|
|
||||||
this.runnable = new BukkitRunnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
remainSecond--;
|
|
||||||
if(remainSecond <= 0){
|
|
||||||
Bukkit.getScheduler().runTask(plugin,() -> {
|
|
||||||
if(EnderDragon.getInstance().getDragonManager().canRespawn(world_name)){
|
|
||||||
EnderDragon.getInstance().getDragonManager().initiateRespawn(world_name);
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
remainSecond = delay;
|
|
||||||
Lang.error(Lang.command_respawn_cd_retry);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
package pers.xanadu.enderdragon.task;
|
|
||||||
|
|
||||||
import pers.xanadu.enderdragon.EnderDragon;
|
|
||||||
import pers.xanadu.enderdragon.manager.TaskManager;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.LocalTime;
|
|
||||||
|
|
||||||
public abstract class Task {
|
|
||||||
protected int period;
|
|
||||||
protected int day;
|
|
||||||
private final TaskType type;
|
|
||||||
public abstract LocalDateTime getNextTime(LocalDateTime cur);
|
|
||||||
public abstract void updateTime();
|
|
||||||
protected LocalDateTime nextTime;
|
|
||||||
protected Task(TaskType type,String str){
|
|
||||||
this.type = type;
|
|
||||||
switch (type){
|
|
||||||
case minute :
|
|
||||||
case hour : {
|
|
||||||
this.period = Integer.parseInt(str);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case day : {
|
|
||||||
this.period = Integer.parseInt(str.split(",")[0]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case week :
|
|
||||||
case month :
|
|
||||||
case year : {
|
|
||||||
this.day = Integer.parseInt(str.split(",")[0]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(EnderDragon.data.getString(TaskManager.path) == null){
|
|
||||||
switch (type){
|
|
||||||
case minute :
|
|
||||||
case hour : {
|
|
||||||
this.nextTime = this.getNextTime(LocalDateTime.now().withSecond(0));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case day :
|
|
||||||
case week :
|
|
||||||
case month :
|
|
||||||
case year : {
|
|
||||||
calcNextTime(str);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
TaskManager.saveFile(nextTime);
|
|
||||||
}
|
|
||||||
else this.nextTime = TaskManager.getLocalDateTime(EnderDragon.data.getString(TaskManager.path));
|
|
||||||
}
|
|
||||||
private void calcNextTime(String str){
|
|
||||||
LocalTime time = TaskManager.getRoundTime(str.split(",")[1]);
|
|
||||||
if(time != null) this.nextTime = this.getNextTime(LocalDateTime.now().withSecond(0).with(time));
|
|
||||||
else this.nextTime = this.getNextTime(LocalDateTime.now().withSecond(0));
|
|
||||||
}
|
|
||||||
public boolean isTimeUp(){
|
|
||||||
LocalDateTime now = LocalDateTime.now();
|
|
||||||
if(now.isEqual(nextTime) || now.isAfter(nextTime)){
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
public TaskType getType(){
|
|
||||||
return this.type;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
package pers.xanadu.enderdragon.task;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.TreeMap;
|
|
||||||
|
|
||||||
public enum TaskType {
|
|
||||||
minute,
|
|
||||||
hour,
|
|
||||||
day,
|
|
||||||
week,
|
|
||||||
month,
|
|
||||||
year,
|
|
||||||
unknown;
|
|
||||||
private static final Map<String,TaskType> mp = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
|
||||||
public static TaskType getByName(String str){
|
|
||||||
if(str == null) return unknown;
|
|
||||||
return mp.getOrDefault(str,unknown);
|
|
||||||
}
|
|
||||||
static{
|
|
||||||
TaskType[] values = values();
|
|
||||||
for (TaskType taskType : values) {
|
|
||||||
String name = taskType.name();
|
|
||||||
mp.put(name, taskType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
package pers.xanadu.enderdragon.task.type;
|
|
||||||
|
|
||||||
import pers.xanadu.enderdragon.task.Task;
|
|
||||||
import pers.xanadu.enderdragon.task.TaskType;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
import static pers.xanadu.enderdragon.manager.TaskManager.saveFile;
|
|
||||||
|
|
||||||
public class Day extends Task {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public LocalDateTime getNextTime(LocalDateTime cur) {
|
|
||||||
return cur.plusDays(period);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void updateTime(){
|
|
||||||
this.nextTime = LocalDateTime.now().withSecond(0).plusDays(period);
|
|
||||||
saveFile(nextTime);
|
|
||||||
}
|
|
||||||
public Day(TaskType type, String str){
|
|
||||||
super(type,str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
package pers.xanadu.enderdragon.task.type;
|
|
||||||
|
|
||||||
import pers.xanadu.enderdragon.task.Task;
|
|
||||||
import pers.xanadu.enderdragon.task.TaskType;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
import static pers.xanadu.enderdragon.manager.TaskManager.saveFile;
|
|
||||||
|
|
||||||
public class Hour extends Task {
|
|
||||||
@Override
|
|
||||||
public LocalDateTime getNextTime(LocalDateTime cur) {
|
|
||||||
return cur.plusHours(period);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void updateTime(){
|
|
||||||
this.nextTime = LocalDateTime.now().withSecond(0).plusHours(period);
|
|
||||||
saveFile(nextTime);
|
|
||||||
}
|
|
||||||
public Hour(TaskType type, String str){
|
|
||||||
super(type,str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
package pers.xanadu.enderdragon.task.type;
|
|
||||||
|
|
||||||
import pers.xanadu.enderdragon.task.Task;
|
|
||||||
import pers.xanadu.enderdragon.task.TaskType;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
import static pers.xanadu.enderdragon.manager.TaskManager.saveFile;
|
|
||||||
|
|
||||||
public class Minute extends Task {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public LocalDateTime getNextTime(LocalDateTime cur) {
|
|
||||||
return cur.plusMinutes(period);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void updateTime(){
|
|
||||||
this.nextTime = LocalDateTime.now().withSecond(0).plusMinutes(period);
|
|
||||||
saveFile(nextTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Minute(TaskType type, String str){
|
|
||||||
super(type,str);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
package pers.xanadu.enderdragon.task.type;
|
|
||||||
|
|
||||||
import pers.xanadu.enderdragon.task.Task;
|
|
||||||
import pers.xanadu.enderdragon.task.TaskType;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
import static pers.xanadu.enderdragon.manager.TaskManager.saveFile;
|
|
||||||
|
|
||||||
public class Month extends Task {
|
|
||||||
@Override
|
|
||||||
public LocalDateTime getNextTime(LocalDateTime cur) {
|
|
||||||
return cur.plusMonths(1).withDayOfMonth(day);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void updateTime(){
|
|
||||||
this.nextTime = LocalDateTime.now().withSecond(0).plusMonths(1).withDayOfMonth(day);
|
|
||||||
saveFile(nextTime);
|
|
||||||
}
|
|
||||||
public Month(TaskType type, String str){
|
|
||||||
super(type,str);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
package pers.xanadu.enderdragon.task.type;
|
|
||||||
|
|
||||||
import pers.xanadu.enderdragon.task.Task;
|
|
||||||
import pers.xanadu.enderdragon.task.TaskType;
|
|
||||||
|
|
||||||
import java.time.DayOfWeek;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
import static pers.xanadu.enderdragon.manager.TaskManager.saveFile;
|
|
||||||
|
|
||||||
public class Week extends Task {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public LocalDateTime getNextTime(LocalDateTime cur) {
|
|
||||||
return cur.with(DayOfWeek.of(day)).plusDays(7);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void updateTime(){
|
|
||||||
this.nextTime = LocalDateTime.now().withSecond(0).plusDays(7);
|
|
||||||
saveFile(nextTime);
|
|
||||||
}
|
|
||||||
public Week(TaskType type, String str){
|
|
||||||
super(type,str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
package pers.xanadu.enderdragon.task.type;
|
|
||||||
|
|
||||||
import pers.xanadu.enderdragon.task.Task;
|
|
||||||
import pers.xanadu.enderdragon.task.TaskType;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
import static pers.xanadu.enderdragon.manager.TaskManager.saveFile;
|
|
||||||
|
|
||||||
public class Year extends Task {
|
|
||||||
@Override
|
|
||||||
public LocalDateTime getNextTime(LocalDateTime cur) {
|
|
||||||
return cur.plusYears(1).withDayOfMonth(day);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void updateTime(){
|
|
||||||
this.nextTime = LocalDateTime.now().withSecond(0).plusYears(1);
|
|
||||||
saveFile(nextTime);
|
|
||||||
}
|
|
||||||
public Year(TaskType type, String str){
|
|
||||||
super(type,str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user