diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index d7574fa7..84378b95 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -707,6 +707,10 @@ TRACE_COMMAND_HELP_SHOW = §8/§etrace show §8<§eParameter§8> - §7Shows all TRACE_COMMAND_HELP_HIDE = §8/§etrace hide §8- §7Hides all TNT-positions TRACE_COMMAND_HELP_DELETE = §8/§etrace delete §8- §7Deletes all TNT-positions TRACE_COMMAND_HELP_GUI = §8/§etrace gui §8- §7Shows the Trace GUI +TRACE_COMMAND_HELP_REPLAY = §8/§etrace replay §8[§7Tick§8] §8- §7Replays your recording +TRACE_COMMAND_HELP_REPLAY_DISABLE = §8/§etrace replay disable §8- §7Stops the replay +TRACE_COMMAND_HELP_REPLAY_NEXT = §8/§etrace replay next §8[§7Step§8] §8- §7Jump one tick forward +TRACE_COMMAND_HELP_REPLAY_PREVIOUS = §8/§etrace replay previous §8[§7Step§8] §8- §7Jump one tick back TRACE_GUI_ITEM_NAME = §eTracer TRACE_GUI_ITEM_LORE = §7Status§8: {0} diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index b9373877..b7b50a7a 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -687,6 +687,10 @@ TRACE_COMMAND_HELP_SHOW = §8/§etrace show §8<§eParameter§8> - §7Zeigt alle TRACE_COMMAND_HELP_HIDE = §8/§etrace hide §8- §7Versteckt alle TNT-Positionen TRACE_COMMAND_HELP_DELETE = §8/§etrace delete §8- §7Löscht alle TNT-Positionen TRACE_COMMAND_HELP_GUI = §8/§etrace gui §8- §7Zeigt die Trace Oberfläche an +TRACE_COMMAND_HELP_REPLAY = §8/§etrace replay §8- §7Replayes die Aufnahme +TRACE_COMMAND_HELP_REPLAY_DISABLE = §8/§etrace replay disable §8- §7Stoppt das Replay +TRACE_COMMAND_HELP_REPLAY_NEXT = §8/§etrace replay next §8- §7Springe ein Tick vor +TRACE_COMMAND_HELP_REPLAY_PREVIOUS = §8/§etrace replay previous §8- §7Springe ein Tick zurück TRACE_GUI_ITEM_NAME = §eTracer TRACE_GUI_ITEM_LORE = §7Status§8: {0} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java index bf385f06..564f7cc7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java @@ -24,10 +24,7 @@ import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.features.tracer.gui.TraceGui; import de.steamwar.bausystem.features.tracer.record.*; import de.steamwar.bausystem.features.tracer.show.Record; -import de.steamwar.bausystem.features.tracer.show.ShowModeParameter; -import de.steamwar.bausystem.features.tracer.show.ShowModeParameterType; -import de.steamwar.bausystem.features.tracer.show.StoredRecords; -import de.steamwar.bausystem.features.tracer.show.TraceShowManager; +import de.steamwar.bausystem.features.tracer.show.*; import de.steamwar.bausystem.features.tracer.show.mode.RawEntityShowMode; import de.steamwar.bausystem.features.tracer.show.mode.TraceEntityShowMode; import de.steamwar.bausystem.region.Region; @@ -108,7 +105,9 @@ public class TraceCommand extends SWCommand { @Register(value = {"hide"}, description = "TRACE_COMMAND_HELP_HIDE") public void hideCommand(@Validator Player p) { TraceShowManager.hide(p); - StoredRecords.hideIsolated(Region.getRegion(p.getLocation()), p); + Region region = Region.getRegion(p.getLocation()); + StoredRecords.hideIsolated(region, p); + StoredRecords.removeReplayTime(region, p); BauSystem.MESSAGE.send("TRACE_MESSAGE_HIDE", p); } @@ -118,6 +117,7 @@ public class TraceCommand extends SWCommand { Region region = Region.getRegion(p.getLocation()); StoredRecords.clear(region); StoredRecords.hideIsolated(region); + StoredRecords.removeReplayTime(region); BauSystem.MESSAGE.send("TRACE_MESSAGE_DELETE", p); } @@ -137,6 +137,34 @@ public class TraceCommand extends SWCommand { } } + @Register(value = "replay", description = "TRACE_COMMAND_HELP_REPLAY") + public void replay(@Validator Player p, @OptionalValue("0") int replayTick) { + Region region = Region.getRegion(p.getLocation()); + if (replayTick < 0) replayTick = 0; + StoredRecords.setReplayTime(region, p, replayTick); + } + + @Register(value = {"replay", "disable"}, description = "TRACE_COMMAND_HELP_REPLAY_DISABLE") + public void replayDisable(@Validator Player p) { + Region region = Region.getRegion(p.getLocation()); + StoredRecords.removeReplayTime(region, p); + } + + @Register(value = {"replay", "next"}, description = "TRACE_COMMAND_HELP_REPLAY_NEXT") + public void replayNext(@Validator Player p, @OptionalValue("1") int step) { + Region region = Region.getRegion(p.getLocation()); + int replayTick = StoredRecords.getReplayTime(region, p); + StoredRecords.setReplayTime(region, p, replayTick + step); + } + + @Register(value = {"replay", "previous"}, description = "TRACE_COMMAND_HELP_REPLAY_PREVIOUS") + public void replayPrevious(@Validator Player p, @OptionalValue("1") int step) { + Region region = Region.getRegion(p.getLocation()); + int replayTick = StoredRecords.getReplayTime(region, p) - step; + if (replayTick < 0) replayTick = 0; + StoredRecords.setReplayTime(region, p, replayTick); + } + @AllArgsConstructor private enum ShowModeType { ENTITY(TraceEntityShowMode::new, new ShowModeParameterType[]{}), 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 f56acb7b..ba087107 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 @@ -27,12 +27,14 @@ import lombok.experimental.UtilityClass; import org.bukkit.entity.Player; import java.util.*; +import java.util.function.Predicate; import java.util.stream.Collectors; @UtilityClass public class StoredRecords { private static final Map>> isolatedTNT = new HashMap<>(); + private static final Map> replayTime = new HashMap<>(); private static final Map> records = new HashMap<>(); public static void add(Region region, Record record) { @@ -99,11 +101,54 @@ public class StoredRecords { regionalIsolatedTNT.remove(player); } + public static int getReplayTime(Region region, Player player) { + return replayTime.computeIfAbsent(region, k -> new HashMap<>()).getOrDefault(player, -1); + } + + public static void removeReplayTime(Region region) { + replayTime.remove(region); + } + + public static void removeReplayTime(Region region, Player player) { + Map regionalReplayTime = replayTime.get(region); + if (regionalReplayTime == null) { + return; + } + regionalReplayTime.remove(player); + } + + public static void setReplayTime(Region region, Player player, int time) { + if (time < 0) { + removeReplayTime(region, player); + return; + } + replayTime.computeIfAbsent(region, k -> new HashMap<>()).put(player, time); + TraceShowManager.reshow(region, player); + } + static void show(Region region, Player player, ShowMode traceShowMode) { + 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; if (isolatedTNT.containsKey(region) && isolatedTNT.get(region).containsKey(player)) { - isolatedTNT.get(region).get(player).forEach(record -> record.getPositions().forEach(traceShowMode::show)); + isolatedTNT.get(region).get(player).forEach(record -> { + record.getPositions() + .stream() + .filter(finalReplayTimeFilter) + .forEach(traceShowMode::show); + }); } else { - records.getOrDefault(region, new ArrayList<>()).forEach(record -> record.showAll(traceShowMode)); + records.getOrDefault(region, new ArrayList<>()).forEach(record -> { + record.getTnt().forEach(tntRecord -> { + tntRecord.getPositions() + .stream() + .filter(finalReplayTimeFilter) + .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 0de6aaba..fa7306cd 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 @@ -137,6 +137,7 @@ public class TraceShowManager implements Listener { if (regionalShowModes == null) { return; } + // TODO: Fix show with replay regionalShowModes.values().forEach(tntPositionShowMode -> tntPositionShowMode.show(tnt)); }