SteamWar/BauSystem2.0
Archiviert
12
0

Add TraceCommand.showAtCommand, TraceCommand.showFromCommand and TraceCommand.showFromToCommand
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2023-09-27 11:44:01 +02:00
Ursprung 925ba19ff3
Commit 8217e9645b
8 geänderte Dateien mit 113 neuen und 43 gelöschten Zeilen

Datei anzeigen

@ -31,16 +31,21 @@ public class TNTPosition extends Position {
private final Record.TNTRecord record;
private final int fuseTicks;
private final long timeTicks;
private final Vector previousLocation;
private final Vector velocity;
private final Vector updateVelocity;
private final boolean source;
private final boolean exploded;
public TNTPosition(Record.TNTRecord record, TNTPrimed entity, Vector previousLocation, Vector velocity, Vector updateVelocity, boolean source, boolean exploded) {
@Setter
private boolean microMotion;
public TNTPosition(Record.TNTRecord record, TNTPrimed entity, long timeTicks, Vector previousLocation, Vector velocity, Vector updateVelocity, boolean source, boolean exploded) {
super(entity.getLocation().toVector());
this.record = record;
this.fuseTicks = entity.getFuseTicks();
this.timeTicks = timeTicks;
this.previousLocation = previousLocation;
this.velocity = velocity;
this.updateVelocity = updateVelocity;

Datei anzeigen

@ -124,6 +124,36 @@ public class TraceCommand extends SWCommand {
BauSystem.MESSAGE.send("TRACE_MESSAGE_AUTO_DELETE_" + autoTraceRecorder.getTraceRecordAutoDeletion().name(), p);
}
@Register(value = {"show"})
public void showAtCommand(@Validator Player p, @OptionalValue("time") @StaticValue({"time", "fuse"}) String type, @StaticValue("at") String __, @Min(intValue = 0) int at) {
showFromToCommand(p, type, __, at, __, at);
}
@Register(value = {"show"})
public void showFromCommand(@Validator Player p, @OptionalValue("time") @StaticValue({"time", "fuse"}) String type, @StaticValue("from") String __, @Min(intValue = 0) int from) {
if (from == 0) {
TraceShowManager.setShowFilter(p, null);
return;
}
showFromToCommand(p, type, __, from, __, Integer.MAX_VALUE);
}
@Register(value = {"show"})
public void showFromToCommand(@Validator Player p, @OptionalValue("time") @StaticValue({"time", "fuse"}) String type, @StaticValue("from") String __, @Min(intValue = 0) int from, @StaticValue("to") String ___, @Min(intValue = 0) int to) {
TraceShowManager.setShowFilter(p, tntPosition -> {
switch (type) {
case "time":
return tntPosition.getTimeTicks() >= from && tntPosition.getTimeTicks() <= to;
case "fuse":
return tntPosition.getFuseTicks() >= from && tntPosition.getFuseTicks() <= to;
default:
return true;
}
});
}
// /trace show at 0
// /trace show raw -auto at 0
@Register(value = {"show"}, description = "TRACE_COMMAND_HELP_SHOW")
public void showCommand(@Validator Player p, @OptionalValue("entity") ShowModeType showModeType, ShowModeParameterType... showModeParameterTypes) {
ShowModeParameter showModeParameter = new ShowModeParameter();

Datei anzeigen

@ -99,7 +99,7 @@ public class EntityShowMode implements ShowMode<TNTPosition> {
if (position.isExploded()) {
generatePositions(position, false, false);
}
if (!showModeParameter.isSourceOnly() && !hideWater) {
if (!showModeParameter.isSourceOnly() && !showModeParameter.isMicroMotionLocation() && !hideWater) {
return;
}
}
@ -108,6 +108,15 @@ public class EntityShowMode implements ShowMode<TNTPosition> {
if (position.isSource()) {
generatePositions(position, false, false);
}
if (!showModeParameter.isMicroMotionLocation() && !hideWater) {
return;
}
}
if (showModeParameter.isMicroMotionLocation()) {
if (position.isMicroMotion()) {
generatePositions(position, false, false);
}
if (!hideWater) {
return;
}

Datei anzeigen

@ -19,6 +19,7 @@
package de.steamwar.bausystem.features.tracer.show;
import de.steamwar.bausystem.features.tpslimit.TPSUtils;
import de.steamwar.bausystem.features.tracer.TNTPosition;
import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.shared.ShowMode;
@ -38,6 +39,7 @@ public class Record {
@Getter
private final List<TNTRecord> tnt = new ArrayList<>();
private final Region region;
private final long startTicks = TPSUtils.currentTick.get();
public int size() {
return tnt.size();
@ -57,18 +59,21 @@ public class Record {
tnt.clear();
}
private void checkMicroMotion() {
private void checkMicroMotion(Vector explosionPosition) {
for (TNTRecord tntRecord : tnt) {
List<TNTPosition> positions = tntRecord.positions;
if (positions.isEmpty()) continue;
TNTPosition position = positions.get(positions.size() - 1);
if (position.isExploded()) continue;
if (position.getLocation().distanceSquared(explosionPosition) > 64) continue;
Vector velocity = position.getVelocity();
if (velocity.getY() == 0 && (velocity.getX() != 0 || velocity.getZ() != 0) && (Math.abs(velocity.getX()) < 0.001 || Math.abs(velocity.getZ()) < 0.001)) {
if (velocity.getY() == 0 && ((velocity.getX() != 0 && Math.abs(velocity.getX()) < 0.001) || (velocity.getZ() != 0 && Math.abs(velocity.getZ()) < 0.001))) {
if (!tntRecord.hasMicroMotion) {
positions.forEach(tntPosition -> TraceShowManager.show(region, tntPosition));
}
tntRecord.hasMicroMotion = true;
position.setMicroMotion(true);
}
}
}
@ -112,17 +117,17 @@ public class Record {
public void explode(TNTPrimed tntPrimed) {
add(tntPrimed, false, true);
record.checkMicroMotion();
record.checkMicroMotion(tntPrimed.getLocation().toVector());
}
private void add(TNTPrimed tntPrimed, boolean source, boolean exploded) {
TNTPosition position;
if (positions.isEmpty()) {
position = new TNTPosition(this, tntPrimed, null, tntPrimed.getVelocity(), null, source, exploded);
position = new TNTPosition(this, tntPrimed, TPSUtils.currentTick.get() - record.startTicks, null, tntPrimed.getVelocity(), null, source, exploded);
} else {
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);
position = new TNTPosition(this, tntPrimed, TPSUtils.currentTick.get() - record.startTicks, positions.get(positions.size() - 1).getLocation(), tntPrimed.getVelocity(), lastVelocity, source, exploded);
}
positions.add(position);
TraceShowManager.show(region, position);

Datei anzeigen

@ -33,6 +33,7 @@ public class ShowModeParameter {
private boolean buildDestroyOnly = false;
private boolean testblockDestroyOnly = false;
private boolean microMotion = false;
private boolean microMotionLocation = false;
public void enableWater() {
this.water = true;
@ -73,4 +74,8 @@ public class ShowModeParameter {
public void enableMicroMotion() {
this.microMotion = true;
}
public void enableMicroMotionLocation() {
this.microMotionLocation = true;
}
}

Datei anzeigen

@ -43,6 +43,7 @@ public enum ShowModeParameterType {
BUILD_DESTROY_ONLY(ShowModeParameter::enableBuildDestroyOnly, Arrays.asList("-builddestroy", "-builddestoryonly"), "WATER", "TESTBLOCK_DESTROY_ONLY"),
TESTBLOCK_DESTROY_ONLY(ShowModeParameter::enableTestblockDestroyOnly, Arrays.asList("-testblockdestroy", "-testblockdestroyonly"), "WATER", "BUILD_DESTROY_ONLY"),
MICROMOTION(ShowModeParameter::enableMicroMotion, Arrays.asList("-micromotion", "-micro", "-m")),
MICROMOTION_LOCATION(ShowModeParameter::enableMicroMotionLocation, Arrays.asList("-micromotionloc", "-microloc", "-mloc", "-micromotionlocation", "-microlocation", "-mlocation")),
;
@Getter

Datei anzeigen

@ -26,6 +26,7 @@ import de.steamwar.bausystem.shared.ShowMode;
import lombok.experimental.UtilityClass;
import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Collectors;
@UtilityClass
@ -57,20 +58,11 @@ public class StoredRecords {
return records.getOrDefault(region, Collections.emptyList());
}
public Record.TNTRecord getRecord(UUID id) {
return records.values().stream()
.flatMap(Collection::stream)
.map(Record::getTnt)
.flatMap(Collection::stream)
.filter(tntRecord -> tntRecord.getId().equals(id))
.findFirst()
.orElse(null);
}
static void show(Region region, ShowMode<TNTPosition> traceShowMode) {
static void show(Region region, Predicate<TNTPosition> traceShowFilter, ShowMode<TNTPosition> traceShowMode) {
records.getOrDefault(region, new ArrayList<>()).forEach(record -> {
record.getTnt().forEach(tntRecord -> {
tntRecord.getPositions()
tntRecord.getPositions().stream()
.filter(traceShowFilter)
.forEach(traceShowMode::show);
});
});

Datei anzeigen

@ -31,46 +31,43 @@ import org.bukkit.event.player.PlayerQuitEvent;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Predicate;
public class TraceShowManager implements Listener {
private TraceShowManager() {
}
private static final Map<Region, Map<Player, ShowMode<TNTPosition>>> showModes = new HashMap<>();
private static final Map<Region, Map<Player, Predicate<TNTPosition>>> showFilters = new HashMap<>();
public static void show(Player player, ShowMode<TNTPosition> traceShowMode) {
hide(player);
Region region = Region.getRegion(player.getLocation());
_hide(region, player, true);
Map<Player, ShowMode<TNTPosition>> regionalShowModes = showModes.computeIfAbsent(region, __ -> new HashMap<>());
regionalShowModes.put(player, traceShowMode);
StoredRecords.show(region, traceShowMode);
StoredRecords.show(region, getShowFilter(player, region), traceShowMode);
}
public static void hide(Player player) {
Region region = Region.getRegion(player.getLocation());
Map<Player, ShowMode<TNTPosition>> regionalShowModes = showModes.get(region);
if (regionalShowModes == null) {
return;
}
ShowMode<TNTPosition> showMode = regionalShowModes.remove(player);
if (showMode == null) {
return;
}
showMode.hide();
_hide(region, player, true);
showFilters.getOrDefault(region, new HashMap<>()).remove(player);
}
public static void reshow(Region region, Player p) {
Map<Player, ShowMode<TNTPosition>> regionalShowModes = showModes.get(region);
if (regionalShowModes == null) {
return;
public static void setShowFilter(Player player, Predicate<TNTPosition> showFilter) {
Region region = Region.getRegion(player.getLocation());
Map<Player, Predicate<TNTPosition>> regionShowFilters = showFilters.computeIfAbsent(region, __ -> new HashMap<>());
if (showFilter == null) {
regionShowFilters.remove(player);
} else {
regionShowFilters.put(player, showFilter);
}
ShowMode<TNTPosition> showMode = regionalShowModes.get(p);
if (showMode == null) {
return;
}
showMode.hide();
StoredRecords.show(region, showMode);
_hide(region, player, false);
ShowMode<TNTPosition> showMode = showModes.computeIfAbsent(region, __ -> new HashMap<>()).computeIfAbsent(player, __ -> new EntityShowMode(player, new ShowModeParameter(), 10));
StoredRecords.show(region, getShowFilter(player, region), showMode);
}
public static void reshow(Region region) {
@ -80,10 +77,31 @@ public class TraceShowManager implements Listener {
}
for (Map.Entry<Player, ShowMode<TNTPosition>> entry : regionalShowModes.entrySet()) {
entry.getValue().hide();
StoredRecords.show(region, entry.getValue());
StoredRecords.show(region, getShowFilter(entry.getKey(), region), entry.getValue());
}
}
private static void _hide(Region region, Player player, boolean remove) {
Map<Player, ShowMode<TNTPosition>> regionalShowModes = showModes.get(region);
if (regionalShowModes == null) {
return;
}
ShowMode<TNTPosition> showMode;
if (remove) {
showMode = regionalShowModes.remove(player);
} else {
showMode = regionalShowModes.get(player);
}
if (showMode == null) {
return;
}
showMode.hide();
}
private static Predicate<TNTPosition> getShowFilter(Player player, Region region) {
return showFilters.getOrDefault(region, new HashMap<>()).getOrDefault(player, tntPosition -> true);
}
/* Only to be called by record */
static void show(Region region, TNTPosition tnt) {
Map<Player, ShowMode<TNTPosition>> regionalShowModes = showModes.get(region);
@ -91,7 +109,9 @@ public class TraceShowManager implements Listener {
return;
}
regionalShowModes.forEach((player, tntPositionShowMode) -> {
if (getShowFilter(player, region).test(tnt)) {
tntPositionShowMode.show(tnt);
}
});
}
@ -115,5 +135,8 @@ public class TraceShowManager implements Listener {
ShowMode<TNTPosition> showMode = playerShowModeMap.remove(event.getPlayer());
if (showMode != null) showMode.hide();
});
showFilters.forEach((region, playerPredicateMap) -> {
playerPredicateMap.remove(event.getPlayer());
});
}
}