2022-01-11 22:02:04 +00:00
|
|
|
package com.alttd.frameSpawners;
|
|
|
|
|
|
|
|
|
|
import com.alttd.config.Config;
|
|
|
|
|
import com.alttd.objects.Frame;
|
|
|
|
|
import com.alttd.util.Logger;
|
|
|
|
|
import org.bukkit.Location;
|
|
|
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
|
|
|
|
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
public class FrameSpawnerLocation extends BukkitRunnable {
|
|
|
|
|
|
2022-01-13 22:17:59 +00:00
|
|
|
private int amount;
|
|
|
|
|
private final long repeatDelay;
|
|
|
|
|
private final List<Frame> frames;
|
|
|
|
|
private Iterator<Frame> iterator;
|
|
|
|
|
private final Location location;
|
|
|
|
|
public FrameSpawnerLocation(int amount, int repeatDelay, List<Frame> frames, Location location) {
|
2022-01-11 22:02:04 +00:00
|
|
|
this.amount = amount;
|
2022-01-13 22:17:59 +00:00
|
|
|
this.repeatDelay = (repeatDelay * 1000L) / 20;
|
2022-01-11 22:02:04 +00:00
|
|
|
this.frames = frames;
|
|
|
|
|
this.iterator = frames.iterator();
|
|
|
|
|
this.location = location;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
if (iterator.hasNext())
|
|
|
|
|
iterator.next().spawn(location);
|
2022-01-13 20:27:37 +00:00
|
|
|
else if (amount != 0) {
|
2022-01-11 22:02:04 +00:00
|
|
|
iterator = frames.iterator();
|
2022-01-13 20:27:37 +00:00
|
|
|
amount--;
|
2022-01-13 22:17:59 +00:00
|
|
|
if (repeatDelay <= 0)
|
|
|
|
|
return;
|
|
|
|
|
try { //Wait before repeating the frames
|
|
|
|
|
Thread.sleep(repeatDelay); //TODO figure out why this isn't working and fix it
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
2022-01-13 20:27:37 +00:00
|
|
|
} else {
|
2022-01-11 22:02:04 +00:00
|
|
|
this.cancel();
|
|
|
|
|
if (Config.DEBUG)
|
|
|
|
|
Logger.info("Stopped repeating task due to end of frames");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|