Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
a8aa431210
Commit
6400e20bbb
@ -22,41 +22,21 @@ package de.steamwar.bausystem.features.tracer;
|
|||||||
import de.steamwar.bausystem.features.tracer.show.Record;
|
import de.steamwar.bausystem.features.tracer.show.Record;
|
||||||
import de.steamwar.bausystem.shared.Position;
|
import de.steamwar.bausystem.shared.Position;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.bukkit.entity.TNTPrimed;
|
import org.bukkit.entity.TNTPrimed;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class TNTPosition extends Position {
|
public class TNTPosition extends Position {
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public static class CachingSupplier<T> implements Supplier<T> {
|
|
||||||
|
|
||||||
private final Supplier<T> 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 Record.TNTRecord record;
|
||||||
private final int fuseTicks;
|
private final int fuseTicks;
|
||||||
private final Vector previousLocation;
|
private final Vector previousLocation;
|
||||||
private final Vector velocity;
|
private final Vector velocity;
|
||||||
private final CachingSupplier<Vector> updateVelocity;
|
private final Vector updateVelocity;
|
||||||
private final boolean source;
|
private final boolean source;
|
||||||
private final boolean exploded;
|
private final boolean exploded;
|
||||||
|
|
||||||
public TNTPosition(Record.TNTRecord record, TNTPrimed entity, Vector previousLocation, Vector velocity, CachingSupplier<Vector> 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());
|
super(entity.getLocation().toVector());
|
||||||
this.record = record;
|
this.record = record;
|
||||||
this.fuseTicks = entity.getFuseTicks();
|
this.fuseTicks = entity.getFuseTicks();
|
||||||
@ -67,10 +47,6 @@ public class TNTPosition extends Position {
|
|||||||
this.exploded = exploded;
|
this.exploded = exploded;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector getUpdateVelocity() {
|
|
||||||
return updateVelocity.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Position{" +
|
return "Position{" +
|
||||||
|
@ -118,21 +118,11 @@ public class Record {
|
|||||||
private void add(TNTPrimed tntPrimed, boolean source, boolean exploded) {
|
private void add(TNTPrimed tntPrimed, boolean source, boolean exploded) {
|
||||||
TNTPosition position;
|
TNTPosition position;
|
||||||
if (positions.isEmpty()) {
|
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 {
|
} else {
|
||||||
int currentSize = positions.size() + 1;
|
TNTPosition tntPosition = positions.get(positions.size() - 1);
|
||||||
TNTPosition.CachingSupplier<Vector> velocitySupplier = new TNTPosition.CachingSupplier<>(() -> {
|
Vector lastVelocity = tntPrimed.getLocation().toVector().clone().subtract(tntPosition.getLocation());
|
||||||
Vector current = null;
|
position = new TNTPosition(this, tntPrimed, positions.get(positions.size() - 1).getLocation(), tntPrimed.getVelocity(), lastVelocity, source, exploded);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
positions.add(position);
|
positions.add(position);
|
||||||
TraceShowManager.show(region, position);
|
TraceShowManager.show(region, position);
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren