diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TNTPosition.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TNTPosition.java index 38b6f844..be47e4bc 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TNTPosition.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TNTPosition.java @@ -22,41 +22,21 @@ package de.steamwar.bausystem.features.tracer; import de.steamwar.bausystem.features.tracer.show.Record; import de.steamwar.bausystem.shared.Position; import lombok.Getter; -import lombok.RequiredArgsConstructor; import org.bukkit.entity.TNTPrimed; import org.bukkit.util.Vector; -import java.util.function.Supplier; - @Getter public class TNTPosition extends Position { - @RequiredArgsConstructor - public static class CachingSupplier implements Supplier { - - private final Supplier supplier; - private boolean initialized; - private T value; - - @Override - public T get() { - if (!initialized) { - value = supplier.get(); - initialized = true; - } - return value; - } - } - private final Record.TNTRecord record; private final int fuseTicks; private final Vector previousLocation; private final Vector velocity; - private final CachingSupplier updateVelocity; + private final Vector updateVelocity; private final boolean source; private final boolean exploded; - public TNTPosition(Record.TNTRecord record, TNTPrimed entity, Vector previousLocation, Vector velocity, CachingSupplier updateVelocity, boolean source, boolean exploded) { + public TNTPosition(Record.TNTRecord record, TNTPrimed entity, Vector previousLocation, Vector velocity, Vector updateVelocity, boolean source, boolean exploded) { super(entity.getLocation().toVector()); this.record = record; this.fuseTicks = entity.getFuseTicks(); @@ -67,10 +47,6 @@ public class TNTPosition extends Position { this.exploded = exploded; } - public Vector getUpdateVelocity() { - return updateVelocity.get(); - } - @Override public String toString() { return "Position{" + diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/Record.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/Record.java index 09d0e832..8314b640 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/Record.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/Record.java @@ -118,21 +118,11 @@ public class Record { private void add(TNTPrimed tntPrimed, boolean source, boolean exploded) { TNTPosition position; if (positions.isEmpty()) { - position = new TNTPosition(this, tntPrimed, null, tntPrimed.getVelocity(), new TNTPosition.CachingSupplier<>(() -> null), source, exploded); + position = new TNTPosition(this, tntPrimed, null, tntPrimed.getVelocity(), null, source, exploded); } else { - int currentSize = positions.size() + 1; - TNTPosition.CachingSupplier velocitySupplier = new TNTPosition.CachingSupplier<>(() -> { - Vector current = null; - for (int i = currentSize - 1; i >= 0; i--) { - TNTPosition currentTNT = positions.get(i); - if ((currentTNT.getVelocity().getX() == 0 || currentTNT.getVelocity().getZ() == 0) && current != null) { - break; - } - current = currentTNT.getVelocity(); - } - return current; - }); - position = new TNTPosition(this, tntPrimed, positions.get(positions.size() - 1).getLocation(), tntPrimed.getVelocity(), velocitySupplier, source, exploded); + TNTPosition tntPosition = positions.get(positions.size() - 1); + Vector lastVelocity = tntPrimed.getLocation().toVector().clone().subtract(tntPosition.getLocation()); + position = new TNTPosition(this, tntPrimed, positions.get(positions.size() - 1).getLocation(), tntPrimed.getVelocity(), lastVelocity, source, exploded); } positions.add(position); TraceShowManager.show(region, position);