SteamWar/BauSystem2.0
Archiviert
12
0

Trace Refactor #233

Zusammengeführt
YoyoNow hat 121 Commits von TracerGUI nach master 2024-04-21 16:03:26 +02:00 zusammengeführt
2 geänderte Dateien mit 24 neuen und 24 gelöschten Zeilen
Nur Änderungen aus Commit e71ccc3160 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -60,7 +60,7 @@ public class Recorder implements Listener {
/** /**
* Maps a tracked tnt entity to the last record taken of it * Maps a tracked tnt entity to the last record taken of it
*/ */
private final Map<TNTPrimed, TNTRecord> lastRecordMap = new HashMap<>(); private final Map<TNTPrimed, List<TNTRecord>> historyMap = new HashMap<>();
public Recorder(){ public Recorder(){
BauSystem.runTaskTimer(BauSystem.getInstance(), this::record, 0, 1); BauSystem.runTaskTimer(BauSystem.getInstance(), this::record, 0, 1);
@ -86,11 +86,9 @@ public class Recorder implements Listener {
activeTraces.remove(region); activeTraces.remove(region);
for(TNTPrimed tnt : trackedTNT.getOrDefault(region, Collections.emptyList())) for(TNTPrimed tnt : trackedTNT.getOrDefault(region, Collections.emptyList()))
lastRecordMap.remove(tnt); historyMap.remove(tnt);
trackedTNT.put(region, new ArrayList<>()); trackedTNT.put(region, new ArrayList<>());
} }
/** Internal methode to record all tracked TNT Entities /** Internal methode to record all tracked TNT Entities
@ -112,13 +110,14 @@ public class Recorder implements Listener {
* @param trace trace to record the tnt for * @param trace trace to record the tnt for
*/ */
private void record(TNTPrimed tntPrimed, Trace trace){ private void record(TNTPrimed tntPrimed, Trace trace){
TNTRecord lastRecord = lastRecordMap.getOrDefault(tntPrimed, null); List<TNTRecord> history = historyMap.getOrDefault(tntPrimed, new ArrayList<>());
TNTRecord record = new TNTRecord(tntPrimed, tntPrimed.getFuseTicks() == 0, TPSUtils.currentTick.get() - trace.getStartTime(), lastRecord); if(historyMap.size() == 0)
if(lastRecord != null) historyMap.put(tntPrimed, history);
lastRecord.setNext(record);
TNTRecord record = new TNTRecord(tntPrimed, tntPrimed.getFuseTicks() == 0, TPSUtils.currentTick.get() - trace.getStartTime(), history);
history.add(record);
lastRecordMap.put(tntPrimed, record);
trace.add(record); trace.add(record);
} }

Datei anzeigen

@ -24,6 +24,9 @@ import org.bukkit.Location;
import org.bukkit.entity.TNTPrimed; import org.bukkit.entity.TNTPrimed;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.util.List;
import java.util.Optional;
@Getter @Getter
public class TNTRecord { public class TNTRecord {
/** /**
@ -52,31 +55,29 @@ public class TNTRecord {
private final Vector velocity; private final Vector velocity;
/** /**
* Reference to the last record having been taken of the tnt represented by this record * List of all tnt records, that are represent the same tnt
*/ */
private final TNTRecord previous; private final List<TNTRecord> history;
/** public TNTRecord(TNTPrimed tnt, boolean explosion, long ticksSinceStart, List<TNTRecord> history){
* Reference to the next record of the tnt represented by this record
*/
private TNTRecord next;
public TNTRecord(TNTPrimed tnt, boolean explosion, long ticksSinceStart, TNTRecord previous){
this.explosion = explosion; this.explosion = explosion;
this.ticksSinceStart = ticksSinceStart; this.ticksSinceStart = ticksSinceStart;
fuse = tnt.getFuseTicks(); fuse = tnt.getFuseTicks();
location = tnt.getLocation(); location = tnt.getLocation();
velocity = tnt.getVelocity(); velocity = tnt.getVelocity();
this.previous = previous; this.history = history;
} }
public Optional<TNTRecord> getNext(){
int index = history.indexOf(this);
/** return index == history.size() - 1 ? Optional.empty() : Optional.of(history.get(index + 1));
* One call only function to set next }
* @param next
*/ public Optional<TNTRecord> getPrev(){
protected void setNext(TNTRecord next){ int index = history.indexOf(this);
if(this.next == null) this.next = next;
return index == 0 ? Optional.empty() : Optional.of(history.get(index - 1));
} }
@Override @Override