Spaces:
Build error
Build error
File size: 1,587 Bytes
d46f4a3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
package net.minecraft.client.telemetry.events;
import java.time.Duration;
import java.time.Instant;
import javax.annotation.Nullable;
import net.minecraft.client.telemetry.TelemetryEventSender;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@OnlyIn(Dist.CLIENT)
public abstract class AggregatedTelemetryEvent {
private static final int SAMPLE_INTERVAL_MS = 60000;
private static final int SAMPLES_PER_EVENT = 10;
private int sampleCount;
private boolean ticking = false;
@Nullable
private Instant lastSampleTime;
public void start() {
this.ticking = true;
this.lastSampleTime = Instant.now();
this.sampleCount = 0;
}
public void tick(TelemetryEventSender p_263410_) {
if (this.shouldTakeSample()) {
this.takeSample();
this.sampleCount++;
this.lastSampleTime = Instant.now();
}
if (this.shouldSentEvent()) {
this.sendEvent(p_263410_);
this.sampleCount = 0;
}
}
public boolean shouldTakeSample() {
return this.ticking && this.lastSampleTime != null && Duration.between(this.lastSampleTime, Instant.now()).toMillis() > 60000L;
}
public boolean shouldSentEvent() {
return this.sampleCount >= 10;
}
public void stop() {
this.ticking = false;
}
protected int getSampleCount() {
return this.sampleCount;
}
public abstract void takeSample();
public abstract void sendEvent(TelemetryEventSender p_263328_);
} |