Fixed frames not properly repeating at the right speed

This commit is contained in:
Teriuihi 2022-08-31 05:13:18 +02:00
parent 77dcd8862c
commit be97b45833
3 changed files with 36 additions and 19 deletions

View File

@ -1,5 +1,6 @@
package com.alttd.frameSpawners; package com.alttd.frameSpawners;
import com.alttd.AltitudeParticles;
import com.alttd.config.Config; import com.alttd.config.Config;
import com.alttd.objects.Frame; import com.alttd.objects.Frame;
import com.alttd.util.Logger; import com.alttd.util.Logger;
@ -16,26 +17,33 @@ public class FrameSpawnerLocation extends BukkitRunnable {
private Iterator<Frame> iterator; private Iterator<Frame> iterator;
private final Location location; private final Location location;
private final float rotation; private final float rotation;
public FrameSpawnerLocation(int amount, List<Frame> frames, Location location, float rotation) { private final int frameDelay;
public FrameSpawnerLocation(int amount, List<Frame> frames, int frameDelay, Location location, float rotation) {
this.amount = amount; this.amount = amount;
this.frames = frames; this.frames = frames;
this.iterator = frames.iterator(); this.iterator = frames.iterator();
this.location = location; this.location = location;
this.rotation = rotation; this.rotation = rotation;
this.frameDelay = frameDelay;
} }
@Override @Override
public void run() { public void run() {
if (iterator.hasNext()) if (amount == 0){
iterator.next().spawn(location, rotation);
else if (amount != 0) {
iterator = frames.iterator();
if (amount > 0)
amount--;
} 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");
} }
new BukkitRunnable() {
@Override
public void run() {
if (!iterator.hasNext())
this.cancel();
iterator.next().spawn(location, rotation);
}
}.runTaskTimerAsynchronously(AltitudeParticles.getInstance(), 0, frameDelay);
iterator = frames.iterator();
if (amount != -1)
amount--;
} }
} }

View File

@ -1,5 +1,6 @@
package com.alttd.frameSpawners; package com.alttd.frameSpawners;
import com.alttd.AltitudeParticles;
import com.alttd.config.Config; import com.alttd.config.Config;
import com.alttd.objects.APartType; import com.alttd.objects.APartType;
import com.alttd.objects.Frame; import com.alttd.objects.Frame;
@ -21,7 +22,8 @@ public class FrameSpawnerPlayer extends BukkitRunnable {
private final PlayerSettings playerSettings; private final PlayerSettings playerSettings;
private final APartType aPartType; private final APartType aPartType;
private final String uniqueId; private final String uniqueId;
public FrameSpawnerPlayer(int amount, List<Frame> frames, Player player, PlayerSettings playerSettings, APartType aPartType, String uniqueId) { private final int frameDelay;
public FrameSpawnerPlayer(int amount, List<Frame> frames, int frameDelay, Player player, PlayerSettings playerSettings, APartType aPartType, String uniqueId) {
this.amount = amount; this.amount = amount;
this.frames = frames; this.frames = frames;
this.iterator = frames.iterator(); this.iterator = frames.iterator();
@ -29,6 +31,7 @@ public class FrameSpawnerPlayer extends BukkitRunnable {
this.playerSettings = playerSettings; this.playerSettings = playerSettings;
this.aPartType = aPartType; this.aPartType = aPartType;
this.uniqueId = uniqueId; this.uniqueId = uniqueId;
this.frameDelay = frameDelay;
} }
@Override @Override
@ -46,15 +49,21 @@ public class FrameSpawnerPlayer extends BukkitRunnable {
Logger.info("Stopped repeating task due to player switching/disabling particles."); Logger.info("Stopped repeating task due to player switching/disabling particles.");
return; return;
} }
if (iterator.hasNext()) if (amount == 0) {
iterator.next().spawn(player.getLocation(), player.getLocation().getYaw());
else if (amount != 0) {
iterator = frames.iterator();
amount--;
} 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.");
} }
new BukkitRunnable() {
@Override
public void run() {
if (!iterator.hasNext())
this.cancel();
iterator.next().spawn(player.getLocation(), player.getLocation().getYaw());
}
}.runTaskTimerAsynchronously(AltitudeParticles.getInstance(), 0, frameDelay);
iterator = frames.iterator();
if (amount != -1)
amount--;
} }
} }

View File

@ -48,8 +48,8 @@ public class ParticleSet {
public void run(Location location, Player player) { public void run(Location location, Player player) {
if (tooSoon(player.getUniqueId()) || isVanished(player)) if (tooSoon(player.getUniqueId()) || isVanished(player))
return; return;
FrameSpawnerLocation frameSpawnerLocation = new FrameSpawnerLocation(repeat, frames, location, player.getLocation().getYaw()); FrameSpawnerLocation frameSpawnerLocation = new FrameSpawnerLocation(repeat, frames, frameDelay, location, player.getLocation().getYaw());
frameSpawnerLocation.runTaskTimerAsynchronously(AltitudeParticles.getInstance(), frameDelay, repeatDelay); frameSpawnerLocation.runTaskTimerAsynchronously(AltitudeParticles.getInstance(), 0, repeatDelay);
} }
public void run(Player player, PlayerSettings playerSettings) { public void run(Player player, PlayerSettings playerSettings) {
@ -57,8 +57,8 @@ public class ParticleSet {
return; return;
if (Config.DEBUG) if (Config.DEBUG)
Logger.info("Starting particle set % for %.", uniqueId, player.getName()); Logger.info("Starting particle set % for %.", uniqueId, player.getName());
FrameSpawnerPlayer frameSpawnerPlayer = new FrameSpawnerPlayer(repeat, frames, player, playerSettings, aPartType, uniqueId); FrameSpawnerPlayer frameSpawnerPlayer = new FrameSpawnerPlayer(repeat, frames, frameDelay, player, playerSettings, aPartType, uniqueId);
frameSpawnerPlayer.runTaskTimerAsynchronously(AltitudeParticles.getInstance(), frameDelay, repeatDelay); frameSpawnerPlayer.runTaskTimerAsynchronously(AltitudeParticles.getInstance(), 0, repeatDelay);
} }
private boolean isVanished(Player player) { private boolean isVanished(Player player) {