Trace Refactor #233
@ -67,8 +67,22 @@ public class Recorder implements Listener {
|
|||||||
*/
|
*/
|
||||||
private final Set<Region> autoTraceRegions = new HashSet<>();
|
private final Set<Region> autoTraceRegions = new HashSet<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Counters for how long no tnt was seen in an active auto trace region
|
||||||
|
*/
|
||||||
|
private final Map<Region, Integer> noTntRecordedCounter = new HashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Amount of ticks, after wich an auto-trace is stopped, if no tnt where seen
|
||||||
|
*/
|
||||||
|
private final long AUTO_TRACE_STOP_TRESHHOLD = 120;
|
||||||
|
|
||||||
public Recorder(){
|
public Recorder(){
|
||||||
BauSystem.runTaskTimer(BauSystem.getInstance(), this::record, 0, 1);
|
BauSystem.runTaskTimer(BauSystem.getInstance(), () -> {
|
||||||
|
noTntRecordedCounter.replaceAll((region, counter) -> counter + 1);
|
||||||
|
record();
|
||||||
|
checkForAutoTraceFinish();
|
||||||
|
}, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Toggles auto trace for the given region
|
/** Toggles auto trace for the given region
|
||||||
@ -82,13 +96,24 @@ public class Recorder implements Listener {
|
|||||||
autoTraceRegions.add(region);
|
autoTraceRegions.add(region);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Makes checks for whether auto traces finished
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public void checkForAutoTraceFinish(){
|
||||||
|
for(Region region: autoTraceRegions)
|
||||||
|
if(autoTraceRegions.contains(region) && noTntRecordedCounter.get(region) > AUTO_TRACE_STOP_TRESHHOLD){
|
||||||
|
stopRecording(region);
|
||||||
|
autoTraceRegions.remove(region);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** 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
|
||||||
* @
|
|
||||||
*/
|
*/
|
||||||
public void startRecording(Region region){
|
public void startRecording(Region region){
|
||||||
if(activeTraces.containsKey(region)) return;
|
if(activeTraces.containsKey(region)) return;
|
||||||
|
if(autoTraceRegions.contains(region)) noTntRecordedCounter.put(region, 0);
|
||||||
Trace trace = new Trace(region);
|
Trace trace = new Trace(region);
|
||||||
activeTraces.put(region, trace);
|
activeTraces.put(region, trace);
|
||||||
}
|
}
|
||||||
@ -115,6 +140,9 @@ 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);
|
||||||
|
if(trackedTNT.getOrDefault(region, Collections.emptyList()).size() > 0)
|
||||||
|
noTntRecordedCounter.put(region, 0);
|
||||||
|
|
||||||
for(TNTPrimed tnt : trackedTNT.getOrDefault(region, Collections.emptyList())){
|
for(TNTPrimed tnt : trackedTNT.getOrDefault(region, Collections.emptyList())){
|
||||||
record(tnt, trace);
|
record(tnt, trace);
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren