Начинающий
- Статус
- Оффлайн
- Регистрация
- 17 Мар 2023
- Сообщения
- 81
- Реакции
- 1
Код:
private final TimerHelper timeDelay = new TimerHelper();
private final ArrayDeque<Float> tpsResult = new ArrayDeque<>(20);
private long time;
private static long tickTime;
public static float TICK_TIMER = 1f;
private static float tps;
public static float getTPS() {
return round2(tps);
}
public static float getTPS2() {
return round2(20.0f * ((float) tickTime / 1000f));
}
public static float round2(double value) {
BigDecimal bd = new BigDecimal(value);
bd = bd.setScale(2, RoundingMode.HALF_UP);
return bd.floatValue();
}
@EventTarget
public void onPacketReceive(EventReceivePacket event) {
if (!(event.getPacket() instanceof SPacketChat)) {
timeDelay.reset();
}
if (event.getPacket() instanceof SPacketTimeUpdate) {
if (time != 0L) {
tickTime = System.currentTimeMillis() - time;
if (tpsResult.size() > 20)
tpsResult.poll();
tpsResult.add(20.0f * (1000.0f / (float) (tickTime)));
float average = 0.0f;
for (Float value : tpsResult) average += MathUtils.clamp(value, 0f, 20f);
tps = average / (float) tpsResult.size();
}
time = System.currentTimeMillis();
}
}
@EventTarget
public void onUpdate(EventUpdate eventUpdate) {
if (Synth.getInstance().getModuleManager().getModule(Timer.class).isEnabled()) return;
if (getTPS() > 1)
TICK_TIMER = getTPS() / 20f;
else TICK_TIMER = 1f;
}
@Override
public void onDisable() {
TICK_TIMER = 1f;
super.onDisable();
}
}