2022-01-11 22:02:04 +00:00
|
|
|
package com.alttd.frameSpawners;
|
|
|
|
|
|
|
|
|
|
import com.alttd.config.Config;
|
2022-01-13 22:17:59 +00:00
|
|
|
import com.alttd.objects.APartType;
|
2022-01-11 22:02:04 +00:00
|
|
|
import com.alttd.objects.Frame;
|
2022-01-13 22:17:59 +00:00
|
|
|
import com.alttd.objects.ParticleSet;
|
|
|
|
|
import com.alttd.storage.PlayerSettings;
|
2022-01-11 22:02:04 +00:00
|
|
|
import com.alttd.util.Logger;
|
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
|
|
|
|
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
public class FrameSpawnerPlayer 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 Player player;
|
|
|
|
|
private final PlayerSettings playerSettings;
|
|
|
|
|
private final APartType aPartType;
|
|
|
|
|
private final String uniqueId;
|
|
|
|
|
public FrameSpawnerPlayer(int amount, int repeatDelay, List<Frame> frames, Player player, PlayerSettings playerSettings, APartType aPartType, String uniqueId) {
|
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.player = player;
|
2022-01-13 22:17:59 +00:00
|
|
|
this.playerSettings = playerSettings;
|
|
|
|
|
this.aPartType = aPartType;
|
|
|
|
|
this.uniqueId = uniqueId;
|
2022-01-11 22:02:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
if (!player.isOnline()) {
|
|
|
|
|
this.cancel();
|
|
|
|
|
if (Config.DEBUG)
|
|
|
|
|
Logger.info("Stopped repeating task due to player offline.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-01-13 22:17:59 +00:00
|
|
|
ParticleSet activeParticleSet = playerSettings.getParticles(aPartType);
|
2022-01-13 22:44:30 +00:00
|
|
|
if (activeParticleSet == null || !activeParticleSet.getParticleId().equalsIgnoreCase(uniqueId) || playerSettings.hasActiveParticles()) {
|
2022-01-13 22:17:59 +00:00
|
|
|
this.cancel();
|
|
|
|
|
if (Config.DEBUG)
|
|
|
|
|
Logger.info("Stopped repeating task due to player switching/disabling particles.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-01-11 22:02:04 +00:00
|
|
|
if (iterator.hasNext())
|
2022-04-28 01:37:52 +00:00
|
|
|
iterator.next().spawn(player.getLocation(), player.getLocation().getYaw());
|
2022-01-13 22:17:59 +00:00
|
|
|
else if (amount != 0) {
|
2022-01-11 22:02:04 +00:00
|
|
|
iterator = frames.iterator();
|
2022-01-13 22:17:59 +00:00
|
|
|
amount--;
|
|
|
|
|
if (repeatDelay <= 0)
|
|
|
|
|
return;
|
|
|
|
|
try { //Wait before repeating the frames
|
|
|
|
|
Thread.sleep(repeatDelay); //TODO figure out why this doesn't work and fix it
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2022-01-11 22:02:04 +00:00
|
|
|
this.cancel();
|
|
|
|
|
if (Config.DEBUG)
|
|
|
|
|
Logger.info("Stopped repeating task due to end of frames.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|