Fix replay arrow movement and visibility

Record arrow positions and velocity every tick so replay hull visibility follows arrows leaving schematics. Record despawns and clear tracked arrows when the fight ends.

Fixes #524
This commit is contained in:
einfachButzi
2026-11-12 01:33:41 +01:00
parent fb8711f357
commit a74a8e3a4c
@@ -58,7 +58,9 @@ import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.*;
import org.bukkit.inventory.ItemStack;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Predicate;
@@ -69,6 +71,7 @@ public class Recording implements Listener {
private static final int AIR = 0;
private static final Random random = new Random();
private final Set<Entity> arrows = new HashSet<>();
public static ItemStack disarmNull(ItemStack stack) {
if (stack == null) return new ItemStack(Material.AIR);
@@ -109,6 +112,8 @@ public class Recording implements Listener {
public void disable() {
Fight.teams().forEach(Recording.this::despawnTeam);
despawnTNT();
arrows.forEach(GlobalRecorder.getInstance()::entityDespawns);
arrows.clear();
}
}.register();
new StateDependent(ArenaMode.AntiReplay, FightState.Ingame) {
@@ -133,6 +138,15 @@ public class Recording implements Listener {
if (FightState.getFightState() == FightState.SPECTATE || !GlobalRecorder.getInstance().recording()) return;
iterateOverEntities(primedTnt::isInstance, this::trackEntity);
// Arrow movement also updates replay visibility when crossing a schematic's hull.
arrows.removeIf(arrow -> {
if (!arrow.isValid()) {
GlobalRecorder.getInstance().entityDespawns(arrow);
return true;
}
trackEntity(arrow);
return false;
});
}, 1, 1);
}
@@ -255,6 +269,9 @@ public class Recording implements Listener {
GlobalRecorder.getInstance().fireballSpawn(e.getEntity());
} else if (e.getEntityType() == EntityType.ARROW) {
GlobalRecorder.getInstance().arrowSpawn(e.getEntity());
if (GlobalRecorder.getInstance().recording()) {
arrows.add(e.getEntity());
}
}
}