From 31f04ef07b8087db7a2139c4430c3351600d737a Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 3 Oct 2022 21:24:23 +0200 Subject: [PATCH] Add trace ShowModeParameterType.BUILD_DESTROY_ONLY Signed-off-by: yoyosource --- .../features/tracer/record/AutoTraceRecorder.java | 6 ++++-- .../bausystem/features/tracer/record/Recorder.java | 10 +++++++--- .../features/tracer/record/SimpleTraceRecorder.java | 6 ++++-- .../features/tracer/record/TraceRecorder.java | 2 +- .../bausystem/features/tracer/show/Record.java | 5 +++++ .../features/tracer/show/ShowModeParameter.java | 5 +++++ .../features/tracer/show/ShowModeParameterType.java | 5 +++-- .../features/tracer/show/StoredRecords.java | 12 ++++++++---- .../features/tracer/show/TraceShowManager.java | 7 +++++-- .../tracer/show/mode/FactoredEntityShowMode.java | 3 +++ 10 files changed, 45 insertions(+), 16 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/AutoTraceRecorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/AutoTraceRecorder.java index 4d43a30e..c8e66bac 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/AutoTraceRecorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/AutoTraceRecorder.java @@ -93,12 +93,14 @@ public abstract class AutoTraceRecorder implements TraceRecorder { } @Override - public final void explode(TNTPrimed tntPrimed) { + public final void explode(TNTPrimed tntPrimed, boolean inBuildRegion) { if (!recording && shouldStartRecording(StartType.EXPLODE)) { startRecording(); } if (recording) { - getRecord(tntPrimed).explode(tntPrimed); + Record.TNTRecord tntRecord = getRecord(tntPrimed); + if (inBuildRegion) tntRecord.setInBuildArea(true); + tntRecord.explode(tntPrimed); } lastExplosion = 0; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java index c61ba208..2942483b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java @@ -23,6 +23,8 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.tracer.show.Record; import de.steamwar.bausystem.features.tracer.show.StoredRecords; import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.region.utils.RegionExtensionType; +import de.steamwar.bausystem.region.utils.RegionType; import de.steamwar.linkage.Linked; import org.bukkit.Bukkit; import org.bukkit.World; @@ -62,7 +64,7 @@ public class Recorder implements Listener { } @Override - public void explode(TNTPrimed tntPrimed) { + public void explode(TNTPrimed tntPrimed, boolean b) { } } private static final NoopTraceRecorder NOOP = new NoopTraceRecorder(); @@ -82,7 +84,7 @@ public class Recorder implements Listener { } @Override - public void explode(TNTPrimed tntPrimed) { + public void explode(TNTPrimed tntPrimed, boolean b) { } } private static final DisabledTracerRecorder DISABLED = new DisabledTracerRecorder(); @@ -156,7 +158,9 @@ public class Recorder implements Listener { if (!(entity instanceof TNTPrimed)) { return; } - get((TNTPrimed) entity).explode((TNTPrimed) entity); + TraceRecorder traceRecorder = get((TNTPrimed) entity); + Region region = tntTraceRecorderMap.get((TNTPrimed) entity); + traceRecorder.explode((TNTPrimed) entity, !event.blockList().isEmpty() && region.inRegion(event.getLocation(), RegionType.BUILD, RegionExtensionType.EXTENSION)); tntTraceRecorderMap.remove(entity); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/SimpleTraceRecorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/SimpleTraceRecorder.java index d4aa228e..edd6dd48 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/SimpleTraceRecorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/SimpleTraceRecorder.java @@ -66,8 +66,10 @@ public class SimpleTraceRecorder implements TraceRecorder, ActiveTracer { } @Override - public void explode(TNTPrimed tntPrimed) { - getRecord(tntPrimed).explode(tntPrimed); + public void explode(TNTPrimed tntPrimed, boolean inBuildRegion) { + Record.TNTRecord tntRecord = getRecord(tntPrimed); + if (inBuildRegion) tntRecord.setInBuildArea(true); + tntRecord.explode(tntPrimed); recordMap.remove(tntPrimed); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/TraceRecorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/TraceRecorder.java index 29340eae..f89562ef 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/TraceRecorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/TraceRecorder.java @@ -35,7 +35,7 @@ public interface TraceRecorder { } void spawn(TNTPrimed tntPrimed); void tick(TNTPrimed tntPrimed); - void explode(TNTPrimed tntPrimed); + void explode(TNTPrimed tntPrimed, boolean inBuildRegion); default void tick() { } } 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 13a8e0af..71b19f1d 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 @@ -24,6 +24,7 @@ import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.shared.ShowMode; import lombok.Getter; import lombok.RequiredArgsConstructor; +import lombok.Setter; import org.bukkit.entity.TNTPrimed; import org.bukkit.util.Vector; @@ -70,6 +71,10 @@ public class Record { @Getter private final List positions = new ArrayList<>(82); + @Getter + @Setter + private boolean inBuildArea = false; + public TNTRecord(long offset, Region region) { this.offset = offset; this.region = region; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameter.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameter.java index 99dc8392..100e58c3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameter.java @@ -29,6 +29,7 @@ public class ShowModeParameter { private boolean sourceOnly = false; private boolean explodeOnly = false; private boolean ticks = false; + private boolean buildDestroyOnly = false; public void enableWater() { this.water = true; @@ -53,4 +54,8 @@ public class ShowModeParameter { public void enableTicks() { this.ticks = true; } + + public void enableBuildDestroyOnly() { + this.buildDestroyOnly = true; + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameterType.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameterType.java index e49b9abb..5f4bcb46 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameterType.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameterType.java @@ -29,7 +29,7 @@ import java.util.function.Supplier; public enum ShowModeParameterType { - WATER(ShowModeParameter::enableWater, Arrays.asList("-water"), "EXPLODE", "SOURCE"), + WATER(ShowModeParameter::enableWater, Arrays.asList("-water"), "EXPLODE", "SOURCE", "BUILD_DESTROY_ONLY"), INTERPOLATE_Y(ShowModeParameter::enableInterpolateY, Arrays.asList("-interpolatey", "-interpolate-y", "-interpolate_y", "-y"), "ADVANCED"), INTERPOLATE_XZ(ShowModeParameter::enableInterpolateXZ, Arrays.asList("-interpolatex", "-interpolate-x", "-interpolate_x", "-x", "-interpolatez", "-interpolate-z", "-interpolate_z", "-z", "-interpolatexz", "-interpolate-xz", "-interpolate_xz", "-xz"), "ADVANCED"), ADVANCED(showModeParameter -> { @@ -38,7 +38,8 @@ public enum ShowModeParameterType { }, Arrays.asList("-advanced", "-a", "advanced"), "INTERPOLATE_Y", "INTERPOLATE_XZ"), SOURCE(ShowModeParameter::enableSourceOnly, Arrays.asList("-source", "-sourceonly"), "TICKS", "ADVANCED", "INTERPOLATE_Y", "INTERPOLATE_XZ", "WATER"), EXPLODE(ShowModeParameter::enableExplodeOnly, Arrays.asList("-explode", "-explodeonly"), "TICKS", "ADVANCED", "INTERPOLATE_Y", "INTERPOLATE_XZ", "WATER"), - TICKS(ShowModeParameter::enableTicks, Arrays.asList("-ticks", "-t"), "EXPLODE", "SOURCE"); + TICKS(ShowModeParameter::enableTicks, Arrays.asList("-ticks", "-t"), "EXPLODE", "SOURCE"), + BUILD_DESTROY_ONLY(ShowModeParameter::enableBuildDestroyOnly, Arrays.asList("-builddestroy", "-builddestoryonly"), "WATER"); @Getter private final Consumer showModeParameterConsumer; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/StoredRecords.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/StoredRecords.java index 43e563d8..ef0a449b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/StoredRecords.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/StoredRecords.java @@ -155,18 +155,22 @@ public class StoredRecords { replayLoops.computeIfAbsent(region, k -> new HashMap<>()).put(player, loop); } - static void show(Region region, Player player, ShowMode traceShowMode) { + static Predicate replayTimeFilter(Region region, Player player) { Predicate replayTimeFilter = tntPosition -> true; if (replayTime.containsKey(region) && replayTime.get(region).containsKey(player)) { int time = replayTime.get(region).get(player); replayTimeFilter = tntPosition -> (80 - tntPosition.getFuseTicks()) + tntPosition.getRecord().getOffset() == time; } - Predicate finalReplayTimeFilter = replayTimeFilter; + return replayTimeFilter; + } + + static void show(Region region, Player player, ShowMode traceShowMode) { + Predicate replayTimeFilter = replayTimeFilter(region, player); if (isolatedTNT.containsKey(region) && isolatedTNT.get(region).containsKey(player)) { isolatedTNT.get(region).get(player).forEach(record -> { record.getPositions() .stream() - .filter(finalReplayTimeFilter) + .filter(replayTimeFilter) .forEach(traceShowMode::show); }); } else { @@ -174,7 +178,7 @@ public class StoredRecords { record.getTnt().forEach(tntRecord -> { tntRecord.getPositions() .stream() - .filter(finalReplayTimeFilter) + .filter(replayTimeFilter) .forEach(traceShowMode::show); }); }); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/TraceShowManager.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/TraceShowManager.java index fa7306cd..d04ee169 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/TraceShowManager.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/TraceShowManager.java @@ -34,6 +34,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.function.Predicate; public class TraceShowManager implements Listener { private TraceShowManager() { @@ -137,8 +138,10 @@ public class TraceShowManager implements Listener { if (regionalShowModes == null) { return; } - // TODO: Fix show with replay - regionalShowModes.values().forEach(tntPositionShowMode -> tntPositionShowMode.show(tnt)); + regionalShowModes.forEach((player, tntPositionShowMode) -> { + Predicate replayTimeFilter = StoredRecords.replayTimeFilter(region, player); + if (replayTimeFilter.test(tnt)) tntPositionShowMode.show(tnt); + }); } /* Only to be called by StoredRecords */ diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/mode/FactoredEntityShowMode.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/mode/FactoredEntityShowMode.java index 1029b648..93dbaa0c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/mode/FactoredEntityShowMode.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/mode/FactoredEntityShowMode.java @@ -55,6 +55,9 @@ public abstract class FactoredEntityShowMode implements EntityTraceShowMode { @Override public void show(TNTPosition position) { + if (showModeParameter.isBuildDestroyOnly() && !position.getRecord().isInBuildArea()) { + return; + } if (showModeParameter.isExplodeOnly()) { if (position.isExploded()) { RoundedPosition roundedPosition = new RoundedPosition(position, factor);