Trace Refactor #233
@ -43,13 +43,19 @@ public class Recorder implements Listener {
|
||||
/**
|
||||
* Map for all tnts being traced, by region
|
||||
*/
|
||||
private final Map<Region, Set<TNTPrimed>> trackedTNT = new HashMap<>();
|
||||
private final Map<Region, List<TNTPrimed>> trackedTNT = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Maps a tracked tnt entity to the last record taken of it
|
||||
*/
|
||||
private final Map<TNTPrimed, TNTRecord> lastRecordMap = new HashMap<>();
|
||||
|
||||
public Recorder(){
|
||||
BauSystem.runTaskTimer(BauSystem.getInstance(), () ->{
|
||||
record();
|
||||
}, 0, 1);
|
||||
}
|
||||
|
||||
/** Starts a recording at the given region
|
||||
*
|
||||
* @param region region to be recorded
|
||||
@ -66,8 +72,8 @@ public class Recorder implements Listener {
|
||||
*/
|
||||
public void stopRecording(Region region){
|
||||
activeTraces.remove(region);
|
||||
for(TNTPrimed tnt : trackedTNT.getOrDefault(region, Collections.emptySet())) lastRecordMap.remove(tnt);
|
||||
trackedTNT.put(region, new HashSet<>());
|
||||
for(TNTPrimed tnt : trackedTNT.getOrDefault(region, Collections.emptyList())) lastRecordMap.remove(tnt);
|
||||
trackedTNT.put(region, new ArrayList<>());
|
||||
}
|
||||
|
||||
/** Internal methode to record all tracked TNT Entities
|
||||
@ -76,7 +82,7 @@ public class Recorder implements Listener {
|
||||
private void record(){
|
||||
for(Region region : activeTraces.keySet()){
|
||||
Trace trace = activeTraces.get(region);
|
||||
for(TNTPrimed tnt : trackedTNT.getOrDefault(region, Collections.emptySet())){
|
||||
for(TNTPrimed tnt : trackedTNT.getOrDefault(region, Collections.emptyList())){
|
||||
TNTRecord record = new TNTRecord(tnt, false, TPSUtils.currentTick.get() - trace.getStartTime(), lastRecordMap.getOrDefault(tnt, null));
|
||||
lastRecordMap.put(tnt, record);
|
||||
trace.add(record);
|
||||
@ -104,9 +110,9 @@ public class Recorder implements Listener {
|
||||
public void onTNTSpawn(EntitySpawnEvent event){
|
||||
if(!(event.getEntity() instanceof TNTPrimed)) return;
|
||||
Region region = Region.getRegion(event.getLocation());
|
||||
if(activeTraces.keySet().contains(region)){
|
||||
if(activeTraces.containsKey(region)){
|
||||
//Check whether set for tracking already exists. Creating it if necessary
|
||||
if(!trackedTNT.keySet().contains(region)) trackedTNT.put(region, new HashSet<>());
|
||||
if(!trackedTNT.containsKey(region)) trackedTNT.put(region, new ArrayList<>());
|
||||
|
||||
trackedTNT.get(region).add((TNTPrimed) event.getEntity());
|
||||
}
|
||||
|
@ -23,7 +23,9 @@ import de.steamwar.bausystem.features.tpslimit.TPSUtils;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class Trace {
|
||||
@ -42,7 +44,7 @@ public class Trace {
|
||||
/**
|
||||
* Records of TNTs, making up the trace
|
||||
*/
|
||||
private final Set<TNTRecord> records = new HashSet<>();
|
||||
private final List<TNTRecord> records = new ArrayList<>();
|
||||
|
||||
public Trace (Region region){
|
||||
this.region = region;
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren