forked from SteamWar/SteamWar
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:
@@ -58,7 +58,9 @@ import org.bukkit.event.inventory.InventoryType;
|
|||||||
import org.bukkit.event.player.*;
|
import org.bukkit.event.player.*;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
@@ -69,6 +71,7 @@ public class Recording implements Listener {
|
|||||||
|
|
||||||
private static final int AIR = 0;
|
private static final int AIR = 0;
|
||||||
private static final Random random = new Random();
|
private static final Random random = new Random();
|
||||||
|
private final Set<Entity> arrows = new HashSet<>();
|
||||||
|
|
||||||
public static ItemStack disarmNull(ItemStack stack) {
|
public static ItemStack disarmNull(ItemStack stack) {
|
||||||
if (stack == null) return new ItemStack(Material.AIR);
|
if (stack == null) return new ItemStack(Material.AIR);
|
||||||
@@ -109,6 +112,8 @@ public class Recording implements Listener {
|
|||||||
public void disable() {
|
public void disable() {
|
||||||
Fight.teams().forEach(Recording.this::despawnTeam);
|
Fight.teams().forEach(Recording.this::despawnTeam);
|
||||||
despawnTNT();
|
despawnTNT();
|
||||||
|
arrows.forEach(GlobalRecorder.getInstance()::entityDespawns);
|
||||||
|
arrows.clear();
|
||||||
}
|
}
|
||||||
}.register();
|
}.register();
|
||||||
new StateDependent(ArenaMode.AntiReplay, FightState.Ingame) {
|
new StateDependent(ArenaMode.AntiReplay, FightState.Ingame) {
|
||||||
@@ -133,6 +138,15 @@ public class Recording implements Listener {
|
|||||||
if (FightState.getFightState() == FightState.SPECTATE || !GlobalRecorder.getInstance().recording()) return;
|
if (FightState.getFightState() == FightState.SPECTATE || !GlobalRecorder.getInstance().recording()) return;
|
||||||
|
|
||||||
iterateOverEntities(primedTnt::isInstance, this::trackEntity);
|
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);
|
}, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,6 +269,9 @@ public class Recording implements Listener {
|
|||||||
GlobalRecorder.getInstance().fireballSpawn(e.getEntity());
|
GlobalRecorder.getInstance().fireballSpawn(e.getEntity());
|
||||||
} else if (e.getEntityType() == EntityType.ARROW) {
|
} else if (e.getEntityType() == EntityType.ARROW) {
|
||||||
GlobalRecorder.getInstance().arrowSpawn(e.getEntity());
|
GlobalRecorder.getInstance().arrowSpawn(e.getEntity());
|
||||||
|
if (GlobalRecorder.getInstance().recording()) {
|
||||||
|
arrows.add(e.getEntity());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user