diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index fb2d1386..19b53de7 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -707,10 +707,11 @@ 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 = §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§8/§7step tick forward -TRACE_COMMAND_HELP_REPLAY_PREVIOUS = §8/§etrace replay previous §8[§7Step§8] §8- §7Jump one§8/§7step tick back +TRACE_COMMAND_HELP_REPLAY_NEXT = §8/§etrace replay next §8[§7step§8] §8- §7Jump one§8/§7step tick forward +TRACE_COMMAND_HELP_REPLAY_PREVIOUS = §8/§etrace replay previous §8[§7step§8] §8- §7Jump one§8/§7step tick back +TRACE_COMMAND_HELP_REPLAY_LOOP = §8/§etrace replay loop §8<§7start§8> §8<§7end§8> §8[§7speed§8] §8- §7Loop the replay 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 62d5742a..4936643e 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -687,10 +687,11 @@ 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 = §8/§etrace replay §8[§7Tick§8] §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 einen§8/§7step Tick vor -TRACE_COMMAND_HELP_REPLAY_PREVIOUS = §8/§etrace replay previous §8- §7Springe einen§8/§7step Tick zurück +TRACE_COMMAND_HELP_REPLAY_NEXT = §8/§etrace replay next §8[§7Step§8] §8- §7Springe einen§8/§7step Tick vor +TRACE_COMMAND_HELP_REPLAY_PREVIOUS = §8/§etrace replay previous §8[§7Step§8] §8- §7Springe einen§8/§7step Tick zurück +TRACE_COMMAND_HELP_REPLAY_LOOP = §8/§etrace replay loop §8<§7start§8> §8<§7end§8> §8[§7speed§8] §8- §7Spielt die Aufnahme in einer Schleife ab 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 564f7cc7..ced48fde 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java @@ -165,6 +165,48 @@ public class TraceCommand extends SWCommand { StoredRecords.setReplayTime(region, p, replayTick); } + @Register(value = {"replay", "loop"}, description = "TRACE_COMMAND_HELP_REPLAY_LOOP") + public void replayLoop(@Validator Player p, int start, int end, @OptionalValue("0") int speed) { + Region region = Region.getRegion(p.getLocation()); + + if (start < 0) start = 0; + if (end < 0) end = 0; + + int initial = StoredRecords.getReplayTime(region, p); + if (!(Math.min(start, end) < initial && Math.max(start, end) > initial)) { + initial = start; + } + int finalInitial = initial; + + int finalStart = start; + int finalEnd = end; + Supplier supplier = new Supplier() { + int temp = speed; + int current = finalInitial; + + @Override + public Integer get() { + if (temp-- > 0) { + return current; + } + temp = speed; + if (finalEnd > finalStart) { + current++; + if (current > finalEnd) { + current = finalStart; + } + } else { + current--; + if (current < finalEnd) { + current = finalStart; + } + } + return current; + } + }; + StoredRecords.setReplayLoop(region, p, supplier); + } + @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 ba087107..43e563d8 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 @@ -19,15 +19,18 @@ package de.steamwar.bausystem.features.tracer.show; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.tracer.TNTPosition; import de.steamwar.bausystem.features.tracer.record.Recorder; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.shared.ShowMode; import lombok.experimental.UtilityClass; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; import java.util.*; import java.util.function.Predicate; +import java.util.function.Supplier; import java.util.stream.Collectors; @UtilityClass @@ -35,8 +38,21 @@ public class StoredRecords { private static final Map>> isolatedTNT = new HashMap<>(); private static final Map> replayTime = new HashMap<>(); + private static final Map>> replayLoops = new HashMap<>(); private static final Map> records = new HashMap<>(); + static { + Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> { + replayLoops.forEach((region, playerSupplierMap) -> { + playerSupplierMap.forEach((player, integerSupplier) -> { + int tick = integerSupplier.get(); + replayTime.computeIfAbsent(region, __ -> new HashMap<>()).put(player, tick); + TraceShowManager.reshow(region, player); + }); + }); + }, 1, 1); + } + public static void add(Region region, Record record) { records.computeIfAbsent(region, k -> new ArrayList<>()).add(record); } @@ -107,14 +123,18 @@ public class StoredRecords { public static void removeReplayTime(Region region) { replayTime.remove(region); + replayLoops.remove(region); } public static void removeReplayTime(Region region, Player player) { Map regionalReplayTime = replayTime.get(region); - if (regionalReplayTime == null) { - return; + if (regionalReplayTime != null) { + regionalReplayTime.remove(player); + } + Map> regionalReplayLoops = replayLoops.get(region); + if (regionalReplayLoops != null) { + regionalReplayLoops.remove(player); } - regionalReplayTime.remove(player); } public static void setReplayTime(Region region, Player player, int time) { @@ -124,6 +144,15 @@ public class StoredRecords { } replayTime.computeIfAbsent(region, k -> new HashMap<>()).put(player, time); TraceShowManager.reshow(region, player); + + Map> regionalReplayLoops = replayLoops.get(region); + if (regionalReplayLoops != null) { + regionalReplayLoops.remove(player); + } + } + + public static void setReplayLoop(Region region, Player player, Supplier loop) { + replayLoops.computeIfAbsent(region, k -> new HashMap<>()).put(player, loop); } static void show(Region region, Player player, ShowMode traceShowMode) {