Added repeat delay
This commit is contained in:
parent
907ad4819e
commit
77df8b1e6d
|
|
@ -11,12 +11,14 @@ import java.util.List;
|
||||||
|
|
||||||
public class FrameSpawnerLocation extends BukkitRunnable {
|
public class FrameSpawnerLocation extends BukkitRunnable {
|
||||||
|
|
||||||
int amount;
|
private int amount;
|
||||||
List<Frame> frames;
|
private final long repeatDelay;
|
||||||
Iterator<Frame> iterator;
|
private final List<Frame> frames;
|
||||||
Location location;
|
private Iterator<Frame> iterator;
|
||||||
public FrameSpawnerLocation(int amount, List<Frame> frames, Location location) {
|
private final Location location;
|
||||||
|
public FrameSpawnerLocation(int amount, int repeatDelay, List<Frame> frames, Location location) {
|
||||||
this.amount = amount;
|
this.amount = amount;
|
||||||
|
this.repeatDelay = (repeatDelay * 1000L) / 20;
|
||||||
this.frames = frames;
|
this.frames = frames;
|
||||||
this.iterator = frames.iterator();
|
this.iterator = frames.iterator();
|
||||||
this.location = location;
|
this.location = location;
|
||||||
|
|
@ -29,6 +31,13 @@ public class FrameSpawnerLocation extends BukkitRunnable {
|
||||||
else if (amount != 0) {
|
else if (amount != 0) {
|
||||||
iterator = frames.iterator();
|
iterator = frames.iterator();
|
||||||
amount--;
|
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 {
|
} else {
|
||||||
this.cancel();
|
this.cancel();
|
||||||
if (Config.DEBUG)
|
if (Config.DEBUG)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,10 @@
|
||||||
package com.alttd.frameSpawners;
|
package com.alttd.frameSpawners;
|
||||||
|
|
||||||
import com.alttd.config.Config;
|
import com.alttd.config.Config;
|
||||||
|
import com.alttd.objects.APartType;
|
||||||
import com.alttd.objects.Frame;
|
import com.alttd.objects.Frame;
|
||||||
|
import com.alttd.objects.ParticleSet;
|
||||||
|
import com.alttd.storage.PlayerSettings;
|
||||||
import com.alttd.util.Logger;
|
import com.alttd.util.Logger;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
@ -11,15 +14,23 @@ import java.util.List;
|
||||||
|
|
||||||
public class FrameSpawnerPlayer extends BukkitRunnable {
|
public class FrameSpawnerPlayer extends BukkitRunnable {
|
||||||
|
|
||||||
int amount;
|
private int amount;
|
||||||
List<Frame> frames;
|
private final long repeatDelay;
|
||||||
Iterator<Frame> iterator;
|
private final List<Frame> frames;
|
||||||
Player player;
|
private Iterator<Frame> iterator;
|
||||||
public FrameSpawnerPlayer(int amount, List<Frame> frames, Player player) {
|
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.amount = amount;
|
||||||
|
this.repeatDelay = (repeatDelay * 1000L) / 20;
|
||||||
this.frames = frames;
|
this.frames = frames;
|
||||||
this.iterator = frames.iterator();
|
this.iterator = frames.iterator();
|
||||||
this.player = player;
|
this.player = player;
|
||||||
|
this.playerSettings = playerSettings;
|
||||||
|
this.aPartType = aPartType;
|
||||||
|
this.uniqueId = uniqueId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -30,11 +41,26 @@ public class FrameSpawnerPlayer extends BukkitRunnable {
|
||||||
Logger.info("Stopped repeating task due to player offline.");
|
Logger.info("Stopped repeating task due to player offline.");
|
||||||
return;
|
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())
|
if (iterator.hasNext())
|
||||||
iterator.next().spawn(player.getLocation());
|
iterator.next().spawn(player.getLocation());
|
||||||
else if (amount != 0)
|
else if (amount != 0) {
|
||||||
iterator = frames.iterator();
|
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();
|
this.cancel();
|
||||||
if (Config.DEBUG)
|
if (Config.DEBUG)
|
||||||
Logger.info("Stopped repeating task due to end of frames.");
|
Logger.info("Stopped repeating task due to end of frames.");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user