Add simple Trace replay
Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
f438b4aa77
Commit
e894ed08f6
@ -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_HIDE = §8/§etrace hide §8- §7Hides all TNT-positions
|
||||||
TRACE_COMMAND_HELP_DELETE = §8/§etrace delete §8- §7Deletes 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_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_NAME = §eTracer
|
||||||
TRACE_GUI_ITEM_LORE = §7Status§8: {0}
|
TRACE_GUI_ITEM_LORE = §7Status§8: {0}
|
||||||
|
@ -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_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_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_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_NAME = §eTracer
|
||||||
TRACE_GUI_ITEM_LORE = §7Status§8: {0}
|
TRACE_GUI_ITEM_LORE = §7Status§8: {0}
|
||||||
|
@ -24,10 +24,7 @@ import de.steamwar.bausystem.Permission;
|
|||||||
import de.steamwar.bausystem.features.tracer.gui.TraceGui;
|
import de.steamwar.bausystem.features.tracer.gui.TraceGui;
|
||||||
import de.steamwar.bausystem.features.tracer.record.*;
|
import de.steamwar.bausystem.features.tracer.record.*;
|
||||||
import de.steamwar.bausystem.features.tracer.show.Record;
|
import de.steamwar.bausystem.features.tracer.show.Record;
|
||||||
import de.steamwar.bausystem.features.tracer.show.ShowModeParameter;
|
import de.steamwar.bausystem.features.tracer.show.*;
|
||||||
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.mode.RawEntityShowMode;
|
import de.steamwar.bausystem.features.tracer.show.mode.RawEntityShowMode;
|
||||||
import de.steamwar.bausystem.features.tracer.show.mode.TraceEntityShowMode;
|
import de.steamwar.bausystem.features.tracer.show.mode.TraceEntityShowMode;
|
||||||
import de.steamwar.bausystem.region.Region;
|
import de.steamwar.bausystem.region.Region;
|
||||||
@ -108,7 +105,9 @@ public class TraceCommand extends SWCommand {
|
|||||||
@Register(value = {"hide"}, description = "TRACE_COMMAND_HELP_HIDE")
|
@Register(value = {"hide"}, description = "TRACE_COMMAND_HELP_HIDE")
|
||||||
public void hideCommand(@Validator Player p) {
|
public void hideCommand(@Validator Player p) {
|
||||||
TraceShowManager.hide(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);
|
BauSystem.MESSAGE.send("TRACE_MESSAGE_HIDE", p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,6 +117,7 @@ public class TraceCommand extends SWCommand {
|
|||||||
Region region = Region.getRegion(p.getLocation());
|
Region region = Region.getRegion(p.getLocation());
|
||||||
StoredRecords.clear(region);
|
StoredRecords.clear(region);
|
||||||
StoredRecords.hideIsolated(region);
|
StoredRecords.hideIsolated(region);
|
||||||
|
StoredRecords.removeReplayTime(region);
|
||||||
BauSystem.MESSAGE.send("TRACE_MESSAGE_DELETE", p);
|
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
|
@AllArgsConstructor
|
||||||
private enum ShowModeType {
|
private enum ShowModeType {
|
||||||
ENTITY(TraceEntityShowMode::new, new ShowModeParameterType[]{}),
|
ENTITY(TraceEntityShowMode::new, new ShowModeParameterType[]{}),
|
||||||
|
@ -27,12 +27,14 @@ import lombok.experimental.UtilityClass;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@UtilityClass
|
@UtilityClass
|
||||||
public class StoredRecords {
|
public class StoredRecords {
|
||||||
|
|
||||||
private static final Map<Region, Map<Player, List<Record.TNTRecord>>> isolatedTNT = new HashMap<>();
|
private static final Map<Region, Map<Player, List<Record.TNTRecord>>> isolatedTNT = new HashMap<>();
|
||||||
|
private static final Map<Region, Map<Player, Integer>> replayTime = new HashMap<>();
|
||||||
private static final Map<Region, List<Record>> records = new HashMap<>();
|
private static final Map<Region, List<Record>> records = new HashMap<>();
|
||||||
|
|
||||||
public static void add(Region region, Record record) {
|
public static void add(Region region, Record record) {
|
||||||
@ -99,11 +101,54 @@ public class StoredRecords {
|
|||||||
regionalIsolatedTNT.remove(player);
|
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<Player, Integer> 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<TNTPosition> traceShowMode) {
|
static void show(Region region, Player player, ShowMode<TNTPosition> traceShowMode) {
|
||||||
|
Predicate<TNTPosition> 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<TNTPosition> finalReplayTimeFilter = replayTimeFilter;
|
||||||
if (isolatedTNT.containsKey(region) && isolatedTNT.get(region).containsKey(player)) {
|
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 {
|
} 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);
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -137,6 +137,7 @@ public class TraceShowManager implements Listener {
|
|||||||
if (regionalShowModes == null) {
|
if (regionalShowModes == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// TODO: Fix show with replay
|
||||||
regionalShowModes.values().forEach(tntPositionShowMode -> tntPositionShowMode.show(tnt));
|
regionalShowModes.values().forEach(tntPositionShowMode -> tntPositionShowMode.show(tnt));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren