Fix frame iterator resetting mid run, improved logging

Frame iterator was resetting every run due to a shared iterator between runs, this is now unique per run.
Include frame keys for logging, log the frame spawning in debug logs.
This commit is contained in:
akastijn 2026-02-08 19:48:20 +01:00
parent f6ee8eacf5
commit b60df9dc8d
3 changed files with 31 additions and 14 deletions

View File

@ -150,7 +150,7 @@ public class ParticleConfig {
* @return A ParticleSet created from the ParticleData * @return A ParticleSet created from the ParticleData
*/ */
public ParticleSet convertToParticleSet(ParticleData particleData) { public ParticleSet convertToParticleSet(ParticleData particleData) {
log.info("Converting ParticleData to ParticleSet for {}", particleData.getParticleName()); log.info("Converting ParticleData to ParticleSet for [{}]", particleData.getParticleName());
List<Frame> loadedFrames = new ArrayList<>(); List<Frame> loadedFrames = new ArrayList<>();
double randomOffset = particleData.getRandomOffset(); double randomOffset = particleData.getRandomOffset();
@ -175,7 +175,11 @@ public class ParticleConfig {
aParticleList.add(new AParticle(x, y + 0.2, z, randomOffset, particleBuilder)); aParticleList.add(new AParticle(x, y + 0.2, z, randomOffset, particleBuilder));
} }
loadedFrames.add(new Frame(aParticleList)); loadedFrames.add(new Frame(entry.getKey(), aParticleList));
}
if (Config.DEBUG) {
log.info("Loaded {} frames for [{}]", loadedFrames.size(), particleData.getParticleName());
} }
// Create and return the ParticleSet // Create and return the ParticleSet

View File

@ -24,7 +24,6 @@ public class FrameSpawnerPlayer extends BukkitRunnable {
private int amount; private int amount;
private final List<Frame> frames; private final List<Frame> frames;
private Iterator<Frame> iterator;
private final Player player; private final Player player;
private final PlayerSettings playerSettings; private final PlayerSettings playerSettings;
private final APartType aPartType; private final APartType aPartType;
@ -34,7 +33,6 @@ public class FrameSpawnerPlayer extends BukkitRunnable {
public FrameSpawnerPlayer(int amount, List<Frame> frames, int frameDelay, Player player, PlayerSettings playerSettings, APartType aPartType, String uniqueId, boolean stationary) { public FrameSpawnerPlayer(int amount, List<Frame> frames, int frameDelay, Player player, PlayerSettings playerSettings, APartType aPartType, String uniqueId, boolean stationary) {
this.amount = amount; this.amount = amount;
this.frames = frames; this.frames = frames;
this.iterator = frames.iterator();
this.player = player; this.player = player;
this.playerSettings = playerSettings; this.playerSettings = playerSettings;
this.aPartType = aPartType; this.aPartType = aPartType;
@ -58,26 +56,27 @@ public class FrameSpawnerPlayer extends BukkitRunnable {
Location location = player.getLocation(); Location location = player.getLocation();
float yaw = location.getYaw(); float yaw = location.getYaw();
ParticleSet activeParticleSet = playerSettings.getParticles(aPartType); ParticleSet activeParticleSet = playerSettings.getParticles(aPartType);
if (activeParticleSet == null || !activeParticleSet.getParticleId().equalsIgnoreCase(uniqueId) || !playerSettings.hasActiveParticles()) { if (shouldStopTask(activeParticleSet)) return;
this.cancel();
if (Config.DEBUG)
log.info("Stopped repeating task due to player switching/disabling particles.");
return;
}
if (amount == 0) { if (amount == 0) {
this.cancel(); this.cancel();
if (Config.DEBUG) if (Config.DEBUG)
log.info("Stopped repeating task due to end of frames."); log.info("Stopped repeating task due to end of frames.");
} }
iterator = frames.iterator(); final Iterator<Frame> iterator = frames.iterator();
if (Config.DEBUG) {
log.info("Starting frame spawn for player {}.", player.getName());
}
new BukkitRunnable() { new BukkitRunnable() {
@Override @Override
public void run() { public void run() {
if (!iterator.hasNext()) { if (!iterator.hasNext() || shouldStopTask(activeParticleSet)) {
this.cancel(); this.cancel();
return; return;
} }
Frame next = iterator.next(); Frame next = iterator.next();
if (Config.DEBUG) {
log.info("Spawning frame with {} particles at {} for player {}", next.getKey(), location, player.getName());
}
if (stationary) { if (stationary) {
next.spawn(location, yaw); next.spawn(location, yaw);
} }
@ -90,6 +89,16 @@ public class FrameSpawnerPlayer extends BukkitRunnable {
amount--; amount--;
} }
private boolean shouldStopTask(ParticleSet activeParticleSet) {
if (activeParticleSet == null || !activeParticleSet.getParticleId().equalsIgnoreCase(uniqueId) || !playerSettings.hasActiveParticles()) {
this.cancel();
if (Config.DEBUG)
log.info("Stopped repeating task due to player switching/disabling particles.");
return true;
}
return false;
}
private boolean isVanished(Player player) { private boolean isVanished(Player player) {
return VanishAPI.isInvisible(player) || player.getGameMode().equals(GameMode.SPECTATOR); return VanishAPI.isInvisible(player) || player.getGameMode().equals(GameMode.SPECTATOR);
} }

View File

@ -1,6 +1,7 @@
package com.alttd.objects; package com.alttd.objects;
import com.alttd.storage.PlayerSettings; import com.alttd.storage.PlayerSettings;
import lombok.Getter;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -11,9 +12,12 @@ import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class Frame { public class Frame {
List<AParticle> aParticles; @Getter
private final String key;
private final List<AParticle> aParticles;
public Frame(List<AParticle> aParticles) { public Frame(String key, List<AParticle> aParticles) {
this.key = key;
this.aParticles = aParticles; this.aParticles = aParticles;
} }