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