SteamWar/BauSystem2.0
Archiviert
12
0

Merge pull request 'tracer/bug-354-Fix-smaller-trace-issues' (#242) from tracer/bug-354-Fix-smaller-trace-issues into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Reviewed-on: #242
Reviewed-by: YoyoNow <jwsteam@nidido.de>
Dieser Commit ist enthalten in:
YoyoNow 2024-04-28 12:15:17 +02:00
Commit 929400b4d9
2 geänderte Dateien mit 31 neuen und 20 gelöschten Zeilen

Datei anzeigen

@ -57,17 +57,21 @@ public class TraceCommand extends SWCommand {
public void stop(@Validator Player player) { public void stop(@Validator Player player) {
Region region = Region.getRegion(player.getLocation()); Region region = Region.getRegion(player.getLocation());
TraceRecorder.instance.stopRecording(region); TraceRecorder.instance.stopRecording(region);
if (TraceRecorder.instance.isAutoTraceEnabledInRegion(region)) {
TraceRecorder.instance.removeAutoTraceRegion(region);
BauSystem.MESSAGE.send("TRACE_MESSAGE_AUTO_STOP", player);
} else {
BauSystem.MESSAGE.send("TRACE_MESSAGE_STOP", player); BauSystem.MESSAGE.send("TRACE_MESSAGE_STOP", player);
} }
}
@Register(value = "auto", description = "TRACE_COMMAND_HELP_AUTO") @Register(value = "auto", description = "TRACE_COMMAND_HELP_AUTO")
public void auto(@Validator Player player) { public void auto(@Validator Player player) {
Region region = Region.getRegion(player.getLocation()); Region region = Region.getRegion(player.getLocation());
if (TraceRecorder.instance.toggleAutoTrace(region)) { TraceRecorder.instance.addAutoTraceRegion(region);
BauSystem.MESSAGE.send("TRACE_MESSAGE_AUTO_START", player); BauSystem.MESSAGE.send("TRACE_MESSAGE_AUTO_START", player);
} else {
BauSystem.MESSAGE.send("TRACE_MESSAGE_AUTO_STOP", player);
}
} }
@Register(value = "show", description = "TRACE_COMMAND_HELP_SHOW") @Register(value = "show", description = "TRACE_COMMAND_HELP_SHOW")
@ -248,7 +252,7 @@ public class TraceCommand extends SWCommand {
@Override @Override
public ViewFlag map(CommandSender commandSender, String[] previousArguments, String s) { public ViewFlag map(CommandSender commandSender, String[] previousArguments, String s) {
for (ViewFlag flag : ViewFlag.flags) { for (ViewFlag flag : ViewFlag.flags) {
if (s.equals("--" + flag.name)) { if (s.equals("-" + flag.name)) {
return flag; return flag;
} }

Datei anzeigen

@ -74,18 +74,12 @@ public class TraceRecorder implements Listener {
}, 0, 1); }, 0, 1);
} }
/** public void addAutoTraceRegion(Region region) {
* Toggles auto trace for the given region
*
* @param region
*/
public boolean toggleAutoTrace(Region region) {
if (!autoTraceRegions.remove(region)) {
autoTraceRegions.add(region); autoTraceRegions.add(region);
return true;
} else {
return false;
} }
public void removeAutoTraceRegion(Region region) {
autoTraceRegions.remove(region);
} }
/** /**
@ -137,6 +131,7 @@ public class TraceRecorder implements Listener {
TraceRecordingWrapper wrappedTrace = activeTraces.get(region); TraceRecordingWrapper wrappedTrace = activeTraces.get(region);
for (TNTPrimed tnt : trackedTNT.getOrDefault(region, Collections.emptyList())) { for (TNTPrimed tnt : trackedTNT.getOrDefault(region, Collections.emptyList())) {
TNTPoint record = record(tnt, wrappedTrace, Collections.emptyList()); TNTPoint record = record(tnt, wrappedTrace, Collections.emptyList());
if (record == null) continue;
wrappedTrace.addRecord(record); wrappedTrace.addRecord(record);
} }
wrappedTrace.commitRecorded(); wrappedTrace.commitRecorded();
@ -153,6 +148,17 @@ public class TraceRecorder implements Listener {
*/ */
private TNTPoint record(TNTPrimed tntPrimed, TraceRecordingWrapper wrappedTrace, List<Block> destroyedBlocks) { private TNTPoint record(TNTPrimed tntPrimed, TraceRecordingWrapper wrappedTrace, List<Block> destroyedBlocks) {
List<TNTPoint> history = historyMap.getOrDefault(tntPrimed, new ArrayList<>()); List<TNTPoint> history = historyMap.getOrDefault(tntPrimed, new ArrayList<>());
// Failsave for tnt entering unloaded chunks
if (tntPrimed.isDead() || history.size() > 0 && history.get(history.size() - 1).getFuse() == tntPrimed.getFuseTicks()) {
Region region = tntSpawnRegion.get(tntPrimed);
if (region == null) return null;
trackedTNT.get(region).remove(tntPrimed);
tntSpawnRegion.remove(tntPrimed);
historyMap.remove(tntPrimed);
tntSpawnRegion.remove(tntPrimed);
return null;
}
int tntID; int tntID;
if (history.size() == 0) { if (history.size() == 0) {
@ -168,7 +174,7 @@ public class TraceRecorder implements Listener {
} }
boolean afterFirstExplosion = wrappedTrace.isExplosionRecorded(); boolean afterFirstExplosion = wrappedTrace.isExplosionRecorded();
TNTPoint record = new TNTPoint(tntID, tntPrimed, isExplosion, afterFirstExplosion, TPSUtils.currentTick.get() - wrappedTrace.getStartTick(), history, destroyedBlocks); TNTPoint record = new TNTPoint(tntID, tntPrimed, isExplosion, afterFirstExplosion, TPSUtils.currentRealTick.get() - wrappedTrace.getStartTick(), history, destroyedBlocks);
history.add(record); history.add(record);
return record; return record;
@ -248,6 +254,7 @@ public class TraceRecorder implements Listener {
tntSpawnRegion.remove((TNTPrimed) event.getEntity()); tntSpawnRegion.remove((TNTPrimed) event.getEntity());
activeTraces.get(region).addRecord(record((TNTPrimed) event.getEntity(), activeTraces.get(region), event.blockList())); activeTraces.get(region).addRecord(record((TNTPrimed) event.getEntity(), activeTraces.get(region), event.blockList()));
tntSpawnRegion.remove((TNTPrimed) event.getEntity());
historyMap.remove((TNTPrimed) event.getEntity()); historyMap.remove((TNTPrimed) event.getEntity());
} }
} }