Added repeat delay

This commit is contained in:
Teriuihi 2022-01-13 23:17:59 +01:00
parent 907ad4819e
commit 77df8b1e6d
2 changed files with 47 additions and 12 deletions

View File

@ -11,12 +11,14 @@ import java.util.List;
public class FrameSpawnerLocation extends BukkitRunnable {
int amount;
List<Frame> frames;
Iterator<Frame> iterator;
Location location;
public FrameSpawnerLocation(int amount, List<Frame> frames, Location location) {
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) {
this.amount = amount;
this.repeatDelay = (repeatDelay * 1000L) / 20;
this.frames = frames;
this.iterator = frames.iterator();
this.location = location;
@ -29,6 +31,13 @@ public class FrameSpawnerLocation extends BukkitRunnable {
else if (amount != 0) {
iterator = frames.iterator();
amount--;
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();
}
} else {
this.cancel();
if (Config.DEBUG)

View File

@ -1,7 +1,10 @@
package com.alttd.frameSpawners;
import com.alttd.config.Config;
import com.alttd.objects.APartType;
import com.alttd.objects.Frame;
import com.alttd.objects.ParticleSet;
import com.alttd.storage.PlayerSettings;
import com.alttd.util.Logger;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
@ -11,15 +14,23 @@ import java.util.List;
public class FrameSpawnerPlayer extends BukkitRunnable {
int amount;
List<Frame> frames;
Iterator<Frame> iterator;
Player player;
public FrameSpawnerPlayer(int amount, List<Frame> frames, Player player) {
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) {
this.amount = amount;
this.repeatDelay = (repeatDelay * 1000L) / 20;
this.frames = frames;
this.iterator = frames.iterator();
this.player = player;
this.playerSettings = playerSettings;
this.aPartType = aPartType;
this.uniqueId = uniqueId;
}
@Override
@ -30,11 +41,26 @@ public class FrameSpawnerPlayer extends BukkitRunnable {
Logger.info("Stopped repeating task due to player offline.");
return;
}
ParticleSet activeParticleSet = playerSettings.getParticles(aPartType);
if (activeParticleSet == null || !activeParticleSet.getParticleId().equalsIgnoreCase(uniqueId)) {
this.cancel();
if (Config.DEBUG)
Logger.info("Stopped repeating task due to player switching/disabling particles.");
return;
}
if (iterator.hasNext())
iterator.next().spawn(player.getLocation());
else if (amount != 0)
else if (amount != 0) {
iterator = frames.iterator();
else {
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 {
this.cancel();
if (Config.DEBUG)
Logger.info("Stopped repeating task due to end of frames.");