Replaced doubly linked list structure with ArrayList refrence, for tnt history
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed

Dieser Commit ist enthalten in:
D4rkr34lm 2024-03-01 11:40:24 +01:00
Ursprung 40f4af2a06
Commit e71ccc3160
2 geänderte Dateien mit 24 neuen und 24 gelöschten Zeilen

Datei anzeigen

@ -60,7 +60,7 @@ public class Recorder implements Listener {
/**
* 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(){
BauSystem.runTaskTimer(BauSystem.getInstance(), this::record, 0, 1);
@ -86,11 +86,9 @@ public class Recorder implements Listener {
activeTraces.remove(region);
for(TNTPrimed tnt : trackedTNT.getOrDefault(region, Collections.emptyList()))
lastRecordMap.remove(tnt);
historyMap.remove(tnt);
trackedTNT.put(region, new ArrayList<>());
}
/** 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
*/
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(lastRecord != null)
lastRecord.setNext(record);
if(historyMap.size() == 0)
historyMap.put(tntPrimed, history);
TNTRecord record = new TNTRecord(tntPrimed, tntPrimed.getFuseTicks() == 0, TPSUtils.currentTick.get() - trace.getStartTime(), history);
history.add(record);
lastRecordMap.put(tntPrimed, record);
trace.add(record);
}

Datei anzeigen

@ -24,6 +24,9 @@ import org.bukkit.Location;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.util.Vector;
import java.util.List;
import java.util.Optional;
@Getter
public class TNTRecord {
/**
@ -52,31 +55,29 @@ public class TNTRecord {
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;
/**
* 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){
public TNTRecord(TNTPrimed tnt, boolean explosion, long ticksSinceStart, List<TNTRecord> history){
this.explosion = explosion;
this.ticksSinceStart = ticksSinceStart;
fuse = tnt.getFuseTicks();
location = tnt.getLocation();
velocity = tnt.getVelocity();
this.previous = previous;
this.history = history;
}
public Optional<TNTRecord> getNext(){
int index = history.indexOf(this);
/**
* One call only function to set next
* @param next
*/
protected void setNext(TNTRecord next){
if(this.next == null) this.next = next;
return index == history.size() - 1 ? Optional.empty() : Optional.of(history.get(index + 1));
}
public Optional<TNTRecord> getPrev(){
int index = history.indexOf(this);
return index == 0 ? Optional.empty() : Optional.of(history.get(index - 1));
}
@Override